This commit is contained in:
zizifn
2023-05-18 19:57:18 +08:00
committed by zizifn
parent 82538f0dcd
commit 5fa2258ce2
3 changed files with 10 additions and 2 deletions

View File

@@ -172,7 +172,7 @@ export default {
function safeCloseWebSocket(ws: WebSocket) {
try {
if (ws.readyState === WebSocket.READY_STATE_OPEN) {
if (ws.readyState !== WebSocket.READY_STATE_CLOSED) {
ws.close();
}
} catch (error) {

View File

@@ -24,7 +24,11 @@ export default {
}
});
webSocket.addEventListener('close', async (event) => {
console.log('-------------close-----------------', event);
console.log(
'-------------close-----------------',
event,
webSocket.readyState
);
webSocket.close();
});

View File

@@ -39,6 +39,10 @@ export function makeReadableWebSocketStream(
// https://streams.spec.whatwg.org/#example-rs-push-backpressure
controller.enqueue(vlessBuffer);
});
// The event means that the client closed the client -> server stream.
// However, the server -> client stream is still open until you call close() on the server side.
// The WebSocket protocol says that a separate close message must be sent in each direction to fully close the socket.
ws.addEventListener('error', (e: any) => {
log('socket has error');
readableStreamCancel = true;