[Groonga-commit] groonga/express-kotoumi [master] Send pub-sub commands with ".subscribe" suffix from a client to the backend

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Feb 13 18:56:57 JST 2013


YUKI Hiroshi	2013-02-13 18:56:57 +0900 (Wed, 13 Feb 2013)

  New Revision: cbd8ca8d5522e298de829d9967eec7a85f3f1ad8
  https://github.com/groonga/express-kotoumi/commit/cbd8ca8d5522e298de829d9967eec7a85f3f1ad8

  Log:
    Send pub-sub commands with ".subscribe" suffix from a client to the backend

  Modified files:
    lib/frontend/socket.io-adaptor.js
    test/frontend-socket.io-adaptor.test.js

  Modified: lib/frontend/socket.io-adaptor.js (+8 -3)
===================================================================
--- lib/frontend/socket.io-adaptor.js    2013-02-13 18:51:57 +0900 (107f7a7)
+++ lib/frontend/socket.io-adaptor.js    2013-02-13 18:56:57 +0900 (aaa2cf2)
@@ -63,6 +63,8 @@ exports.register = function(application, server, params) {
           socket.emit(event, data);
         };
         options.timeout = DEFAULT_TIMEOUT;
+      } else if (model.PublishSubscribe.isInstance(commandDefinition)) {
+        commandName += '.subscribe';
       }
 
       connection.emitMessage(commandName, data, callback, options);
@@ -119,14 +121,17 @@ exports.register = function(application, server, params) {
     var events = [];
     var handlers = {};
     registeredCommands.forEach(function(command) {
-      socket.on(command.name,
-                createClientMessageHandler(command.name, socket));
-
       if (model.PublishSubscribe.isInstance(command.definition)) {
+        socket.on(command.name + '.subscribe',
+                  createClientMessageHandler(command.name, socket));
+
         var publishedMessageHandler = createPublishedMessageHandler(command.name, socket);
         connection.on(command.name, publishedMessageHandler);
         events.push(command.name);
         handlers[command.name] = publishedMessageHandler;
+      } else {
+        socket.on(command.name,
+                  createClientMessageHandler(command.name, socket));
       }
     });
 

  Modified: test/frontend-socket.io-adaptor.test.js (+13 -13)
===================================================================
--- test/frontend-socket.io-adaptor.test.js    2013-02-13 18:51:57 +0900 (0c01393)
+++ test/frontend-socket.io-adaptor.test.js    2013-02-13 18:56:57 +0900 (5f6ac7a)
@@ -167,17 +167,17 @@ suite('Socket.IO API', function() {
         ];
         connection = connection
           .mock('emitMessage')
-            .takes('pubsub', messages[0], null, {})
+            .takes('pubsub.subscribe', messages[0], null, {})
           .mock('emitMessage')
-            .takes('pubsub', messages[1], null, {})
+            .takes('pubsub.subscribe', messages[1], null, {})
           .mock('emitMessage')
-            .takes('pubsub', messages[2], null, {})
+            .takes('pubsub.subscribe', messages[2], null, {})
           .mock('emitMessage')
-            .takes('pubsub', messages[3], null, {})
+            .takes('pubsub.subscribe', messages[3], null, {})
           .mock('emitMessage')
-            .takes('pubsub', messages[4], null, {})
+            .takes('pubsub.subscribe', messages[4], null, {})
           .mock('emitMessage')
-            .takes('pubsub', messages[5], null, {});
+            .takes('pubsub.subscribe', messages[5], null, {});
 
         clientSockets[0].emit('pubsub', messages[0]);
         clientSockets[1].emit('pubsub', messages[1]);
@@ -394,8 +394,8 @@ suite('Socket.IO API', function() {
         var message = Math.random();
         connection = connection
           .mock('emitMessage')
-            .takes('foobar', message, null, {});
-        clientSockets[0].emit('foobar', message);
+            .takes('foobar.subscribe', message, null, {});
+        clientSockets[0].emit('foobar.subscribe', message);
       })
       .wait(0.01)
       .next(function() {
@@ -431,11 +431,11 @@ suite('Socket.IO API', function() {
 
         connection = connection
           .mock('emitMessage')
-            .takes('builder', 'builder request', null, {});
+            .takes('builder.subscribe', 'builder request', null, {});
         clientSockets[0].on('builder', function(data) {
           mockedReceiver.receive(data);
         });
-        clientSockets[0].emit('builder', { requestMessage: true });
+        clientSockets[0].emit('builder.subscribe', { requestMessage: true });
       })
       .wait(0.01)
       .next(function() {
@@ -480,18 +480,18 @@ suite('Socket.IO API', function() {
 
         connection = connection
           .mock('emitMessage')
-            .takes('custom', { requestMessage: true }, null, {});
+            .takes('custom.subscribe', { requestMessage: true }, null, {});
         clientSockets[0].on('custom', function(data) {
           mockedReceiver.receive(data);
         });
-        clientSockets[0].emit('customevent', { requestMessage: true });
+        clientSockets[0].emit('customevent.subscribe', { requestMessage: true });
       })
       .wait(0.01)
       .next(function() {
         connection.assertThrows();
         connection.controllers.customevent.trigger({
           statusCode: 200,
-          type: 'customevent.result',
+          type: 'customevent',
           body: { responseMessage: true }
         });
       })
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index