YUKI Hiroshi
null+****@clear*****
Wed Jan 8 16:55:00 JST 2014
YUKI Hiroshi 2014-01-08 16:55:00 +0900 (Wed, 08 Jan 2014) New Revision: 70a3b519042594d808e5692f52951d49dcfcba03 https://github.com/droonga/express-droonga/commit/70a3b519042594d808e5692f52951d49dcfcba03 Message: Use "publish" instead of "notify(notification)" Modified files: lib/adapter/api/socket.io.js lib/adapter/command.js lib/adapter/socket.io.js test/adapter/socket.io.test.js Modified: lib/adapter/api/socket.io.js (+3 -3) =================================================================== --- lib/adapter/api/socket.io.js 2014-01-06 18:55:39 +0900 (6eec993) +++ lib/adapter/api/socket.io.js 2014-01-08 16:55:00 +0900 (a350458) @@ -15,9 +15,9 @@ module.exports = { data.subscriber = data.subscriber || command.sha1sum(data.route); connection.emit('watch.unsubscribe', data); }, - notification: 'watch.notification', - onNotify: function(data, socket) { - socket.emit('watch.notification', data); + messageType: 'watch.publish', + onPublish: function(data, socket) { + socket.emit('watch.publish', data); } })//, Modified: lib/adapter/command.js (+10 -10) =================================================================== --- lib/adapter/command.js 2014-01-06 18:55:39 +0900 (5f85558) +++ lib/adapter/command.js 2014-01-08 16:55:00 +0900 (06cad2f) @@ -69,11 +69,11 @@ PublishSubscribe.extend = function(targetClass) { Object.defineProperty(targetClass.prototype, 'onUnsubscribed', { get: function() { return this._options.onUnsubscribed; } }); - Object.defineProperty(targetClass.prototype, 'notification', { - get: function() { return this._options.notification; } + Object.defineProperty(targetClass.prototype, 'messageType', { + get: function() { return this._options.messageType; } }); - Object.defineProperty(targetClass.prototype, 'onNotify', { - get: function() { return this._options.onNotify; } + Object.defineProperty(targetClass.prototype, 'onPublish', { + get: function() { return this._options.onPublish; } }); }; PublishSubscribe.extend(PublishSubscribe); @@ -131,8 +131,8 @@ HTTPStreaming.extend = function(targetClass) { Object.defineProperty(targetClass.prototype, 'unsubscription', { get: function() { return this._options.unsubscription; } }); - Object.defineProperty(targetClass.prototype, 'notification', { - get: function() { return this._options.notification; } + Object.defineProperty(targetClass.prototype, 'messageType', { + get: function() { return this._options.messageType; } }); Object.defineProperty(targetClass.prototype, 'delimiter', { get: function() { return this._options.delimiter || targetClass.defaultDelimiter; } @@ -159,10 +159,10 @@ HTTPStreaming.extend = function(targetClass) { 'Transfer-Encoding': 'chunked' }); - var onNotify = function(message) { + var onPublish = function(message) { response.write(JSON.stringify(message.body) + self.delimiter); }; - connection.on(this.notification, onNotify); + connection.on(this.messageType, onPublish); var subscriptionMessage = this.createSubscription(request); if (!subscriptionMessage.route) { @@ -170,7 +170,7 @@ HTTPStreaming.extend = function(targetClass) { subscriptionMessage.route = route; } if (!subscriptionMessage.subscriber) { - var subscriberID = sha1sum(route + '#type=' + this.notification + '&id=' + connectionsCount); + var subscriberID = sha1sum(route + '#type=' + this.messageType + '&id=' + connectionsCount); subscriptionMessage.subscriber = subscriberID; } @@ -186,7 +186,7 @@ HTTPStreaming.extend = function(targetClass) { connection.emit(self.unsubscription, subscriptionMessage); request.removeListener('close', onDisconnected); response.removeListener('close', onDisconnected); - connection.removeListener(self.notification, onNotify); + connection.removeListener(self.messageType, onPublish); }; request.on('close', onDisconnected); response.on('close', onDisconnected); Modified: lib/adapter/socket.io.js (+14 -14) =================================================================== --- lib/adapter/socket.io.js 2014-01-06 18:55:39 +0900 (bbda90d) +++ lib/adapter/socket.io.js 2014-01-08 16:55:00 +0900 (4fdaf2d) @@ -110,27 +110,27 @@ exports.register = function(application, server, params) { } var allSubscribers = {}; - function createNotificationHandler(notificationEvent, commandDefinition) { + function createPublishedMessageHandler(messageEvent, commandDefinition) { return (function(message) { var subscriberIds = message.to; if (!Array.isArray(subscriberIds)) subscriberIds = [subscriberIds]; - var subscribers = allSubscribers[notificationEvent] || {}; + var subscribers = allSubscribers[messageEvent] || {}; subscriberIds.forEach(function(subscriberId) { var subscriberSocket = subscribers[subscriberId]; subscriberSocket = subscriberSocket && subscriberSocket.socket; if (!subscriberSocket) return; try { - if (commandDefinition.onNotify) { + if (commandDefinition.onPublish) { try { - commandDefinition.onNotify(message.body, subscriberSocket); + commandDefinition.onPublish(message.body, subscriberSocket); } catch(error) { subscriberSocket.emit('error', error.message || error); } } else { - subscriberSocket.emit(notificationEvent, message.body); + subscriberSocket.emit(messageEvent, message.body); } } catch(exception) { console.log(exception + '\n' + exception.stack); @@ -158,10 +158,10 @@ exports.register = function(application, server, params) { return; registeredCommands.push({ name: commandName, definition: definition }); - if (definition.notification) - connection.on(definition.notification, - createNotificationHandler(definition.notification, - definition)); + if (definition.messageType) + connection.on(definition.messageType, + createPublishedMessageHandler(definition.messageType, + definition)); }); var io = socketIo.listen(server); @@ -179,9 +179,9 @@ exports.register = function(application, server, params) { unifiedCommandSet[subscribeEvent] = unifiedCommandSet[unsubscribeEvent] = registeredCommand.definition; - var notificationEvent = registeredCommand.definition.notification; - var subscribers = allSubscribers[notificationEvent] || {}; - allSubscribers[notificationEvent] = subscribers; + var messageEvent = registeredCommand.definition.messageType; + var subscribers = allSubscribers[messageEvent] || {}; + allSubscribers[messageEvent] = subscribers; var subscribeHandler = createClientMessageHandler( subscribeEvent, @@ -227,8 +227,8 @@ exports.register = function(application, server, params) { connection.on('error', errorHandler); socket.on('disconnect', function() { - Object.keys(allSubscribers).forEach(function(notificationEvent) { - var subscribers = allSubscribers[notificationEvent]; + Object.keys(allSubscribers).forEach(function(messageEvent) { + var subscribers = allSubscribers[messageEvent]; if (subscribers && subscribers[subscriberId]) { subscribers[subscriberId].unsubscribe(); delete subscribers[subscriberId]; Modified: test/adapter/socket.io.test.js (+25 -25) =================================================================== --- test/adapter/socket.io.test.js 2014-01-06 18:55:39 +0900 (dc04853) +++ test/adapter/socket.io.test.js 2014-01-08 16:55:00 +0900 (4d4679c) @@ -35,7 +35,7 @@ suite('Socket.IO Adapter', function() { } }), 'pubsub': new command.SocketPublishSubscribe({ - notification: 'pubsub.notification' + messageType: 'pubsub.publish' }), 'pubsub-mod-event': new command.SocketPublishSubscribe({ onSubscribe: function(data, connection) { @@ -50,9 +50,9 @@ suite('Socket.IO Adapter', function() { onUnsubscribed: function(data, socket) { socket.emit('pubsub-mod-event.mod.unsubscribe.response', data); }, - notification: 'pubsub-mod-event.notification', - onNotify: function(data, socket) { - socket.emit('pubsub-mod-event.mod.notification', data); + messageType: 'pubsub-mod-event.publish', + onPublish: function(data, socket) { + socket.emit('pubsub-mod-event.mod.publish', data); } }), 'pubsub-mod-body': new command.SocketPublishSubscribe({ @@ -68,9 +68,9 @@ suite('Socket.IO Adapter', function() { onUnsubscribed: function(data, socket) { socket.emit('pubsub-mod-body.unsubscribe.response', 'modified response'); }, - notification: 'pubsub-mod-body.notification', - onNotify: function(data, socket) { - socket.emit('pubsub-mod-body.notification', 'modified response'); + messageType: 'pubsub-mod-body.publish', + onPublish: function(data, socket) { + socket.emit('pubsub-mod-body.publish', 'modified response'); } }) }; @@ -464,7 +464,7 @@ suite('Socket.IO Adapter', function() { expectedBackendBody: 'modified response' }); - test('notification', function(done) { + test('publish', function(done) { var mockedReceiver; var subscriberId; // step 0: setup @@ -495,15 +495,15 @@ suite('Socket.IO Adapter', function() { clientSockets[0].on('pubsub.unsubscribe.response', function(data) { mockedReceiver.receive(data); }); - clientSockets[0].on('pubsub.notification', function(data) { + clientSockets[0].on('pubsub.publish', function(data) { mockedReceiver.receive(data); }); - // step 1: notifications before subscribing + // step 1: published messages before subscribing mockedReceiver = nodemock .mock('receive').takes('nothing'); - return backend.sendMessage('pubsub.notification', - 'never notified', + return backend.sendMessage('pubsub.publish', + 'never published', { to: subscriberId }); }) .wait(0.01) @@ -530,23 +530,23 @@ suite('Socket.IO Adapter', function() { .next(function() { mockedReceiver.assertThrows(); - // step 3: notifications while subscribing + // step 3: published messages while subscribing mockedReceiver = nodemock - .mock('receive').takes('notified 1') - .mock('receive').takes('notified 2') - .mock('receive').takes('notified 3'); - return backend.sendMessage('pubsub.notification', - 'notified 1', + .mock('receive').takes('published 1') + .mock('receive').takes('published 2') + .mock('receive').takes('published 3'); + return backend.sendMessage('pubsub.publish', + 'published 1', { to: subscriberId }); }) .next(function() { - return backend.sendMessage('pubsub.notification', - 'notified 2', + return backend.sendMessage('pubsub.publish', + 'published 2', { to: subscriberId }); }) .next(function() { - return backend.sendMessage('pubsub.notification', - 'notified 3', + return backend.sendMessage('pubsub.publish', + 'published 3', { to: subscriberId }); }) .wait(0.01) @@ -573,11 +573,11 @@ suite('Socket.IO Adapter', function() { .next(function() { mockedReceiver.assertThrows(); - // step 5: notifications after unsubscribing + // step 5: published message after unsubscribing mockedReceiver = nodemock .mock('receive').takes('nothing'); - return backend.sendMessage('pubsub.notification', - 'never notified'); + return backend.sendMessage('pubsub.publish', + 'never published'); }) .wait(0.01) .next(function() { -------------- next part -------------- HTML����������������������������...Download