diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-03-30 21:22:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-30 17:52:12 +0200 |
commit | cc7f5c10156333acae8cf9d004bb859ba5c58115 (patch) | |
tree | 21525b97b6bbed6bcbbdf82d733bcd17ad2d7e33 | |
parent | 3abc53f8119409916776a5ff277a745022b60680 (diff) |
perf(ext/websocket): special op for sending text data frames (#18507)
Similar to #18506 but for Text frames.
-rw-r--r-- | ext/websocket/01_websocket.js | 5 | ||||
-rw-r--r-- | ext/websocket/lib.rs | 15 |
2 files changed, 16 insertions, 4 deletions
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index 399b46c52..d483608d8 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -325,10 +325,7 @@ class WebSocket extends EventTarget { const d = core.encode(string); this[_bufferedAmount] += d.byteLength; PromisePrototypeThen( - core.opAsync("op_ws_send", this[_rid], { - kind: "text", - value: string, - }), + core.opAsync("op_ws_send_text", this[_rid], string), () => { this[_bufferedAmount] -= d.byteLength; }, diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index 4195f39b8..8eac3e350 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -403,6 +403,20 @@ pub enum SendValue { } #[op] +pub async fn op_ws_send_text( + state: Rc<RefCell<OpState>>, + rid: ResourceId, + data: String, +) -> Result<(), AnyError> { + let resource = state + .borrow_mut() + .resource_table + .get::<WsStreamResource>(rid)?; + resource.send(Message::Text(data)).await?; + Ok(()) +} + +#[op] pub async fn op_ws_send( state: Rc<RefCell<OpState>>, rid: ResourceId, @@ -504,6 +518,7 @@ deno_core::extension!(deno_websocket, op_ws_send, op_ws_close, op_ws_next_event, + op_ws_send_text, ], esm = [ "01_websocket.js", "02_websocketstream.js" ], options = { |