Replace ws with uws (#2807)

* Replace ws with uws

* fix indent

* Adjust indentation

* remove trailing space
lolsob-rspec
Eshin Kunishima 2017-05-07 00:05:38 +09:00 committed by Eugen Rochko
parent 0682e4fe1a
commit 0a9c2152c9
3 changed files with 16 additions and 18 deletions

View File

@ -99,11 +99,11 @@
"style-loader": "^0.16.1",
"utf-8-validate": "^3.0.1",
"uuid": "^3.0.1",
"uws": "^0.14.5",
"webpack": "^2.4.1",
"webpack-manifest-plugin": "^1.1.0",
"webpack-merge": "^4.1.0",
"websocket.js": "^0.1.7",
"ws": "^2.1.0"
"websocket.js": "^0.1.7"
},
"devDependencies": {
"@kadira/storybook": "^2.35.3",

View File

@ -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) {

View File

@ -6671,10 +6671,6 @@ uid-number@~0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
ultron@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.0.tgz#b07a2e6a541a815fc6a34ccd4533baec307ca864"
uniq@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
@ -6765,6 +6761,10 @@ uuid@^3.0.0, uuid@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"
uws@^0.14.5:
version "0.14.5"
resolved "https://registry.yarnpkg.com/uws/-/uws-0.14.5.tgz#67aaf33c46b2a587a5f6666d00f7691328f149dc"
v8flags@^2.0.10:
version "2.0.11"
resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.0.11.tgz#bca8f30f0d6d60612cc2c00641e6962d42ae6881"
@ -7067,12 +7067,6 @@ write@^0.2.1:
dependencies:
mkdirp "^0.5.1"
ws@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-2.1.0.tgz#b24eaed9609f8632dd51e3f7698619a90fddcc92"
dependencies:
ultron "~1.1.0"
xdg-basedir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-2.0.0.tgz#edbc903cc385fc04523d966a335504b5504d1bd2"