Skip to content

Commit

Permalink
Migrate from uws to cws (mastodon#10805)
Browse files Browse the repository at this point in the history
  • Loading branch information
abcang authored and multiple creatures committed Nov 19, 2019
1 parent 0041faf commit 22e1150
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mastodon",
"license": "AGPL-3.0-or-later",
"engines": {
"node": ">=8 <11"
"node": ">=8.12 <12"
},
"scripts": {
"postversion": "git push --tags",
Expand Down Expand Up @@ -70,6 +70,7 @@
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.3.4",
"@clusterws/cws": "^0.14.0",
"array-includes": "^3.0.3",
"atrament": "^0.2.3",
"autoprefixer": "^9.4.10",
Expand Down Expand Up @@ -160,7 +161,6 @@
"tiny-queue": "^0.2.1",
"uglifyjs-webpack-plugin": "^2.1.2",
"uuid": "^3.1.0",
"uws": "10.148.0",
"webpack": "^4.29.6",
"webpack-assets-manifest": "^3.1.1",
"webpack-bundle-analyzer": "^3.1.0",
Expand Down
25 changes: 4 additions & 21 deletions streaming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const redis = require('redis');
const pg = require('pg');
const log = require('npmlog');
const url = require('url');
const WebSocket = require('uws');
const { WebSocketServer } = require('@clusterws/cws');
const uuid = require('uuid');
const fs = require('fs');

Expand Down Expand Up @@ -545,20 +545,13 @@ const startWorker = (workerId) => {
});
});

const wss = new WebSocket.Server({ server, verifyClient: wsVerifyClient });
const wss = new WebSocketServer({ server, verifyClient: wsVerifyClient });

wss.on('connection', ws => {
const req = ws.upgradeReq;
wss.on('connection', (ws, req) => {
const location = url.parse(req.url, true);
req.requestId = uuid.v4();
req.remoteAddress = ws._socket.remoteAddress;

ws.isAlive = true;

ws.on('pong', () => {
ws.isAlive = true;
});

let channel;

switch(location.query.stream) {
Expand Down Expand Up @@ -619,17 +612,7 @@ const startWorker = (workerId) => {
}
});

setInterval(() => {
wss.clients.forEach(ws => {
if (ws.isAlive === false) {
ws.terminate();
return;
}

ws.isAlive = false;
ws.ping('', false, true);
});
}, 30000);
wss.startAutoPing(30000);

attachServerWithConfig(server, address => {
log.info(`Worker ${workerId} now listening on ${address}`);
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,11 @@
lodash "^4.17.11"
to-fast-properties "^2.0.0"

"@clusterws/cws@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@clusterws/cws/-/cws-0.14.0.tgz#242824b6884454001340222a836db6f6c5e62bfb"
integrity sha512-knZj3KZNHIAGsX7TUc/0Q5gcx2bKMMcTPsAOZomLKdK5a4o/umKFlttWRH84Yr1nVlQy+UMO23qfDR8gRZ/4cw==

"@cnakazawa/watch@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef"
Expand Down Expand Up @@ -9290,11 +9295,6 @@ uuid@^3.0.1, uuid@^3.1.0, uuid@^3.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==

uws@10.148.0:
version "10.148.0"
resolved "https://registry.yarnpkg.com/uws/-/uws-10.148.0.tgz#3fcd35f083ca515e091cd33b2d78f0f51a666215"
integrity sha512-aJpFgMMyxubiE/ll4nj9nWoQbv0HzZZDWXfwyu78nuFObX0Zoyv3TWjkqKPQ1vb2sMPZoz67tri7QNE6dybNmQ==

v8-compile-cache@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.2.tgz#a428b28bb26790734c4fc8bc9fa106fccebf6a6c"
Expand Down

0 comments on commit 22e1150

Please sign in to comment.