|
1 | | - |
2 | 1 | /*! |
3 | 2 | * socket.io-node |
4 | 3 | * Copyright(c) 2011 LearnBoost <dev@learnboost.com> |
|
9 | 8 | * Module dependencies. |
10 | 9 | */ |
11 | 10 |
|
12 | | -var http = require('http') |
13 | | - , https = require('https') |
14 | | - , fs = require('fs') |
| 11 | +var fs = require('fs') |
15 | 12 | , url = require('url') |
16 | 13 | , util = require('./util') |
17 | 14 | , store = require('./store') |
@@ -55,7 +52,7 @@ var parent = module.parent.exports |
55 | 52 | * @api public |
56 | 53 | */ |
57 | 54 |
|
58 | | -function Manager (server) { |
| 55 | +function Manager (server, options) { |
59 | 56 | this.server = server; |
60 | 57 | this.namespaces = {}; |
61 | 58 | this.sockets = this.of(''); |
@@ -83,6 +80,10 @@ function Manager (server) { |
83 | 80 | , 'client store expiration': 15 |
84 | 81 | }; |
85 | 82 |
|
| 83 | + for (var i in options) { |
| 84 | + this.settings[i] = options[i]; |
| 85 | + } |
| 86 | + |
86 | 87 | this.initStore(); |
87 | 88 |
|
88 | 89 | // reset listeners |
@@ -380,6 +381,10 @@ Manager.prototype.onLeave = function (id, room) { |
380 | 381 | if (index >= 0) { |
381 | 382 | this.rooms[room].splice(index, 1); |
382 | 383 | } |
| 384 | + |
| 385 | + if (!this.rooms[room].length) { |
| 386 | + delete this.rooms[room]; |
| 387 | + } |
383 | 388 | delete this.roomClients[id][room]; |
384 | 389 | } |
385 | 390 | }; |
@@ -438,13 +443,13 @@ Manager.prototype.onClientMessage = function (id, packet) { |
438 | 443 | */ |
439 | 444 |
|
440 | 445 | Manager.prototype.onClientDisconnect = function (id, reason) { |
441 | | - this.onDisconnect(id); |
442 | | - |
443 | 446 | for (var name in this.namespaces) { |
444 | 447 | if (this.roomClients[id][name]) { |
445 | 448 | this.namespaces[name].handleDisconnect(id, reason); |
446 | 449 | } |
447 | 450 | } |
| 451 | + |
| 452 | + this.onDisconnect(id); |
448 | 453 | }; |
449 | 454 |
|
450 | 455 | /** |
@@ -476,8 +481,9 @@ Manager.prototype.onDisconnect = function (id, local) { |
476 | 481 |
|
477 | 482 | if (this.roomClients[id]) { |
478 | 483 | for (var room in this.roomClients[id]) { |
479 | | - this.rooms[room].splice(this.rooms[room].indexOf(id), 1); |
| 484 | + this.onLeave(id, room); |
480 | 485 | } |
| 486 | + delete this.roomClients[id] |
481 | 487 | } |
482 | 488 |
|
483 | 489 | this.store.destroyClient(id, this.get('client store expiration')); |
@@ -792,7 +798,7 @@ Manager.prototype.handleHandshake = function (data, req, res) { |
792 | 798 | var id = self.generateId() |
793 | 799 | , hs = [ |
794 | 800 | id |
795 | | - , self.get('heartbeat timeout') || '' |
| 801 | + , self.enabled('heartbeats') ? self.get('heartbeat timeout') || '' : '' |
796 | 802 | , self.get('close timeout') || '' |
797 | 803 | , self.transports(data).join(',') |
798 | 804 | ].join(':'); |
@@ -843,7 +849,9 @@ Manager.prototype.handshakeData = function (data) { |
843 | 849 | return { |
844 | 850 | headers: data.headers |
845 | 851 | , address: connectionAddress |
846 | | - , time: date.toString() |
| 852 | + , time: (new Date).toString() |
| 853 | + , query: data.query |
| 854 | + , url: data.request.url |
847 | 855 | , xdomain: !!data.request.headers.origin |
848 | 856 | , secure: data.request.connection.secure |
849 | 857 | , issued: +date |
|
0 commit comments