[Groonga-commit] droonga/express-droonga at c4d097c [master] Add "watch" pub/sub API as a builtin command

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Oct 16 17:21:59 JST 2013


YUKI Hiroshi	2013-10-16 17:21:59 +0900 (Wed, 16 Oct 2013)

  New Revision: c4d097c48e29cde050ed77371aa72b3b2aa84c49
  https://github.com/droonga/express-droonga/commit/c4d097c48e29cde050ed77371aa72b3b2aa84c49

  Message:
    Add "watch" pub/sub API as a builtin command

  Modified files:
    lib/adapter/api/socket.io.js

  Modified: lib/adapter/api/socket.io.js (+32 -1)
===================================================================
--- lib/adapter/api/socket.io.js    2013-10-16 17:21:30 +0900 (e77119d)
+++ lib/adapter/api/socket.io.js    2013-10-16 17:21:59 +0900 (093bda0)
@@ -1,8 +1,39 @@
 var command = require('../command');
+var crypto = require('crypto');
+
+function sha1sum(source) {
+  var hash = crypto.createHash('sha1');
+  hash = hash.update(source);
+  return hash.digest('hex');
+}
 
 module.exports = {
 //  'status': {},
-  'search': new command.SocketRequestResponse()//,
+
+  'search': new command.SocketRequestResponse(),
+
+  'watch': new command.SocketPublishSubscribe({
+    onSubscribe: function(data, connection) {
+      data.subscriber = /* data.subscriber || */ sha1sum(connection.routeToSelf);
+      data.route = /* data.route || */ connection.routeToSelf;
+      connection.emit('watch.subscribe', data);
+    },
+    onSubscribeResponse: function(data, socket) {
+      socket.emit('watch.subscribe.response', data);
+    },
+    onUnsubscribe: function(data, connection) {
+      data.subscriber = /* data.subscriber || */ sha1sum(connection.routeToSelf);
+      data.route = /* data.route || */ connection.routeToSelf;
+      connection.emit('watch.unsubscribe', data);
+    },
+    onUnsubscribeResponse: function(data, socket) {
+      socket.emit('watch.unsubscribe.response', data);
+    },
+    onNotify: function(data, socket) {
+      socket.emit('watch.notification', data);
+    }
+  })//,    
+
 //  'createtable': {},
 //  'removetable': {},
 //  'createcolumn': {},
-------------- next part --------------
HTML����������������������������...
Download 



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