Skip to content

Commit 2c1851d

Browse files
refactor: simplify transport creation
The try/catch clause was needed for the JSONP transport, which was removed in [1]. [1]: b2c7381
1 parent 68f9e0d commit 2c1851d

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

lib/socket.ts

+9-20
Original file line numberDiff line numberDiff line change
@@ -448,34 +448,23 @@ export class Socket extends Emitter<
448448
* @private
449449
*/
450450
private open() {
451-
let transport;
452-
if (
453-
this.opts.rememberUpgrade &&
454-
Socket.priorWebsocketSuccess &&
455-
this.transports.indexOf("websocket") !== -1
456-
) {
457-
transport = "websocket";
458-
} else if (0 === this.transports.length) {
451+
if (this.transports.length === 0) {
459452
// Emit error on next tick so it can be listened to
460453
this.setTimeoutFn(() => {
461454
this.emitReserved("error", "No transports available");
462455
}, 0);
463456
return;
464-
} else {
465-
transport = this.transports[0];
466457
}
467-
this.readyState = "opening";
468458

469-
// Retry with the next transport if the transport is disabled (jsonp: false)
470-
try {
471-
transport = this.createTransport(transport);
472-
} catch (e) {
473-
debug("error while creating transport: %s", e);
474-
this.transports.shift();
475-
this.open();
476-
return;
477-
}
459+
const transportName =
460+
this.opts.rememberUpgrade &&
461+
Socket.priorWebsocketSuccess &&
462+
this.transports.indexOf("websocket") !== -1
463+
? "websocket"
464+
: this.transports[0];
465+
this.readyState = "opening";
478466

467+
const transport = this.createTransport(transportName);
479468
transport.open();
480469
this.setTransport(transport);
481470
}

0 commit comments

Comments
 (0)