diff options
author | Eshin Kunishima <mikoim@users.noreply.github.com> | 2017-05-07 00:05:38 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-06 17:05:38 +0200 |
commit | 67b7d3d3b6565b88ef94b681b7f7db99b11d2435 (patch) | |
tree | 4f178e97833b899b5e7113068a3eebbc47388e71 /streaming | |
parent | 6358a169fd5ac903730d36d00901dfb73be316a7 (diff) |
Replace ws with uws (#2807)
* Replace ws with uws * fix indent * Adjust indentation * remove trailing space
Diffstat (limited to 'streaming')
-rw-r--r-- | streaming/index.js | 16 |
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) { |