Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Updating engine.io configuration methods. #957

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
51 changes: 23 additions & 28 deletions lib/connectors/sioconnector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var httpServer = require('http').createServer();
var sio = require('socket.io');
var SioSocket = require('./siosocket');

var PKG_ID_BYTES = 4;
Expand Down Expand Up @@ -38,34 +38,26 @@ module.exports = Connector;
Connector.prototype.start = function(cb) {
var self = this;
// issue https://github.com/NetEase/pomelo-cn/issues/174
var opts = {}
if(!!this.opts) {
opts = this.opts;
}
else {
opts = {
if (!!this.opts) {
this.wsocket = sio.listen(this.port, this.opts);
} else {
this.wsocket = sio.listen(this.port, {
transports: [
'websocket', 'polling-xhr', 'polling-jsonp', 'polling'
]
};
'websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'flashsocket'
],
pingTimeout: this.heartbeatTimeout,
pingInterval: this.heartbeatInterval
});
}

var sio = require('socket.io')(httpServer, opts);

var port = this.port;
httpServer.listen(port, function () {
console.log('sio Server listening at port %d', port);
});
sio.set('resource', '/socket.io');
sio.set('transports', this.opts.transports);
sio.set('heartbeat timeout', this.heartbeatTimeout);
sio.set('heartbeat interval', this.heartbeatInterval);

sio.on('connection', function (socket) {
this.wsocket.sockets.on('connection', function(socket) {
var siosocket = new SioSocket(curId++, socket);
self.emit('connection', siosocket);
siosocket.on('closing', function(reason) {
siosocket.send({route: 'onKick', reason: reason});
siosocket.send({
route: 'onKick',
reason: reason
});
});
});

Expand All @@ -81,7 +73,7 @@ Connector.prototype.stop = function(force, cb) {
};

Connector.encode = Connector.prototype.encode = function(reqId, route, msg) {
if(reqId) {
if (reqId) {
return composeResponse(reqId, route, msg);
} else {
return composePush(route, msg);
Expand Down Expand Up @@ -126,17 +118,20 @@ var composeResponse = function(msgId, route, msgBody) {
};

var composePush = function(route, msgBody) {
return JSON.stringify({route: route, body: msgBody});
return JSON.stringify({
route: route,
body: msgBody
});
};

var parseIntField = function(str, offset, len) {
var res = 0;
for(var i=0; i<len; i++) {
if(i > 0) {
for (var i = 0; i < len; i++) {
if (i > 0) {
res <<= 8;
}
res |= str.charCodeAt(offset + i) & 0xff;
}

return res;
};
};