mosquito-transport 1.7.2 → 1.7.4
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/TODO +2 -1
- package/lib/index.d.ts +10 -0
- package/lib/index.js +13 -7
- package/package.json +3 -2
package/TODO
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -633,6 +633,16 @@ interface MosquitoServerConfig {
|
|
|
633
633
|
corsOrigin?: CorsOptions;
|
|
634
634
|
maxRequestBufferSize?: number;
|
|
635
635
|
maxUploadBufferSize?: number;
|
|
636
|
+
/**
|
|
637
|
+
* How long the server waits for a pong from the client before disconnecting
|
|
638
|
+
* @default 4000
|
|
639
|
+
*/
|
|
640
|
+
pingTimeout?: number;
|
|
641
|
+
/**
|
|
642
|
+
* How often the server sends a ping to the client
|
|
643
|
+
* @default 1700
|
|
644
|
+
*/
|
|
645
|
+
pingInterval?: number;
|
|
636
646
|
uidLength?: number;
|
|
637
647
|
accessTokenInterval?: number;
|
|
638
648
|
refreshTokenExpiry?: number;
|
package/lib/index.js
CHANGED
|
@@ -334,7 +334,7 @@ const InternalRoutesList = [
|
|
|
334
334
|
];
|
|
335
335
|
|
|
336
336
|
const useMosquitoServer = (app, config) => {
|
|
337
|
-
const { projectName, port, corsOrigin, maxRequestBufferSize, onSocketSnapshot, onSocketError, enforceE2E_Encryption, preMiddlewares, onUserMounted } = config;
|
|
337
|
+
const { projectName, port, corsOrigin, maxRequestBufferSize, onSocketSnapshot, onSocketError, enforceE2E_Encryption, preMiddlewares, onUserMounted, pingTimeout, pingInterval } = config;
|
|
338
338
|
|
|
339
339
|
app.disable("x-powered-by");
|
|
340
340
|
|
|
@@ -401,15 +401,14 @@ const useMosquitoServer = (app, config) => {
|
|
|
401
401
|
|
|
402
402
|
const server = createServer(app);
|
|
403
403
|
const io = new Server(server, {
|
|
404
|
-
pingTimeout:
|
|
405
|
-
pingInterval:
|
|
404
|
+
pingTimeout: pingTimeout || 4000,
|
|
405
|
+
pingInterval: pingInterval || 1700,
|
|
406
406
|
...corsOrigin === undefined ? undefined : { cors: { origin: corsOrigin } },
|
|
407
407
|
maxHttpBufferSize: maxRequestBufferSize || (one_mb * 100)
|
|
408
408
|
});
|
|
409
409
|
|
|
410
410
|
io.on('connection', async socket => {
|
|
411
411
|
const initAuthHandshake = socket.handshake.auth;
|
|
412
|
-
const scope = {};
|
|
413
412
|
const restrictedRoute = [
|
|
414
413
|
...authLivePath,
|
|
415
414
|
...databaseLivePath
|
|
@@ -610,7 +609,6 @@ const useMosquitoServer = (app, config) => {
|
|
|
610
609
|
socket.on('disconnect', () => {
|
|
611
610
|
clonedSocket.disconnected = true;
|
|
612
611
|
});
|
|
613
|
-
// TODO: disconnected
|
|
614
612
|
onSocketSnapshot(clonedSocket);
|
|
615
613
|
} catch (e) {
|
|
616
614
|
onSocketError?.(Object.assign(simplifyCaughtError(e).simpleError, { socket }));
|
|
@@ -843,7 +841,7 @@ export default class MosquitoTransportServer {
|
|
|
843
841
|
reqBody = JSON.parse(body);
|
|
844
842
|
} catch (_) { }
|
|
845
843
|
} else reqBody = body;
|
|
846
|
-
} else if (req.headers['
|
|
844
|
+
} else if (req.headers['entity-encoded'] === '1' && req.body) {
|
|
847
845
|
reqBody = deserialize(req.body);
|
|
848
846
|
}
|
|
849
847
|
|
|
@@ -1249,7 +1247,9 @@ const validateServerConfig = (config, that) => {
|
|
|
1249
1247
|
onSocketError,
|
|
1250
1248
|
autoPurgeToken,
|
|
1251
1249
|
ffmpegEncoderArg,
|
|
1252
|
-
maxFfmpegTasks
|
|
1250
|
+
maxFfmpegTasks,
|
|
1251
|
+
pingTimeout,
|
|
1252
|
+
pingInterval
|
|
1253
1253
|
} = config;
|
|
1254
1254
|
|
|
1255
1255
|
if (
|
|
@@ -1310,6 +1310,12 @@ const validateServerConfig = (config, that) => {
|
|
|
1310
1310
|
if (maxUploadBufferSize !== undefined && (!Validator.POSITIVE_INTEGER(maxUploadBufferSize) || maxUploadBufferSize < 1024))
|
|
1311
1311
|
throw `"maxUploadBufferSize" must be a positive integer not lesser than 1024 (1kb)`;
|
|
1312
1312
|
|
|
1313
|
+
if (pingInterval !== undefined && (!Validator.POSITIVE_INTEGER(pingInterval) || pingInterval < 300))
|
|
1314
|
+
throw `"pingInterval" must be a positive integer not lesser than 300`;
|
|
1315
|
+
|
|
1316
|
+
if (pingTimeout !== undefined && (!Validator.POSITIVE_INTEGER(pingTimeout) || pingTimeout < 300))
|
|
1317
|
+
throw `"pingTimeout" must be a positive integer not lesser than 300`;
|
|
1318
|
+
|
|
1313
1319
|
if (databaseRules !== undefined && typeof databaseRules !== 'function')
|
|
1314
1320
|
throw `databaseRules type must be function but got ${typeof databaseRules}`;
|
|
1315
1321
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosquito-transport",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "Quickly spawn server infrastructure along robust authentication, database, storage, and cross-platform compatibility",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"buffer": "^6.0.3",
|
|
41
41
|
"compression": "^1.7.4",
|
|
42
42
|
"cors": "^2.8.5",
|
|
43
|
-
"entity-serializer": "^1.0.
|
|
43
|
+
"entity-serializer": "^1.0.3",
|
|
44
44
|
"express": "^4.18.2",
|
|
45
45
|
"google-auth-library": "^8.8.0",
|
|
46
46
|
"guard-object": "^1.1.4",
|
|
47
47
|
"jsonwebtoken": "^9.0.0",
|
|
48
48
|
"limit-task": "1.0.0",
|
|
49
49
|
"lodash": "^4.17.21",
|
|
50
|
+
"mime": "^4.0.7",
|
|
50
51
|
"node-fetch": "^3.3.1",
|
|
51
52
|
"set-large-timeout": "^1.0.1",
|
|
52
53
|
"simplify-error": "^1.0.1",
|