diff --git a/src/client/cloak.js b/src/client/cloak.js index e5d330b..d7d8c49 100644 --- a/src/client/cloak.js +++ b/src/client/cloak.js @@ -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); diff --git a/src/server/cloak/index.js b/src/server/cloak/index.js index 38282c7..e13cfac 100644 --- a/src/server/cloak/index.js +++ b/src/server/cloak/index.js @@ -22,7 +22,6 @@ module.exports = (function() { var defaults = { port: 8090, - logLevel: 1, gameLoopSpeed: 100, defaultRoomSize: null, autoCreateRooms: false, @@ -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); @@ -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; } }; diff --git a/src/server/package.json b/src/server/package.json index edac764..1e0d8a5 100644 --- a/src/server/package.json +++ b/src/server/package.json @@ -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", diff --git a/test/test.js b/test/test.js index dec9c05..890843a 100644 --- a/test/test.js +++ b/test/test.js @@ -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(); + + } });