Skip to content

Commit

Permalink
upgrade socket.io 1.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasyni committed Jan 20, 2017
1 parent 86804e1 commit cbbf158
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3,805 deletions.
34 changes: 23 additions & 11 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 sio = require('socket.io');
var httpServer = require('http').createServer();
var SioSocket = require('./siosocket');

var PKG_ID_BYTES = 4;
Expand Down Expand Up @@ -38,22 +38,34 @@ 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) {
this.wsocket = sio.listen(this.port, this.opts);
opts = this.opts;
}
else {
this.wsocket = sio.listen(this.port, {
opts = {
transports: [
'websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'flashsocket'
'websocket', 'polling-xhr', 'polling-jsonp', 'polling'
]
});
};
}
this.wsocket.set('close timeout', this.closeTimeout);
this.wsocket.set('heartbeat timeout', this.heartbeatTimeout);
this.wsocket.set('heartbeat interval', this.heartbeatInterval);
this.wsocket.set('heartbeats', this.heartbeats);
this.wsocket.set('log level', 1);
this.wsocket.sockets.on('connection', function (socket) {

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('path', '/socket.io');
sio.set('transports', this.opts.transports);
sio.set('close timeout', this.closeTimeout);
sio.set('heartbeat timeout', this.heartbeatTimeout);
sio.set('heartbeat interval', this.heartbeatInterval);
sio.set('heartbeats', this.heartbeats);
sio.set('log level', 1);

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) {
Expand Down
10 changes: 5 additions & 5 deletions template/game-server/app.js.sio
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ app.configure('production|development', 'connector', function(){
app.set('connectorConfig',
{
connector : pomelo.connectors.sioconnector,
//websocket, htmlfile, xhr-polling, jsonp-polling, flashsocket
transports : ['websocket'],
// 'websocket', 'polling-xhr', 'polling-jsonp', 'polling'
transports : ['websocket', 'polling'],
heartbeats : true,
closeTimeout : 60,
heartbeatTimeout : 60,
heartbeatInterval : 25
closeTimeout : 60 * 1000,
heartbeatTimeout : 60 * 1000,
heartbeatInterval : 25 * 1000
});
});

Expand Down
2 changes: 1 addition & 1 deletion template/web-server/public/js/lib/pomeloclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ var bt2Str = function(byteArray,start,end) {
url += ':' + port;
}

socket = io.connect(url, {'force new connection': true, reconnect: false});
socket = io(url, {'force new connection': true, reconnect: false});

socket.on('connect', function(){
console.log('[pomeloclient.init] websocket connected!');
Expand Down
Loading

0 comments on commit cbbf158

Please sign in to comment.