YUKI Hiroshi
null+****@clear*****
Fri Oct 11 18:39:24 JST 2013
YUKI Hiroshi 2013-10-11 18:39:24 +0900 (Fri, 11 Oct 2013) New Revision: c07a243ddab305555192817012eec2fcee4df708 https://github.com/droonga/express-droonga/commit/c07a243ddab305555192817012eec2fcee4df708 Message: Update rule of pub-sub around commands * subscribe => *.subscribe * unsubscribe => *.unsubscribe * publish => *.notification Modified files: lib/adapter/command.js lib/adapter/socket.io.js test/adapter/socket.io.test.js Modified: lib/adapter/command.js (+2 -2) =================================================================== --- lib/adapter/command.js 2013-10-11 17:36:26 +0900 (8328ea0) +++ lib/adapter/command.js 2013-10-11 18:39:24 +0900 (3b4e358) @@ -50,8 +50,8 @@ Object.defineProperty(PublishSubscribe.prototype, 'onSubscribe', { Object.defineProperty(PublishSubscribe.prototype, 'onSubscribed', { get: function() { return this._options.onSubscribed; } }); -Object.defineProperty(PublishSubscribe.prototype, 'onPublish', { - get: function() { return this._options.onPublish; } +Object.defineProperty(PublishSubscribe.prototype, 'onNotify', { + get: function() { return this._options.onNotify; } }); PublishSubscribe.isInstance = Command.isInstance; exports.PublishSubscribe = PublishSubscribe; Modified: lib/adapter/socket.io.js (+9 -6) =================================================================== --- lib/adapter/socket.io.js 2013-10-11 17:36:26 +0900 (38e7058) +++ lib/adapter/socket.io.js 2013-10-11 18:39:24 +0900 (e05a2a6) @@ -98,7 +98,7 @@ exports.register = function(application, server, params) { }); } - function createPublishedMessageHandler(commandName, socket) { + function createNotificationMessageHandler(commandName, socket) { return (function(body) { var commandDefinition = unifiedCommandSet[commandName]; @@ -106,9 +106,9 @@ exports.register = function(application, server, params) { var data = body; var wrappedSocket = new wrapper.SocketIOClientSocketWrapper(socket); - if (commandDefinition.onPublish) { + if (commandDefinition.onNotify) { try { - commandDefinition.onPublish(data, wrappedSocket); + commandDefinition.onNotify(data, wrappedSocket); } catch(error) { wrappedSocket.emit('error', error.message || error); } @@ -155,10 +155,13 @@ exports.register = function(application, server, params) { if (command.PublishSubscribe.isInstance(registeredCommand.definition)) { socket.on(registeredCommand.name + '.subscribe', createClientMessageHandler(registeredCommand.name, socket)); + socket.on(registeredCommand.name + '.unsubscribe', + createClientMessageHandler(registeredCommand.name, socket)); - var publishedMessageHandler = createPublishedMessageHandler(registeredCommand.name, socket); - connection.on(registeredCommand.name, publishedMessageHandler); - events.push(registeredCommand.name); + var publishedMessageHandler = createNotificationMessageHandler(registeredCommand.name, socket); + connection.on(registeredCommand.name + '.notification', + publishedMessageHandler); + events.push(registeredCommand.name + '.notification'); handlers[registeredCommand.name] = publishedMessageHandler; } else { socket.on(registeredCommand.name, Modified: test/adapter/socket.io.test.js (+2 -2) =================================================================== --- test/adapter/socket.io.test.js 2013-10-11 17:36:26 +0900 (8aeda86) +++ test/adapter/socket.io.test.js 2013-10-11 18:39:24 +0900 (71188d3) @@ -38,7 +38,7 @@ suite('Socket.IO Adapter', function() { onSubscribe: function(data, connection) { connection.emit('pubsub-mod-event.mod.subscribe', data); }, - onPublish: function(data, socket) { + onNotify: function(data, socket) { socket.emit('pubsub-mod-event.mod', data); } }), @@ -46,7 +46,7 @@ suite('Socket.IO Adapter', function() { onSubscribe: function(data, connection) { connection.emit('pubsub-mod-body.subscribe', 'modified request'); }, - onPublish: function(data, socket) { + onNotify: function(data, socket) { socket.emit('pubsub-mod-body', 'modified response'); } }) -------------- next part -------------- HTML����������������������������... Download