Skip to content

Commit 2d81715

Browse files
author
Alec Gibson
committed
Move the handshake initialisation to the socket's onopen
This change moves the handshake initialisation to the socket's `onopen`. This avoids us having to wait for a message from the server before initiating the handshake, saving us half a round-trip. It should also make it easier to eventually refactor out the legacy initialisation.
1 parent a081492 commit 2d81715

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/client/connection.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ Connection.prototype.bindToSocket = function(socket) {
141141

142142
socket.onopen = function() {
143143
connection._setState('connecting');
144+
connection._initializeHandshake();
144145
};
145146

146147
socket.onerror = function(err) {
@@ -695,8 +696,8 @@ Connection.prototype._handleSnapshotFetch = function(error, message) {
695696

696697
Connection.prototype._handleLegacyInit = function(message) {
697698
// If the minor protocol version has been set, we can ignore this legacy
698-
// init message, and continue with the updated handshake protocol.
699-
if (message.protocolMinor) return this._initializeHandshake();
699+
// init message, and wait for a response to our handshake message.
700+
if (message.protocolMinor) return;
700701
this._initialize(message);
701702
};
702703

0 commit comments

Comments
 (0)