refactor(ext/websocket): use fastwebsockets client (#18725)

This commit is contained in:
Divy Srivastava 2023-04-20 21:54:22 +05:30 committed by GitHub
parent f520284081
commit 1976504c63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 183 additions and 451 deletions

View file

@ -317,9 +317,7 @@ class WebSocket extends EventTarget {
this[_bufferedAmount] += byteLength;
PromisePrototypeThen(
core.opAsync2(
this[_role] === SERVER
? "op_server_ws_send_binary"
: "op_ws_send_binary",
"op_ws_send_binary",
this[_rid],
view,
),
@ -357,7 +355,7 @@ class WebSocket extends EventTarget {
this[_bufferedAmount] += TypedArrayPrototypeGetByteLength(d);
PromisePrototypeThen(
core.opAsync2(
this[_role] === SERVER ? "op_server_ws_send_text" : "op_ws_send_text",
"op_ws_send_text",
this[_rid],
string,
),
@ -416,7 +414,7 @@ class WebSocket extends EventTarget {
PromisePrototypeCatch(
core.opAsync(
this[_role] === SERVER ? "op_server_ws_close" : "op_ws_close",
"op_ws_close",
this[_rid],
code,
reason,
@ -441,7 +439,7 @@ class WebSocket extends EventTarget {
async [_eventLoop]() {
while (this[_readyState] !== CLOSED) {
const { 0: kind, 1: value } = await core.opAsync2(
this[_role] === SERVER ? "op_server_ws_next_event" : "op_ws_next_event",
"op_ws_next_event",
this[_rid],
);
@ -508,7 +506,7 @@ class WebSocket extends EventTarget {
if (prevState === OPEN) {
try {
await core.opAsync(
this[_role] === SERVER ? "op_server_ws_close" : "op_ws_close",
"op_ws_close",
this[_rid],
code,
value,
@ -537,7 +535,7 @@ class WebSocket extends EventTarget {
this[_idleTimeoutTimeout] = setTimeout(async () => {
if (this[_readyState] === OPEN) {
await core.opAsync(
this[_role] === SERVER ? "op_server_ws_send" : "op_ws_send",
"op_ws_send",
this[_rid],
{
kind: "ping",
@ -548,7 +546,7 @@ class WebSocket extends EventTarget {
this[_readyState] = CLOSING;
const reason = "No response from ping frame.";
await core.opAsync(
this[_role] === SERVER ? "op_server_ws_close" : "op_ws_close",
"op_ws_close",
this[_rid],
1001,
reason,