@@ -53,8 +53,7 @@ export class WsServerManager {
5353 private onUpgrade = ( request : IncomingMessage , socket : Duplex , head : Buffer ) : void => {
5454 const { pathname } = new URL ( request . url ! , 'ws://localhost:51040' )
5555
56- if ( ! this . validateOrigin ( request . headers . origin ! )
57- || this . validateConnectionSecret ( request ) ) {
56+ if ( ! this . validateOrigin ( request . headers . origin ?? '' ) || ! this . validateConnectionSecret ( request ) ) {
5857 console . error ( 'Unauthorized request from' , request . headers . origin ) ;
5958 socket . write ( 'HTTP/1.1 401 Unauthorized\r\n\r\n' )
6059 socket . destroy ( ) ;
@@ -63,7 +62,10 @@ export class WsServerManager {
6362
6463 if ( pathname === '/ws' && this . handlerMap . has ( 'default' ) ) {
6564 const wss = this . wsServerMap . get ( 'default' ) ;
66- wss ?. handleUpgrade ( request , socket , head , ( ws , request ) => this . handlerMap . get ( 'default' ) ! ( ws , this , request ) ) ;
65+ wss ?. handleUpgrade ( request , socket , head , ( ws , request ) => {
66+ console . log ( 'New client connected!' )
67+ this . handlerMap . get ( 'default' ) ! ( ws , this , request )
68+ } ) ;
6769 return ;
6870 }
6971
@@ -79,15 +81,18 @@ export class WsServerManager {
7981
8082 const wss = this . wsServerMap . get ( sessionId ) ! ;
8183
82- wss . handleUpgrade ( request , socket , head , ( ws , request ) => this . handlerMap . get ( sessionId ) ! ( ws , this , request ) ) ;
84+ wss . handleUpgrade ( request , socket , head , ( ws , request ) => {
85+ console . log ( 'New ws session!' )
86+ this . handlerMap . get ( sessionId ) ! ( ws , this , request )
87+ } ) ;
8388 }
8489 }
8590
8691 private validateOrigin = ( origin : string ) : boolean =>
8792 config . corsAllowedOrigins . includes ( origin )
8893
8994 private validateConnectionSecret = ( request : IncomingMessage ) : boolean => {
90- const connectionSecret = request . headers [ 'connection-secret ' ] as string ;
95+ const connectionSecret = request . headers [ 'sec-websocket-protocol ' ] as string ;
9196 return connectionSecret === this . connectionSecret ;
9297 }
9398
0 commit comments