Skip to content

Commit

Permalink
minor server-sent events fixes (mastodon#12945)
Browse files Browse the repository at this point in the history
* Send output on the server-sent events stream immediately so the client sees that it was successfully opened even if it doesn't have any messages.

Fix transparent SSE streaming for the public:local and hashtag:local stream types.

* Tell caches to never store server-sent events.
  • Loading branch information
BenLubar authored and Gargron committed Jan 24, 2020
1 parent 14ca559 commit 0dfba08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/javascript/mastodon/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default function getStream(streamingAPIBaseURL, accessToken, stream, { co
return ws;
}

stream = stream.replace(/:/g, '/');
params.push(`access_token=${accessToken}`);
const es = new EventSource(`${streamingAPIBaseURL}/api/v1/streaming/${stream}?${params.join('&')}`);

Expand Down
3 changes: 3 additions & 0 deletions streaming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,11 @@ const startWorker = (workerId) => {
const accountId = req.accountId || req.remoteAddress;

res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-store');
res.setHeader('Transfer-Encoding', 'chunked');

res.write(':)\n');

const heartbeat = setInterval(() => res.write(':thump\n'), 15000);

req.on('close', () => {
Expand Down

0 comments on commit 0dfba08

Please sign in to comment.