mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
fix(runtime/websocket): respond to ping with pong (#8974)
This commit is contained in:
parent
c823211a2c
commit
f85cd54cb4
2 changed files with 15 additions and 3 deletions
|
@ -167,6 +167,7 @@
|
|||
this.#bufferedAmount += ta.size;
|
||||
core.jsonOpAsync("op_ws_send", {
|
||||
rid: this.#rid,
|
||||
kind: "binary",
|
||||
}, ta).then(() => {
|
||||
this.#bufferedAmount -= ta.size;
|
||||
});
|
||||
|
@ -193,6 +194,7 @@
|
|||
this.#bufferedAmount += d.size;
|
||||
core.jsonOpAsync("op_ws_send", {
|
||||
rid: this.#rid,
|
||||
kind: "text",
|
||||
text: string,
|
||||
}).then(() => {
|
||||
this.#bufferedAmount -= d.size;
|
||||
|
@ -265,6 +267,13 @@
|
|||
event.target = this;
|
||||
this.dispatchEvent(event);
|
||||
|
||||
this.#eventLoop();
|
||||
} else if (message.type === "ping") {
|
||||
core.jsonOpAsync("op_ws_send", {
|
||||
rid: this.#rid,
|
||||
kind: "pong",
|
||||
});
|
||||
|
||||
this.#eventLoop();
|
||||
} else if (message.type === "close") {
|
||||
this.#readyState = CLOSED;
|
||||
|
|
|
@ -216,6 +216,7 @@ pub async fn op_ws_create(
|
|||
#[serde(rename_all = "camelCase")]
|
||||
struct SendArgs {
|
||||
rid: u32,
|
||||
kind: String,
|
||||
text: Option<String>,
|
||||
}
|
||||
|
||||
|
@ -226,9 +227,11 @@ pub async fn op_ws_send(
|
|||
) -> Result<Value, AnyError> {
|
||||
let args: SendArgs = serde_json::from_value(args)?;
|
||||
|
||||
let msg = match args.text {
|
||||
Some(text) => Message::Text(text),
|
||||
None => Message::Binary(bufs[0].to_vec()),
|
||||
let msg = match args.kind.as_str() {
|
||||
"text" => Message::Text(args.text.unwrap()),
|
||||
"binary" => Message::Binary(bufs[0].to_vec()),
|
||||
"pong" => Message::Pong(vec![]),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let rid = args.rid;
|
||||
|
||||
|
|
Loading…
Reference in a new issue