From 8e658044e344258f4674c6dc05af6cea7fa29765 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 23 Nov 2019 02:13:41 -0500 Subject: restrict the api a bit more --- teleterm-web/src/lib.rs | 5 ++- teleterm-web/src/model.rs | 54 ++++++++++++----------------- teleterm-web/src/prelude.rs | 4 +-- teleterm-web/src/protocol.rs | 6 ++-- teleterm-web/src/views.rs | 8 ++--- teleterm/static/teleterm_web.js | 65 ++++++++++++++++++----------------- teleterm/static/teleterm_web_bg.wasm | Bin 720118 -> 717549 bytes 7 files changed, 66 insertions(+), 76 deletions(-) diff --git a/teleterm-web/src/lib.rs b/teleterm-web/src/lib.rs index 8913e3e..1b8fdde 100644 --- a/teleterm-web/src/lib.rs +++ b/teleterm-web/src/lib.rs @@ -18,9 +18,8 @@ enum Msg { fn init(_: Url, orders: &mut impl Orders) -> Init { log::trace!("init"); - let model = crate::model::Model::default(); - orders.perform_cmd(model.list()); - Init::new(model) + orders.send_msg(Msg::Refresh); + Init::new(crate::model::Model::default()) } fn update( diff --git a/teleterm-web/src/model.rs b/teleterm-web/src/model.rs index dd95af3..362b4bd 100644 --- a/teleterm-web/src/model.rs +++ b/teleterm-web/src/model.rs @@ -15,7 +15,7 @@ impl Drop for WatchConn { } #[derive(Default)] -pub struct Model { +pub(crate) struct Model { sessions: Vec, watch_conn: Option, } @@ -38,7 +38,10 @@ impl Model { }, crate::Msg::Refresh => { log::debug!("refreshing"); - orders.perform_cmd(self.list()); + orders.perform_cmd( + seed::Request::new(LIST_URL) + .fetch_json_data(crate::Msg::List), + ); } crate::Msg::StartWatching(id) => { log::debug!("watching {}", id); @@ -62,7 +65,7 @@ impl Model { } crate::protocol::Message::Disconnected => { self.disconnect_watch(); - orders.perform_cmd(self.list()); + orders.send_msg(crate::Msg::Refresh); } crate::protocol::Message::Resize { size } => { self.set_size(size.rows, size.cols); @@ -75,22 +78,24 @@ impl Model { }, crate::Msg::StopWatching => { self.disconnect_watch(); - orders.perform_cmd(self.list()); + orders.send_msg(crate::Msg::Refresh); } } } - pub(crate) fn list( - &self, - ) -> impl futures::Future { - seed::Request::new(LIST_URL).fetch_json_data(crate::Msg::List) + pub(crate) fn screen(&self) -> Option<&vt100::Screen> { + self.watch_conn.as_ref().map(|conn| conn.term.screen()) } - pub(crate) fn watch( - &mut self, - id: &str, - orders: &mut impl Orders, - ) { + pub(crate) fn sessions(&self) -> &[crate::protocol::Session] { + &self.sessions + } + + pub(crate) fn watching(&self) -> bool { + self.watch_conn.is_some() + } + + fn watch(&mut self, id: &str, orders: &mut impl Orders) { let ws = crate::ws::connect( &format!("{}?id={}", WATCH_URL, id), id, @@ -101,38 +106,23 @@ impl Model { self.watch_conn = Some(WatchConn { ws, term }) } - pub fn sessions(&self) -> &[crate::protocol::Session] { - &self.sessions - } - - pub fn update_sessions( - &mut self, - sessions: Vec, - ) { + fn update_sessions(&mut self, sessions: Vec) { self.sessions = sessions; } - pub fn watching(&self) -> bool { - self.watch_conn.is_some() - } - - pub fn disconnect_watch(&mut self) { + fn disconnect_watch(&mut self) { self.watch_conn = None; } - pub fn process(&mut self, bytes: &[u8]) { + fn process(&mut self, bytes: &[u8]) { if let Some(conn) = &mut self.watch_conn { conn.term.process(bytes); } } - pub fn set_size(&mut self, rows: u16, cols: u16) { + fn set_size(&mut self, rows: u16, cols: u16) { if let Some(conn) = &mut self.watch_conn { conn.term.set_size(rows, cols); } } - - pub fn screen(&self) -> Option<&vt100::Screen> { - self.watch_conn.as_ref().map(|conn| conn.term.screen()) - } } diff --git a/teleterm-web/src/prelude.rs b/teleterm-web/src/prelude.rs index afab8ab..68b810d 100644 --- a/teleterm-web/src/prelude.rs +++ b/teleterm-web/src/prelude.rs @@ -1,2 +1,2 @@ -pub use seed::prelude::*; -pub use web_sys::{ErrorEvent, MessageEvent, WebSocket}; +pub(crate) use seed::prelude::*; +pub(crate) use web_sys::{ErrorEvent, MessageEvent, WebSocket}; diff --git a/teleterm-web/src/protocol.rs b/teleterm-web/src/protocol.rs index 9c0c144..4cbedf2 100644 --- a/teleterm-web/src/protocol.rs +++ b/teleterm-web/src/protocol.rs @@ -2,14 +2,14 @@ // crate or something? but ideally in a way that doesn't require pulling in // tokio #[derive(Clone, Debug, serde::Deserialize)] -pub enum Message { +pub(crate) enum Message { TerminalOutput { data: Vec }, Disconnected, Resize { size: Size }, } #[derive(Clone, Debug, serde::Deserialize)] -pub struct Session { +pub(crate) struct Session { pub id: String, pub username: String, pub term_type: String, @@ -20,7 +20,7 @@ pub struct Session { } #[derive(Clone, Debug, serde::Deserialize)] -pub struct Size { +pub(crate) struct Size { pub rows: u16, pub cols: u16, } diff --git a/teleterm-web/src/views.rs b/teleterm-web/src/views.rs index dfcfa59..738dad7 100644 --- a/teleterm-web/src/views.rs +++ b/teleterm-web/src/views.rs @@ -1,4 +1,4 @@ -pub mod list; -pub mod page; -pub mod terminal; -pub mod watch; +pub(crate) mod list; +pub(crate) mod page; +pub(crate) mod terminal; +pub(crate) mod watch; diff --git a/teleterm/static/teleterm_web.js b/teleterm/static/teleterm_web.js index 7ada906..347b24f 100644 --- a/teleterm/static/teleterm_web.js +++ b/teleterm/static/teleterm_web.js @@ -1,6 +1,10 @@ let wasm; +function __wbg_elem_binding0(arg0, arg1) { + wasm.__wbg_function_table.get(227)(arg0, arg1); +} + const heap = new Array(32); heap.fill(undefined); @@ -17,32 +21,29 @@ function addHeapObject(obj) { heap[idx] = obj; return idx; } -function __wbg_elem_binding0(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(295)(arg0, arg1, addHeapObject(arg2)); -} function __wbg_elem_binding1(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(77)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(78)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding2(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(77)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(78)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding3(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(77)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(296)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding4(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(81)(arg0, arg1, arg2); + wasm.__wbg_function_table.get(78)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding5(arg0, arg1, arg2) { - wasm.__wbg_function_table.get(77)(arg0, arg1, addHeapObject(arg2)); + wasm.__wbg_function_table.get(82)(arg0, arg1, arg2); } -function __wbg_elem_binding6(arg0, arg1) { - wasm.__wbg_function_table.get(226)(arg0, arg1); +function __wbg_elem_binding6(arg0, arg1, arg2) { + wasm.__wbg_function_table.get(78)(arg0, arg1, addHeapObject(arg2)); } function __wbg_elem_binding7(arg0, arg1, arg2, arg3, arg4) { - wasm.__wbg_function_table.get(322)(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4)); + wasm.__wbg_function_table.get(323)(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4)); } function __wbg_elem_binding8(arg0, arg1, arg2, arg3) { - wasm.__wbg_function_table.get(326)(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); + wasm.__wbg_function_table.get(327)(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3)); } /** */ @@ -884,16 +885,16 @@ function init(module) { imports.wbg.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm(arg0, arg1)); }; - imports.wbg.__wbindgen_closure_wrapper309 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper319 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding2(a, state.b, arg0); + return __wbg_elem_binding1(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(78)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(79)(a, state.b); else state.a = a; } } @@ -902,16 +903,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper317 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper321 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding3(a, state.b, arg0); + return __wbg_elem_binding2(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(78)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(79)(a, state.b); else state.a = a; } } @@ -920,16 +921,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper1070 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper315 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding0(a, state.b, arg0); + return __wbg_elem_binding5(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(296)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(79)(a, state.b); else state.a = a; } } @@ -938,16 +939,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper650 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper654 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = () => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding6(a, state.b, ); + return __wbg_elem_binding0(a, state.b, ); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(227)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(228)(a, state.b); else state.a = a; } } @@ -956,16 +957,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper315 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper1074 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding1(a, state.b, arg0); + return __wbg_elem_binding3(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(78)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(297)(a, state.b); else state.a = a; } } @@ -974,7 +975,7 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper311 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper313 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; @@ -983,7 +984,7 @@ function init(module) { try { return __wbg_elem_binding4(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(78)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(79)(a, state.b); else state.a = a; } } @@ -992,16 +993,16 @@ function init(module) { const ret = real; return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper313 = function(arg0, arg1, arg2) { + imports.wbg.__wbindgen_closure_wrapper317 = function(arg0, arg1, arg2) { const state = { a: arg0, b: arg1, cnt: 1 }; const real = (arg0) => { state.cnt++; const a = state.a; state.a = 0; try { - return __wbg_elem_binding5(a, state.b, arg0); + return __wbg_elem_binding6(a, state.b, arg0); } finally { - if (--state.cnt === 0) wasm.__wbg_function_table.get(78)(a, state.b); + if (--state.cnt === 0) wasm.__wbg_function_table.get(79)(a, state.b); else state.a = a; } } diff --git a/teleterm/static/teleterm_web_bg.wasm b/teleterm/static/teleterm_web_bg.wasm index d89572a..e4870a3 100644 Binary files a/teleterm/static/teleterm_web_bg.wasm and b/teleterm/static/teleterm_web_bg.wasm differ -- cgit v1.2.3-54-g00ecf