Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ function Manager (server, options) {

var self = this;

// default error handler
server.on('error', function(err) {
self.log.warn('error raised: ' + err);
});

this.initStore();

this.on('set:store', function() {
Expand Down Expand Up @@ -267,6 +262,7 @@ Manager.prototype.initStore = function () {
this.connected = {};
this.open = {};
this.closed = {};
this.closedA = [];
this.rooms = {};
this.roomClients = {};

Expand Down Expand Up @@ -338,6 +334,8 @@ Manager.prototype.onOpen = function (id) {
if (this.closed[id]) {
var self = this;

this.closedA.splice(this.closedA.indexOf(id), 1);

this.store.unsubscribe('dispatch:' + id, function () {
delete self.closed[id];
});
Expand Down Expand Up @@ -426,6 +424,7 @@ Manager.prototype.onClose = function (id) {
}

this.closed[id] = [];
this.closedA.push(id);

var self = this;

Expand Down Expand Up @@ -468,7 +467,9 @@ Manager.prototype.onClientMessage = function (id, packet) {

Manager.prototype.onClientDisconnect = function (id, reason) {
for (var name in this.namespaces) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id][name] !== 'undefined');
if (this.roomClients[id][name]) {
this.namespaces[name].handleDisconnect(id, reason);
}
}

this.onDisconnect(id);
Expand Down Expand Up @@ -498,6 +499,7 @@ Manager.prototype.onDisconnect = function (id, local) {

if (this.closed[id]) {
delete this.closed[id];
this.closedA.splice(this.closedA.indexOf(id), 1);
}

if (this.roomClients[id]) {
Expand Down Expand Up @@ -813,10 +815,14 @@ Manager.prototype.verifyOrigin = function (request) {
if (origin) {
try {
var parts = url.parse(origin);
if(!parts.port)
{
parts.port = 80;
}
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
~origins.indexOf('*:' + parts.port);
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
~origins.indexOf('*:' + parts.port);
if (!ok) this.log.warn('illegal origin: ' + origin);
return ok;
} catch (ex) {
Expand Down Expand Up @@ -958,4 +964,4 @@ Manager.prototype.garbageCollection = function () {
this.onDisconnect(ids[i]);
}
}
};
};
7 changes: 5 additions & 2 deletions lib/transports/websocket/hybi-07-12.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
Expand Down Expand Up @@ -159,7 +158,11 @@ WebSocket.prototype.verifyOrigin = function (origin) {
if (origin) {
try {
var parts = url.parse(origin);
var ok =
if(!parts.port)
{
parts.port = 80;
}
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
~origins.indexOf('*:' + parts.port);
Expand Down
7 changes: 5 additions & 2 deletions lib/transports/websocket/hybi-16.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
Expand Down Expand Up @@ -159,7 +158,11 @@ WebSocket.prototype.verifyOrigin = function (origin) {
if (origin) {
try {
var parts = url.parse(origin);
var ok =
if(!parts.port)
{
parts.port = 80;
}
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
~origins.indexOf('*:' + parts.port);
Expand Down