@@ -12,7 +12,15 @@ import { io, Socket } from 'socket.io-client';
1212export const SocketIoTransportProvider : MessageTransportProvider = {
1313 id : 'socket.io' ,
1414 createTransport : ( url , headers ) => {
15+ const parsedUrl = new URL ( url ) ;
16+ let path = parsedUrl . pathname ;
17+ if ( path && ! path . endsWith ( '/' ) ) {
18+ path += '/' ;
19+ }
20+ // Path always ends in .../socket.io
21+ path += 'socket.io' ;
1522 const socket = io ( url , {
23+ path,
1624 extraHeaders : headers
1725 } ) ;
1826 const transport = new SocketIoTransport ( socket ) ;
@@ -44,6 +52,7 @@ export class SocketIoTransport implements MessageTransport {
4452
4553 constructor ( protected socket : Socket ) {
4654 this . socket . on ( 'disconnect' , ( _reason , _description ) => {
55+ this . ready . reject ( ) ;
4756 this . ready = new Deferred ( ) ;
4857 // Give it 30 seconds to reconnect before firing the disconnect event
4958 this . disconnectTimeout = setTimeout ( ( ) => {
@@ -59,8 +68,19 @@ export class SocketIoTransport implements MessageTransport {
5968 }
6069 this . onReconnectEmitter . fire ( ) ;
6170 } ) ;
62- this . socket . on ( 'error' , ( ) => this . onErrorEmitter . fire ( 'Websocket connection closed unexpectedly.' ) ) ;
63- this . socket . on ( 'connect' , ( ) => this . ready . resolve ( ) ) ;
71+ const timeout = setTimeout ( ( ) => {
72+ this . onErrorEmitter . fire ( 'Websocket connection timed out.' ) ;
73+ this . ready . reject ( ) ;
74+ } , 30_000 ) ;
75+ this . socket . on ( 'error' , ( ) => {
76+ this . onErrorEmitter . fire ( 'Websocket connection closed unexpectedly.' ) ;
77+ this . ready . reject ( ) ;
78+ clearTimeout ( timeout ) ;
79+ } ) ;
80+ this . socket . on ( 'connect' , ( ) => {
81+ this . ready . resolve ( ) ;
82+ clearTimeout ( timeout ) ;
83+ } ) ;
6484 }
6585
6686 async write ( data : Uint8Array ) : Promise < void > {
0 commit comments