about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/streaming/index.js b/streaming/index.js
index 883bf33f5..3a7764ee9 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -7,7 +7,7 @@ import redis from 'redis'
 import pg from 'pg'
 import log from 'npmlog'
 import url from 'url'
-import WebSocket from 'ws'
+import WebSocket from 'uws'
 import uuid from 'uuid'
 
 const env = process.env.NODE_ENV || 'development'
@@ -273,12 +273,16 @@ if (cluster.isMaster) {
 
   // Setup stream output to WebSockets
   const streamToWs = (req, ws) => {
-    const heartbeat = setInterval(() => ws.ping(), 15000)
+    const heartbeat = setInterval(() => {
+      // TODO: Can't add multiple listeners, due to the limitation of uws.
+      if (ws.readyState !== ws.OPEN) {
+        log.verbose(req.requestId, `Ending stream for ${req.accountId}`)
+        clearInterval(heartbeat)
+        return
+      }
 
-    ws.on('close', () => {
-      log.verbose(req.requestId, `Ending stream for ${req.accountId}`)
-      clearInterval(heartbeat)
-    })
+      ws.ping()
+    }, 15000)
 
     return (event, payload) => {
       if (ws.readyState !== ws.OPEN) {