Skip to content

Commit 5c49fcf

Browse files
committed
fix: add restricted codes for WebSocket closure
1 parent ce5597d commit 5c49fcf

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/nativescript-websockets/bridge.android.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class NativeBridge extends NativeBridgeDefinition {
7272
nativeWs!: okhttp3.WebSocket;
7373
startLooper?: android.os.Looper;
7474
handler?: android.os.Handler;
75+
private _restrictedCodes = new Set([1004, 1005, 1006, 1015]);
7576
connect(url: string, protocols: string[], headers: HeaderType): void {
7677
this.startLooper = android.os.Looper.myLooper();
7778
this.handler = new android.os.Handler(this.startLooper);
@@ -169,6 +170,11 @@ export class NativeBridge extends NativeBridgeDefinition {
169170
this.ws._websocketOpen(param1.protocol().toString());
170171
}
171172
public onClosing(websocket: okhttp3.WebSocket, code: number, reason: string): void {
173+
// prevent invalid codes
174+
if (this._restrictedCodes.has(code)) {
175+
websocket.close(1000, reason);
176+
return;
177+
}
172178
websocket.close(code, reason);
173179
}
174180

@@ -180,7 +186,7 @@ export class NativeBridge extends NativeBridgeDefinition {
180186
this.handler.post(
181187
new java.lang.Runnable({
182188
run: action,
183-
})
189+
}),
184190
);
185191
} else {
186192
action();

0 commit comments

Comments
 (0)