Skip to content

Instantly share code, notes, and snippets.

@brettkiefer
Created April 20, 2012 12:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brettkiefer/2428207 to your computer and use it in GitHub Desktop.
Save brettkiefer/2428207 to your computer and use it in GitHub Desktop.
Our socket.io patches
--- a/socket.io/lib/manager.js Mon Nov 28 10:46:16 2011 -0500
+++ b/socket.io/lib/manager.js Mon Nov 28 10:49:24 2011 -0500
@@ -466,12 +466,13 @@
* @api private
*/
-Manager.prototype.onClientDisconnect = function (id, reason) {
+Manager.prototype.onClientDisconnect = function (id, reason, local) {
for (var name in this.namespaces) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id][name] !== 'undefined');
}
- this.onDisconnect(id);
+ if (local) this.store.publish('disconnect', id);
+ this.onDisconnect(id, local);
};
/**
--- a/socket.io/lib/manager.js Wed Dec 14 13:01:17 2011 -0500
+++ b/socket.io/lib/manager.js Thu Dec 15 09:33:21 2011 -0500
@@ -646,7 +646,7 @@
// flag as used
delete handshaken.issued;
this.onHandshake(data.id, handshaken);
- this.store.publish('handshake', data.id, handshaken);
+ //this.store.publish('handshake', data.id, handshaken);
// initialize the socket for all namespaces
for (var i in this.namespaces) {
--- a/socket.io/lib/manager.js Tue Dec 20 09:46:39 2011 -0500
+++ b/socket.io/lib/manager.js Wed Dec 21 23:45:36 2011 -0500
@@ -735,7 +735,7 @@
var id = self.generateId()
, hs = [
id
- , self.enabled('heartbeats') ? self.get('heartbeat timeout') || '' : ''
+ , self.enabled('heartbeats') ? self.get('heartbeat interval') || '' : ''
, self.get('close timeout') || ''
, self.transports(data).join(',')
].join(':');
--- a/socket.io/lib/namespace.js Wed Dec 14 13:01:17 2011 -0500
+++ b/socket.io/lib/namespace.js Thu Dec 15 09:33:21 2011 -0500
@@ -304,7 +304,7 @@
if (authorized) {
manager.onHandshake(sessid, newData || handshakeData);
- self.store.publish('handshake', sessid, newData || handshakeData);
+ //self.store.publish('handshake', sessid, newData || handshakeData);
connect();
} else {
error('unauthorized');
--- a/socket.io/lib/stores/redis.js Wed Dec 14 13:01:17 2011 -0500
+++ b/socket.io/lib/stores/redis.js Thu Dec 15 09:33:21 2011 -0500
@@ -102,6 +102,7 @@
*/
Redis.prototype.publish = function (name) {
+ if (name != "handshake") return;
var args = Array.prototype.slice.call(arguments, 1);
this.pub.publish(name, this.pack({ nodeId: this.nodeId, args: args }));
this.emit.apply(this, ['publish', name].concat(args));
@@ -117,6 +118,7 @@
var nsubs = 0;
Redis.prototype.subscribe = function (name, consumer, fn) {
+ if (name != "handshake") return;
if (!subs[name]) {
subs[name] = true;
nsubs++;
@@ -167,6 +169,7 @@
*/
Redis.prototype.unsubscribe = function (name, fn) {
+ if (name != "handshake") return;
if (subs[name]) {
delete subs[name];
nsubs--;
diff -r 4dc9e52989d3 socket.io/lib/transport.js
--- a/socket.io/lib/transport.js Mon Nov 28 10:46:16 2011 -0500
+++ b/socket.io/lib/transport.js Mon Nov 28 10:49:36 2011 -0500
@@ -457,14 +457,14 @@
if (!this.disconnected) {
this.log.info('transport end');
- var local = this.manager.transports[this.id];
+ var local = !!this.manager.transports[this.id];
this.close();
this.clearTimeouts();
this.disconnected = true;
if (local) {
- this.manager.onClientDisconnect(this.id, reason, true);
+ this.manager.onClientDisconnect(this.id, reason, local);
} else {
this.store.publish('disconnect:' + this.id, reason);
}
@yuvalmesika
Copy link

Hi ,
on socket.io/lib/manager.js file
you removed : self.enabled('heartbeats') ? self.get('heartbeat timeout') || '' : ''
and changed it with : self.enabled('heartbeats') ? self.get('heartbeat interval') || '' : ''
that cause my client to disconnect before sending the heartbeat , changing it back fixed the issue.
Just for reference I use 'heartbeat interval': 15 and 'heartbeat timeout' : 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment