File tree Expand file tree Collapse file tree
packages/nativescript-websockets Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments