YUKI Hiroshi
null+****@clear*****
Thu Oct 17 16:13:17 JST 2013
YUKI Hiroshi 2013-10-17 16:13:17 +0900 (Thu, 17 Oct 2013) New Revision: a7d893f8599f000f40d50acb0476d3c4fc58b07d https://github.com/droonga/express-droonga/commit/a7d893f8599f000f40d50acb0476d3c4fc58b07d Message: Fill default route and subscriber by express-droonga itself Modified files: lib/adapter/api/socket.io.js lib/adapter/socket.io.js Modified: lib/adapter/api/socket.io.js (+1 -22) =================================================================== --- lib/adapter/api/socket.io.js 2013-10-17 15:37:41 +0900 (765e543) +++ lib/adapter/api/socket.io.js 2013-10-17 16:13:17 +0900 (16c2cb9) @@ -4,28 +4,7 @@ module.exports = { // 'status': {}, 'search': new command.SocketRequestResponse(), - - 'watch': new command.SocketPublishSubscribe({ - onSubscribe: function(data, connection) { - data.subscriber = /* data.subscriber || */ command.sha1sum(connection.routeToSelf); - data.route = /* data.route || */ connection.routeToSelf; - connection.emit('watch.subscribe', data); - }, - onSubscribed: function(data, socket) { - socket.emit('watch.subscribe.response', data); - }, - onUnsubscribe: function(data, connection) { - data.subscriber = /* data.subscriber || */ command.sha1sum(connection.routeToSelf); - data.route = /* data.route || */ connection.routeToSelf; - connection.emit('watch.unsubscribe', data); - }, - onUnsubscribed: function(data, socket) { - socket.emit('watch.unsubscribe.response', data); - }, - onNotify: function(data, socket) { - socket.emit('watch.notification', data); - } - })//, + 'watch': new command.SocketPublishSubscribe({})//, // 'createtable': {}, // 'removetable': {}, Modified: lib/adapter/socket.io.js (+16 -9) =================================================================== --- lib/adapter/socket.io.js 2013-10-17 15:37:41 +0900 (ce3c0f3) +++ lib/adapter/socket.io.js 2013-10-17 16:13:17 +0900 (9e046e8) @@ -34,19 +34,32 @@ exports.register = function(application, server, params) { throw new Error('A server instance is required!'); function createClientMessageHandler(commandName, socket, onResponseCallback) { + var commandDefinition = unifiedCommandSet[commandName]; + var defaultParameters = {}; + + var droongaMessageOptions = { + dataset: commandDefinition.dataset, + timeout: DEFAULT_TIMEOUT, + sessionId: socket.id + }; + if (command.PublishSubscribe.isInstance(commandDefinition)) { + defaultParameters.route = connection.getRouteToSelf(droongaMessageOptions); + defaultParameters.subscriber = command.sha1sum(defaultParameters.route); + } + return (function(data, clientOptions) { - var commandDefinition = unifiedCommandSet[commandName]; if (!commandDefinition) return; clientOptions = clientOptions || {}; var event = commandName; - var requestHandler = 'onRequest'; var responseHandler = 'onResponse'; if (command.PublishSubscribe.isInstance(commandDefinition)) { + data.subscriber = data.subscriber || defaultParameters.subscriber; + data.route = data.route || defaultParameters.route; if (/\.subscribe$/.test(commandName)) { requestHandler = 'onSubscribe'; responseHandler = 'onSubscribed'; @@ -55,12 +68,6 @@ exports.register = function(application, server, params) { responseHandler = 'onUnsubscribed'; } } - - var options = { - dataset: commandDefinition.dataset, - timeout: DEFAULT_TIMEOUT, - sessionId: socket.id - }; var callback = function(error, envelope) { if (error) { socket.emit('error', error); @@ -91,7 +98,7 @@ exports.register = function(application, server, params) { } }; - var wrappedConection = new wrapper.DroongaProtocolConnectionWrapper(connection, callback, options); + var wrappedConection = new wrapper.DroongaProtocolConnectionWrapper(connection, callback, droongaMessageOptions); if (commandDefinition[requestHandler]) { try { commandDefinition[requestHandler](data, wrappedConection); -------------- next part -------------- HTML����������������������������... 下載