YUKI Hiroshi
null+****@clear*****
Mon Jan 21 17:36:32 JST 2013
YUKI Hiroshi 2013-01-21 17:36:32 +0900 (Mon, 21 Jan 2013) New Revision: b73828632da4561c1b1d4ba2cfbb22c39f92ec7e https://github.com/groonga/express-kotoumi/commit/b73828632da4561c1b1d4ba2cfbb22c39f92ec7e Log: Accept extra commands for the socket.io API Modified files: lib/socket-adaptor.js test/socket-api.test.js Modified: lib/socket-adaptor.js (+5 -4) =================================================================== --- lib/socket-adaptor.js 2013-01-21 17:03:59 +0900 (74d60d1) +++ lib/socket-adaptor.js 2013-01-21 17:36:32 +0900 (6fd9e20) @@ -54,9 +54,10 @@ exports.registerHandlers = function(application, server, params) { var io = socketIo.listen(server); io.sockets.on('connection', function(socket) { - commands.forEach(function(command) { - socket.on(command, createRequestHandler(command, socket)); - connection.on('message', createResultHandler(command, socket)); - }); + commands.concat(params.extraCommands) + .forEach(function(command) { + socket.on(command, createRequestHandler(command, socket)); + connection.on('message', createResultHandler(command, socket)); + }); }); } Modified: test/socket-api.test.js (+31 -0) =================================================================== --- test/socket-api.test.js 2013-01-21 17:03:59 +0900 (a427bfb) +++ test/socket-api.test.js 2013-01-21 17:36:32 +0900 (6f1df0d) @@ -93,5 +93,36 @@ suite('Socket.IO API', function() { done(error); }); }); + + test('front to back, extra command', function(done) { + var connection = utils.createMockedBackendConnection() + .mock('emitMessage') + .takes('foobar', { requestMessage: true }); + + var application = express(); + server = utils.setupServer(application); + socketAdaptor.registerHandlers(application, server, { + connection: connection, + extraCommands: [ + 'foobar' + ] + }); + + clientSocket = utils.createClientSocket(); + + Deferred + .wait(0.01) + .next(function() { + clientSocket.emit('foobar', { requestMessage: true }); + }) + .wait(0.01) + .next(function() { + connection.assertThrows(); + done(); + }) + .error(function(error) { + done(error); + }); + }); }); -------------- next part -------------- HTML����������������������������... Descargar