YUKI Hiroshi
null+****@clear*****
Thu Jan 9 12:21:03 JST 2014
YUKI Hiroshi 2014-01-09 12:21:03 +0900 (Thu, 09 Jan 2014) New Revision: 2c60e17b2d154264fbeaf532e4916ece889b728e https://github.com/droonga/express-droonga/commit/2c60e17b2d154264fbeaf532e4916ece889b728e Message: Define default behavior of onPublish by command class Modified files: lib/adapter/command.js lib/adapter/socket.io.js Modified: lib/adapter/command.js (+6 -1) =================================================================== --- lib/adapter/command.js 2014-01-09 12:15:26 +0900 (48f0668) +++ lib/adapter/command.js 2014-01-09 12:21:03 +0900 (b35ecc4) @@ -74,9 +74,14 @@ PublishSubscribe.extend = function(targetClass) { Object.defineProperty(targetClass.prototype, 'messageType', { get: function() { return this._options.messageType; } }); + Object.defineProperty(targetClass.prototype, 'onPublish', { - get: function() { return this._options.onPublish; } + get: function() { return this._options.onPublish || this._onPublish; } }); + if (!targetClass.prototype._onPublish) + targetClass.prototype._onPublish = function(message, subscriberSocket) { + subscriberSocket.emit(this.messageType, message); + }; }; PublishSubscribe.extend(PublishSubscribe); exports.PublishSubscribe = PublishSubscribe; Modified: lib/adapter/socket.io.js (+3 -11) =================================================================== --- lib/adapter/socket.io.js 2014-01-09 12:15:26 +0900 (cab60b6) +++ lib/adapter/socket.io.js 2014-01-09 12:21:03 +0900 (a07418a) @@ -123,17 +123,9 @@ exports.register = function(application, server, params) { if (!subscriberSocket) return; try { - if (commandDefinition.onPublish) { - try { - commandDefinition.onPublish(message.body, subscriberSocket); - } catch(error) { - subscriberSocket.emit('error', error.message || error); - } - } else { - subscriberSocket.emit(messageEvent, message.body); - } - } catch(exception) { - console.log(exception + '\n' + exception.stack); + commandDefinition.onPublish(message.body, subscriberSocket); + } catch(error) { + subscriberSocket.emit('error', error.message || error); } }); }); -------------- next part -------------- HTML����������������������������...Download