gearheads
/
mastodon
Archived
2
0
Fork 0

Re-add stream end log for WebSocket (#3397)

gh/stable
Clworld 2017-05-29 02:14:44 +09:00 committed by Eugen Rochko
parent 3fa8512474
commit 45837c533e
1 changed files with 8 additions and 6 deletions

View File

@ -315,12 +315,14 @@ const startWorker = (workerId) => {
}; };
// Setup stream end for WebSockets // Setup stream end for WebSockets
const streamWsEnd = ws => (id, listener) => { const streamWsEnd = (req, ws) => (id, listener) => {
ws.on('close', () => { ws.on('close', () => {
log.verbose(req.requestId, `Ending stream for ${req.accountId}`);
unsubscribe(id, listener); unsubscribe(id, listener);
}); });
ws.on('error', e => { ws.on('error', e => {
log.verbose(req.requestId, `Ending stream for ${req.accountId}`);
unsubscribe(id, listener); unsubscribe(id, listener);
}); });
}; };
@ -370,19 +372,19 @@ const startWorker = (workerId) => {
switch(location.query.stream) { switch(location.query.stream) {
case 'user': case 'user':
streamFrom(`timeline:${req.accountId}`, req, streamToWs(req, ws), streamWsEnd(ws)); streamFrom(`timeline:${req.accountId}`, req, streamToWs(req, ws), streamWsEnd(req, ws));
break; break;
case 'public': case 'public':
streamFrom('timeline:public', req, streamToWs(req, ws), streamWsEnd(ws), true); streamFrom('timeline:public', req, streamToWs(req, ws), streamWsEnd(req, ws), true);
break; break;
case 'public:local': case 'public:local':
streamFrom('timeline:public:local', req, streamToWs(req, ws), streamWsEnd(ws), true); streamFrom('timeline:public:local', req, streamToWs(req, ws), streamWsEnd(req, ws), true);
break; break;
case 'hashtag': case 'hashtag':
streamFrom(`timeline:hashtag:${location.query.tag}`, req, streamToWs(req, ws), streamWsEnd(ws), true); streamFrom(`timeline:hashtag:${location.query.tag}`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
break; break;
case 'hashtag:local': case 'hashtag:local':
streamFrom(`timeline:hashtag:${location.query.tag}:local`, req, streamToWs(req, ws), streamWsEnd(ws), true); streamFrom(`timeline:hashtag:${location.query.tag}:local`, req, streamToWs(req, ws), streamWsEnd(req, ws), true);
break; break;
default: default:
ws.close(); ws.close();