summaryrefslogtreecommitdiffstats
path: root/webchat/sockjs_server_connection_transport.js
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2013-11-12 02:01:29 +0100
committerlassulus <lassulus@googlemail.com>2013-11-12 02:01:29 +0100
commit3531d46cc3644a64b990f904e40e4846b8242a07 (patch)
treea0289317e14a8011d7a6615010b70e5d21eff02c /webchat/sockjs_server_connection_transport.js
parentc6a7cd9027150fca42500b3bbc78be01993856f6 (diff)
webchat: refactor to rpc
Diffstat (limited to 'webchat/sockjs_server_connection_transport.js')
-rw-r--r--webchat/sockjs_server_connection_transport.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/webchat/sockjs_server_connection_transport.js b/webchat/sockjs_server_connection_transport.js
new file mode 100644
index 00000000..6f68b955
--- /dev/null
+++ b/webchat/sockjs_server_connection_transport.js
@@ -0,0 +1,26 @@
+
+module.exports = function make_sockjs_server_connection_transport (connection) {
+ var transport = {}
+
+ connection.on('data', function (data) {
+ try {
+ var message = JSON.parse(data)
+ } catch (error) {
+ return console.log('error', error)
+ }
+ transport.onmessage(message)
+ })
+ connection.on('close', function () {
+ })
+
+ transport.send = function (message) {
+ try {
+ var data = JSON.stringify(message)
+ } catch (error) {
+ return console.log('sockjs transport send error:', error)
+ }
+ connection.write(data)
+ }
+
+ return transport
+}