Skip to content

Commit

Permalink
Merge pull request #88 from incompl/user-socket.io-configuration
Browse files Browse the repository at this point in the history
user socket.io server configuration
  • Loading branch information
Greg committed May 6, 2015
2 parents 3e8eb42 + 49136fd commit b7c063e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/client/cloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
'force new connection': true
};

if (options['socket.io']) {
ioOptions = _.extend(ioOptions, options['socket.io']);
if (options.socketIo) {
ioOptions = _.extend(ioOptions, options.socketIo);
}

socket = io.connect(url, ioOptions);
Expand Down
17 changes: 15 additions & 2 deletions src/server/cloak/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = (function() {

var defaults = {
port: 8090,
logLevel: 1,
gameLoopSpeed: 100,
defaultRoomSize: null,
autoCreateRooms: false,
Expand Down Expand Up @@ -90,7 +89,16 @@ module.exports = (function() {
delete config.express;
}

io.set('log level', config.logLevel);
// Cloak defaults Socket.IO log level to 1
io.set('log level', 1);

// Apply user Socket.IO settings
var ioConfig = config.socketIo;
if (typeof ioConfig === 'object') {
for (var key in ioConfig) {
io.set(key, ioConfig[key]);
}
}

lobby = new Room(cloak, 'Lobby', 0, events.lobby, true);

Expand Down Expand Up @@ -354,6 +362,11 @@ module.exports = (function() {

createTimer: function(name, millis, descending) {
return new Timer(name, millis || 0, descending || false);
},

// For testing
_getIo: function() {
return io;
}

};
Expand Down
2 changes: 1 addition & 1 deletion src/server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cloak",
"description": "A network layer for HTML5 games",
"version": "0.3.0",
"version": "0.4.0",
"homepage": "https://github.com/incompl/cloak",
"author": {
"name": "Greg and Darius at Bocoup",
Expand Down
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,29 @@ module.exports = _.extend(suite, {

server.run();
client.run(this.host);
},

// Test Socket.IO configuration on the server
serverIoConfig: function(test) {

test.expect(1);

var server = this.server;
var client = suite.createClient();

server.configure({
port: this.port,
socketIo: {
'heartbeat interval': 123
}
});

server.run();

test.equals(server._getIo().get('heartbeat interval'), 123);
test.done();


}

});

0 comments on commit b7c063e

Please sign in to comment.