Skip to content

Instantly share code, notes, and snippets.

@yitznewton
Forked from brettkiefer/socket.io.patch
Created July 3, 2014 11:59
Show Gist options
  • Save yitznewton/d5850b1b61f24d045346 to your computer and use it in GitHub Desktop.
Save yitznewton/d5850b1b61f24d045346 to your computer and use it in GitHub Desktop.
--- 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment