Browse Source

minor server-sent events fixes (#12945)

* 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.
Ben Lubar 1 month ago
parent
commit
0dfba0884e
2 changed files with 4 additions and 0 deletions
  1. 1
    0
      app/javascript/mastodon/stream.js
  2. 3
    0
      streaming/index.js

+ 1
- 0
app/javascript/mastodon/stream.js View File

@@ -92,6 +92,7 @@ export default function getStream(streamingAPIBaseURL, accessToken, stream, { co
92 92
     return ws;
93 93
   }
94 94
 
95
+  stream = stream.replace(/:/g, '/');
95 96
   params.push(`access_token=${accessToken}`);
96 97
   const es = new EventSource(`${streamingAPIBaseURL}/api/v1/streaming/${stream}?${params.join('&')}`);
97 98
 

+ 3
- 0
streaming/index.js View File

@@ -436,8 +436,11 @@ const startWorker = (workerId) => {
436 436
     const accountId = req.accountId || req.remoteAddress;
437 437
 
438 438
     res.setHeader('Content-Type', 'text/event-stream');
439
+    res.setHeader('Cache-Control', 'no-store');
439 440
     res.setHeader('Transfer-Encoding', 'chunked');
440 441
 
442
+    res.write(':)\n');
443
+
441 444
     const heartbeat = setInterval(() => res.write(':thump\n'), 15000);
442 445
 
443 446
     req.on('close', () => {

Loading…
Cancel
Save