aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-22 05:13:02 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-22 05:14:14 -0500
commit066aec146a075d0091903b490b6969a172b9d270 (patch)
tree981b3afd9144058a62395f37b0fc922caeb58f9e
parent2d9a95dc9be95c8ab842ce58c49ab466752f2829 (diff)
downloadteleterm-066aec146a075d0091903b490b6969a172b9d270.tar.gz
teleterm-066aec146a075d0091903b490b6969a172b9d270.zip
thread through the id to the actual message events
this is more accurate, since managing the lifetime of the websocket connection is a bit tricky
-rw-r--r--teleterm-web/src/lib.rs16
-rw-r--r--teleterm-web/src/model.rs15
-rw-r--r--teleterm-web/src/ws.rs13
-rw-r--r--teleterm/static/teleterm_web.js45
-rw-r--r--teleterm/static/teleterm_web_bg.wasmbin388582 -> 389447 bytes
5 files changed, 39 insertions, 50 deletions
diff --git a/teleterm-web/src/lib.rs b/teleterm-web/src/lib.rs
index 5c7d5c1..9ec713e 100644
--- a/teleterm-web/src/lib.rs
+++ b/teleterm-web/src/lib.rs
@@ -16,7 +16,7 @@ enum Msg {
List(seed::fetch::ResponseDataResult<Vec<crate::model::Session>>),
Refresh,
StartWatching(String),
- Watch(ws::WebSocketEvent),
+ Watch(String, ws::WebSocketEvent),
}
fn init(_: Url, orders: &mut impl Orders<Msg>) -> Init<crate::model::Model> {
@@ -49,7 +49,7 @@ fn update(
log(&format!("watching {}", id));
model.watch(&id, orders);
}
- Msg::Watch(event) => match event {
+ Msg::Watch(id, event) => match event {
ws::WebSocketEvent::Connected(_) => {
log("connected");
}
@@ -58,18 +58,10 @@ fn update(
model.watch_disconnect();
}
ws::WebSocketEvent::Message(msg) => {
- log(&format!(
- "message from id {}: {:?}",
- model.watch_id().unwrap(),
- msg
- ));
+ log(&format!("message from id {}: {:?}", id, msg));
}
ws::WebSocketEvent::Error(e) => {
- log(&format!(
- "error from id {}: {:?}",
- model.watch_id().unwrap(),
- e
- ));
+ log(&format!("error from id {}: {:?}", id, e));
}
},
}
diff --git a/teleterm-web/src/model.rs b/teleterm-web/src/model.rs
index 0e6f82d..fb36902 100644
--- a/teleterm-web/src/model.rs
+++ b/teleterm-web/src/model.rs
@@ -4,7 +4,6 @@ const LIST_URL: &str = "http://127.0.0.1:4145/list";
const WATCH_URL: &str = "ws://127.0.0.1:4145/watch";
struct WatchConn {
- id: String,
#[allow(dead_code)] // no idea why it thinks this is dead
ws: WebSocket,
}
@@ -35,13 +34,11 @@ impl Model {
) {
let ws = crate::ws::connect(
&format!("{}?id={}", WATCH_URL, id),
+ id,
crate::Msg::Watch,
orders,
);
- self.watch_conn = Some(WatchConn {
- id: id.to_string(),
- ws,
- })
+ self.watch_conn = Some(WatchConn { ws })
}
pub fn sessions(&self) -> &[Session] {
@@ -52,14 +49,6 @@ impl Model {
self.sessions = sessions;
}
- pub fn watch_id(&self) -> Option<&str> {
- if let Some(conn) = &self.watch_conn {
- Some(&conn.id)
- } else {
- None
- }
- }
-
pub fn watch_disconnect(&mut self) {
self.watch_conn = None;
}
diff --git a/teleterm-web/src/ws.rs b/teleterm-web/src/ws.rs
index a0c30a4..c5f9761 100644
--- a/teleterm-web/src/ws.rs
+++ b/teleterm-web/src/ws.rs
@@ -11,12 +11,14 @@ pub(crate) enum WebSocketEvent {
pub(crate) fn connect(
url: &str,
- msg: fn(WebSocketEvent) -> crate::Msg,
+ id: &str,
+ msg: fn(String, WebSocketEvent) -> crate::Msg,
orders: &mut impl Orders<crate::Msg>,
) -> WebSocket {
let ws = WebSocket::new(url).unwrap();
register_ws_handler(
+ id,
WebSocket::set_onopen,
WebSocketEvent::Connected,
msg,
@@ -24,6 +26,7 @@ pub(crate) fn connect(
orders,
);
register_ws_handler(
+ id,
WebSocket::set_onclose,
WebSocketEvent::Disconnected,
msg,
@@ -31,6 +34,7 @@ pub(crate) fn connect(
orders,
);
register_ws_handler(
+ id,
WebSocket::set_onmessage,
WebSocketEvent::Message,
msg,
@@ -38,6 +42,7 @@ pub(crate) fn connect(
orders,
);
register_ws_handler(
+ id,
WebSocket::set_onerror,
WebSocketEvent::Error,
msg,
@@ -49,9 +54,10 @@ pub(crate) fn connect(
}
fn register_ws_handler<T, F>(
+ id: &str,
ws_cb_setter: fn(&WebSocket, Option<&js_sys::Function>),
msg: F,
- ws_msg: fn(WebSocketEvent) -> crate::Msg,
+ ws_msg: fn(String, WebSocketEvent) -> crate::Msg,
ws: &web_sys::WebSocket,
orders: &mut impl Orders<crate::Msg>,
) where
@@ -60,8 +66,9 @@ fn register_ws_handler<T, F>(
{
let (app, msg_mapper) = (orders.clone_app(), orders.msg_mapper());
+ let id = id.to_string();
let closure = Closure::new(move |data| {
- app.update(msg_mapper(ws_msg(msg(data))));
+ app.update(msg_mapper(ws_msg(id.clone(), msg(data))));
});
ws_cb_setter(ws, Some(closure.as_ref().unchecked_ref()));
diff --git a/teleterm/static/teleterm_web.js b/teleterm/static/teleterm_web.js
index 36cfe4b..1132418 100644
--- a/teleterm/static/teleterm_web.js
+++ b/teleterm/static/teleterm_web.js
@@ -1,6 +1,13 @@
let wasm;
+function __wbg_elem_binding0(arg0, arg1, arg2) {
+ wasm.__wbg_function_table.get(54)(arg0, arg1, arg2);
+}
+function __wbg_elem_binding1(arg0, arg1) {
+ wasm.__wbg_function_table.get(174)(arg0, arg1);
+}
+
const heap = new Array(32);
heap.fill(undefined);
@@ -17,23 +24,17 @@ function addHeapObject(obj) {
heap[idx] = obj;
return idx;
}
-function __wbg_elem_binding0(arg0, arg1, arg2) {
- wasm.__wbg_function_table.get(244)(arg0, arg1, addHeapObject(arg2));
-}
-function __wbg_elem_binding1(arg0, arg1) {
- wasm.__wbg_function_table.get(174)(arg0, arg1);
-}
function __wbg_elem_binding2(arg0, arg1, arg2) {
wasm.__wbg_function_table.get(49)(arg0, arg1, addHeapObject(arg2));
}
function __wbg_elem_binding3(arg0, arg1, arg2) {
- wasm.__wbg_function_table.get(54)(arg0, arg1, arg2);
+ wasm.__wbg_function_table.get(49)(arg0, arg1, addHeapObject(arg2));
}
function __wbg_elem_binding4(arg0, arg1, arg2) {
wasm.__wbg_function_table.get(49)(arg0, arg1, addHeapObject(arg2));
}
function __wbg_elem_binding5(arg0, arg1, arg2) {
- wasm.__wbg_function_table.get(49)(arg0, arg1, addHeapObject(arg2));
+ wasm.__wbg_function_table.get(244)(arg0, arg1, addHeapObject(arg2));
}
function __wbg_elem_binding6(arg0, arg1, arg2) {
wasm.__wbg_function_table.get(49)(arg0, arg1, addHeapObject(arg2));
@@ -871,7 +872,7 @@ function init(module) {
const a = state.a;
state.a = 0;
try {
- return __wbg_elem_binding2(a, state.b, arg0);
+ return __wbg_elem_binding3(a, state.b, arg0);
} finally {
if (--state.cnt === 0) wasm.__wbg_function_table.get(50)(a, state.b);
else state.a = a;
@@ -882,16 +883,16 @@ function init(module) {
const ret = real;
return addHeapObject(ret);
};
- imports.wbg.__wbindgen_closure_wrapper213 = function(arg0, arg1, arg2) {
+ imports.wbg.__wbindgen_closure_wrapper505 = function(arg0, arg1, arg2) {
const state = { a: arg0, b: arg1, cnt: 1 };
- const real = (arg0) => {
+ const real = () => {
state.cnt++;
const a = state.a;
state.a = 0;
try {
- return __wbg_elem_binding5(a, state.b, arg0);
+ return __wbg_elem_binding1(a, state.b, );
} finally {
- if (--state.cnt === 0) wasm.__wbg_function_table.get(50)(a, state.b);
+ if (--state.cnt === 0) wasm.__wbg_function_table.get(175)(a, state.b);
else state.a = a;
}
}
@@ -900,16 +901,16 @@ function init(module) {
const ret = real;
return addHeapObject(ret);
};
- imports.wbg.__wbindgen_closure_wrapper503 = function(arg0, arg1, arg2) {
+ imports.wbg.__wbindgen_closure_wrapper219 = function(arg0, arg1, arg2) {
const state = { a: arg0, b: arg1, cnt: 1 };
- const real = () => {
+ const real = (arg0) => {
state.cnt++;
const a = state.a;
state.a = 0;
try {
- return __wbg_elem_binding1(a, state.b, );
+ return __wbg_elem_binding6(a, state.b, arg0);
} finally {
- if (--state.cnt === 0) wasm.__wbg_function_table.get(175)(a, state.b);
+ if (--state.cnt === 0) wasm.__wbg_function_table.get(50)(a, state.b);
else state.a = a;
}
}
@@ -925,7 +926,7 @@ function init(module) {
const a = state.a;
state.a = 0;
try {
- return __wbg_elem_binding3(a, state.b, arg0);
+ return __wbg_elem_binding0(a, state.b, arg0);
} finally {
if (--state.cnt === 0) wasm.__wbg_function_table.get(50)(a, state.b);
else state.a = a;
@@ -936,7 +937,7 @@ function init(module) {
const ret = real;
return addHeapObject(ret);
};
- imports.wbg.__wbindgen_closure_wrapper219 = function(arg0, arg1, arg2) {
+ imports.wbg.__wbindgen_closure_wrapper213 = function(arg0, arg1, arg2) {
const state = { a: arg0, b: arg1, cnt: 1 };
const real = (arg0) => {
state.cnt++;
@@ -961,7 +962,7 @@ function init(module) {
const a = state.a;
state.a = 0;
try {
- return __wbg_elem_binding6(a, state.b, arg0);
+ return __wbg_elem_binding2(a, state.b, arg0);
} finally {
if (--state.cnt === 0) wasm.__wbg_function_table.get(50)(a, state.b);
else state.a = a;
@@ -972,14 +973,14 @@ function init(module) {
const ret = real;
return addHeapObject(ret);
};
- imports.wbg.__wbindgen_closure_wrapper905 = function(arg0, arg1, arg2) {
+ imports.wbg.__wbindgen_closure_wrapper907 = 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(245)(a, state.b);
else state.a = a;
diff --git a/teleterm/static/teleterm_web_bg.wasm b/teleterm/static/teleterm_web_bg.wasm
index 2ee77b7..44138c5 100644
--- a/teleterm/static/teleterm_web_bg.wasm
+++ b/teleterm/static/teleterm_web_bg.wasm
Binary files differ