diff --git a/js/quad-ws.js b/js/quad-ws.js index aff48ba..1a16988 100644 --- a/js/quad-ws.js +++ b/js/quad-ws.js @@ -70,7 +70,7 @@ function ws_write(id, ptr, len) { return false; } function ws_available(id) { - if (ws[id].received.length == 0) return -1; + if (ws[id] != null || ws[id].received.length == 0) return -1; return ws[id].received[0].length; } diff --git a/src/lib.rs b/src/lib.rs index 6a90d3d..383c44d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,8 +24,8 @@ impl QuadWs { channel: ws_open_rust(url).unwrap(), } } - pub fn write(&mut self) -> bool { - ws_write_rust(&mut self.channel, vec![]) + pub fn write(&mut self, data: Vec) -> bool { + ws_write_rust(&mut self.channel, data) } pub fn close(&mut self) { ws_close_rust(&mut self.channel) diff --git a/src/wasm.rs b/src/wasm.rs index 8a72e9c..d49d78b 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -32,8 +32,8 @@ pub fn ws_read_rust(socket: &mut WsChannnel) -> Option> { if available < 0 { return None; } - let mut buffer = vec![0; available as usize]; - unsafe { ws_read(*socket, buffer.as_mut_ptr(), available as u32) }; + let buffer = vec![0; available as usize]; + unsafe { ws_read(*socket, buffer.as_ptr(), available as u32) }; return Some(buffer); }