Created
          June 26, 2011 08:30 
        
      - 
      
- 
        Save dvv/1047407 to your computer and use it in GitHub Desktop. 
    socket handshake info simplified
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | --- memory.js.orig 2011-06-23 19:37:15.000000000 +0400 | |
| +++ memory.js 2011-06-26 13:03:51.000000000 +0400 | |
| @@ -26,7 +26,6 @@ | |
| */ | |
| function Memory (opts) { | |
| - this.handshaken = []; | |
| this.clientsMap = {}; | |
| this.rooms = {}; | |
| }; | |
| @@ -47,7 +46,8 @@ | |
| Memory.prototype.handshake = function (data, fn) { | |
| var id = this.generateId(); | |
| - this.handshaken.push(id); | |
| + // N.B. later at any point just use client.get('handshaken', ...) | |
| + this.client(id).set('handshaken', data); | |
| fn(null, id); | |
| return this; | |
| }; | |
| @@ -59,7 +59,7 @@ | |
| */ | |
| Memory.prototype.isHandshaken = function (id, fn) { | |
| - fn(null, ~this.handshaken.indexOf(id)); | |
| + fn(null, !!this.clientsMap[id]); | |
| return this; | |
| }; | |
| @@ -96,14 +96,11 @@ | |
| */ | |
| Memory.prototype.disconnect = function (id, force, reason) { | |
| - if (~this.handshaken.indexOf(id)) { | |
| + if (this.clientsMap[id]) { | |
| this.log.debug('destroying dispatcher for', id); | |
| - this.handshaken.splice(this.handshaken.indexOf(id), 1); | |
| - if (this.clientsMap[id]) { | |
| - this.clientsMap[id].destroy(); | |
| - delete this.clientsMap[id]; | |
| - } | |
| + this.clientsMap[id].destroy(); | |
| + delete this.clientsMap[id]; | |
| if (force) | |
| this.publish('disconnect-force:' + id, reason); | |
| @@ -310,6 +307,7 @@ | |
| */ | |
| Client.prototype.destroy = function () { | |
| + this.dict = {}; | |
| this.buffer = null; | |
| }; | |
| @@ -320,7 +318,7 @@ | |
| */ | |
| Client.prototype.get = function (key, fn) { | |
| - fn(null, this.dict[key]); | |
| + fn.call(this, null, this.dict[key]); | |
| return this; | |
| }; | |
| @@ -332,7 +330,7 @@ | |
| Client.prototype.set = function (key, value, fn) { | |
| this.dict[key] = value; | |
| - fn && fn(null); | |
| + fn && fn.call(this, null); | |
| return this; | |
| }; | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment