@kne/fastify-message 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -17,7 +17,9 @@ module.exports = fp(async function(fastify, options) {
17
17
  }
18
18
  }, options);
19
19
 
20
- fastify.register(require('@fastify/sse'));
20
+ if (!fastify.sse) {
21
+ fastify.register(require('@fastify/sse'));
22
+ }
21
23
 
22
24
  fastify.register(require('@kne/fastify-namespace'), {
23
25
  name: options.name,
@@ -257,14 +257,19 @@ module.exports = fp(async (fastify, options) => {
257
257
  }
258
258
  },
259
259
  async function (request, reply) {
260
- const intervalSeconds = request.query.interval;
261
- const { timezone } = request.query;
262
- reply.sse.keepAlive();
260
+ const intervalSeconds = request.query.interval ?? 5;
261
+ const { timezone, type, runnerType } = request.query;
262
+ const startTime = Date.now();
263
+ const maxDurationMs = 30 * 60 * 1000;
263
264
 
264
265
  async function* eventStream() {
265
266
  while (reply.sse.isConnected) {
267
+ if (Date.now() - startTime >= maxDurationMs) {
268
+ yield { event: 'timeout', data: JSON.stringify({ message: '连接已超过30分钟,自动断开' }) };
269
+ return;
270
+ }
266
271
  try {
267
- yield { data: JSON.stringify(await services.statistics.getRealtime({ timezone })) };
272
+ yield { data: JSON.stringify(await services.statistics.getRealtime({ timezone, type, runnerType })) };
268
273
  } catch (err) {
269
274
  yield { event: 'error', data: JSON.stringify({ message: err.message }) };
270
275
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-message",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "管理消息发送,支持sms消息,email消息等.",
5
5
  "main": "index.js",
6
6
  "scripts": {