@inditextech/weave-store-azure-web-pubsub 5.2.0 → 5.2.2
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/dist/client.d.ts +773 -65
- package/dist/client.js +892 -1124
- package/dist/client.stats.html +388 -33
- package/dist/server.d.ts +2177 -503
- package/dist/server.js +357 -460
- package/dist/server.stats.html +388 -33
- package/package.json +7 -7
package/dist/server.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AzureKeyCredential, WebPubSubServiceClient } from "@azure/web-pubsub";
|
|
2
2
|
import { DefaultAzureCredential } from "@azure/identity";
|
|
3
|
-
import * as Y$1 from "yjs";
|
|
4
3
|
import * as Y from "yjs";
|
|
5
4
|
import { URL } from "node:url";
|
|
6
5
|
import crypto, { createHmac, timingSafeEqual } from "node:crypto";
|
|
@@ -10,12 +9,10 @@ import process from "node:process";
|
|
|
10
9
|
import { WebSocket } from "ws";
|
|
11
10
|
import { mergeExceptArrays } from "@inditextech/weave-sdk";
|
|
12
11
|
import { defaultInitialState } from "@inditextech/weave-sdk/server";
|
|
13
|
-
|
|
14
12
|
//#region ../../node_modules/emittery/maps.js
|
|
15
|
-
const anyMap = new WeakMap();
|
|
16
|
-
const eventsMap = new WeakMap();
|
|
17
|
-
const producersMap = new WeakMap();
|
|
18
|
-
|
|
13
|
+
const anyMap = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
const eventsMap = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
const producersMap = /* @__PURE__ */ new WeakMap();
|
|
19
16
|
//#endregion
|
|
20
17
|
//#region ../../node_modules/emittery/index.js
|
|
21
18
|
const anyProducer = Symbol("anyProducer");
|
|
@@ -68,9 +65,8 @@ function iterator(instance, eventNames) {
|
|
|
68
65
|
for (const eventName of eventNames) {
|
|
69
66
|
let set = getEventProducers(instance, eventName);
|
|
70
67
|
if (!set) {
|
|
71
|
-
set = new Set();
|
|
72
|
-
|
|
73
|
-
producers.set(eventName, set);
|
|
68
|
+
set = /* @__PURE__ */ new Set();
|
|
69
|
+
producersMap.get(instance).set(eventName, set);
|
|
74
70
|
}
|
|
75
71
|
set.add(producer);
|
|
76
72
|
}
|
|
@@ -98,10 +94,7 @@ function iterator(instance, eventNames) {
|
|
|
98
94
|
const set = getEventProducers(instance, eventName);
|
|
99
95
|
if (set) {
|
|
100
96
|
set.delete(producer);
|
|
101
|
-
if (set.size === 0)
|
|
102
|
-
const producers = producersMap.get(instance);
|
|
103
|
-
producers.delete(eventName);
|
|
104
|
-
}
|
|
97
|
+
if (set.size === 0) producersMap.get(instance).delete(eventName);
|
|
105
98
|
}
|
|
106
99
|
}
|
|
107
100
|
flush();
|
|
@@ -170,10 +163,10 @@ var Emittery = class Emittery {
|
|
|
170
163
|
isGlobalDebugEnabled = newValue;
|
|
171
164
|
}
|
|
172
165
|
constructor(options = {}) {
|
|
173
|
-
anyMap.set(this, new Set());
|
|
174
|
-
eventsMap.set(this, new Map());
|
|
175
|
-
producersMap.set(this, new Map());
|
|
176
|
-
producersMap.get(this).set(anyProducer, new Set());
|
|
166
|
+
anyMap.set(this, /* @__PURE__ */ new Set());
|
|
167
|
+
eventsMap.set(this, /* @__PURE__ */ new Map());
|
|
168
|
+
producersMap.set(this, /* @__PURE__ */ new Map());
|
|
169
|
+
producersMap.get(this).set(anyProducer, /* @__PURE__ */ new Set());
|
|
177
170
|
this.debug = options.debug ?? {};
|
|
178
171
|
if (this.debug.enabled === void 0) this.debug.enabled = false;
|
|
179
172
|
if (!this.debug.logger) this.debug.logger = (type, debugName, eventName, eventData) => {
|
|
@@ -183,7 +176,7 @@ var Emittery = class Emittery {
|
|
|
183
176
|
eventData = `Object with the following keys failed to stringify: ${Object.keys(eventData).join(",")}`;
|
|
184
177
|
}
|
|
185
178
|
if (typeof eventName === "symbol" || typeof eventName === "number") eventName = eventName.toString();
|
|
186
|
-
const currentTime = new Date();
|
|
179
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
187
180
|
const logTime = `${currentTime.getHours()}:${currentTime.getMinutes()}:${currentTime.getSeconds()}.${currentTime.getMilliseconds()}`;
|
|
188
181
|
console.log(`[${logTime}][emittery:${type}][${debugName}] Event Name: ${eventName}\n\tdata: ${eventData}`);
|
|
189
182
|
};
|
|
@@ -198,9 +191,8 @@ var Emittery = class Emittery {
|
|
|
198
191
|
assertEventName(eventName);
|
|
199
192
|
let set = getListeners(this, eventName);
|
|
200
193
|
if (!set) {
|
|
201
|
-
set = new Set();
|
|
202
|
-
|
|
203
|
-
events.set(eventName, set);
|
|
194
|
+
set = /* @__PURE__ */ new Set();
|
|
195
|
+
eventsMap.get(this).set(eventName, set);
|
|
204
196
|
}
|
|
205
197
|
set.add(listener);
|
|
206
198
|
this.logIfDebugEnabled("subscribe", eventName, void 0);
|
|
@@ -225,10 +217,7 @@ var Emittery = class Emittery {
|
|
|
225
217
|
const set = getListeners(this, eventName);
|
|
226
218
|
if (set) {
|
|
227
219
|
set.delete(listener);
|
|
228
|
-
if (set.size === 0)
|
|
229
|
-
const events = eventsMap.get(this);
|
|
230
|
-
events.delete(eventName);
|
|
231
|
-
}
|
|
220
|
+
if (set.size === 0) eventsMap.get(this).delete(eventName);
|
|
232
221
|
}
|
|
233
222
|
this.logIfDebugEnabled("unsubscribe", eventName, void 0);
|
|
234
223
|
if (!isMetaEvent(eventName)) emitMetaEvent(this, listenerRemoved, {
|
|
@@ -258,7 +247,7 @@ var Emittery = class Emittery {
|
|
|
258
247
|
if (isMetaEvent(eventName) && !canEmitMetaEvents) throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");
|
|
259
248
|
this.logIfDebugEnabled("emit", eventName, eventData);
|
|
260
249
|
enqueueProducers(this, eventName, eventData);
|
|
261
|
-
const listeners = getListeners(this, eventName) ?? new Set();
|
|
250
|
+
const listeners = getListeners(this, eventName) ?? /* @__PURE__ */ new Set();
|
|
262
251
|
const anyListeners = anyMap.get(this);
|
|
263
252
|
const staticListeners = [...listeners];
|
|
264
253
|
const staticAnyListeners = isMetaEvent(eventName) ? [] : [...anyListeners];
|
|
@@ -273,7 +262,7 @@ var Emittery = class Emittery {
|
|
|
273
262
|
assertEventName(eventName);
|
|
274
263
|
if (isMetaEvent(eventName) && !canEmitMetaEvents) throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");
|
|
275
264
|
this.logIfDebugEnabled("emitSerial", eventName, eventData);
|
|
276
|
-
const listeners = getListeners(this, eventName) ?? new Set();
|
|
265
|
+
const listeners = getListeners(this, eventName) ?? /* @__PURE__ */ new Set();
|
|
277
266
|
const anyListeners = anyMap.get(this);
|
|
278
267
|
const staticListeners = [...listeners];
|
|
279
268
|
const staticAnyListeners = [...anyListeners];
|
|
@@ -317,14 +306,14 @@ var Emittery = class Emittery {
|
|
|
317
306
|
}
|
|
318
307
|
} else {
|
|
319
308
|
anyMap.get(this).clear();
|
|
320
|
-
for (const [eventName
|
|
309
|
+
for (const [eventName, listeners] of eventsMap.get(this).entries()) {
|
|
321
310
|
listeners.clear();
|
|
322
|
-
eventsMap.get(this).delete(eventName
|
|
311
|
+
eventsMap.get(this).delete(eventName);
|
|
323
312
|
}
|
|
324
|
-
for (const [eventName
|
|
313
|
+
for (const [eventName, producers] of producersMap.get(this).entries()) {
|
|
325
314
|
for (const producer of producers) producer.finish();
|
|
326
315
|
producers.clear();
|
|
327
|
-
producersMap.get(this).delete(eventName
|
|
316
|
+
producersMap.get(this).delete(eventName);
|
|
328
317
|
}
|
|
329
318
|
}
|
|
330
319
|
}
|
|
@@ -369,26 +358,23 @@ Object.defineProperty(Emittery, "listenerRemoved", {
|
|
|
369
358
|
enumerable: true,
|
|
370
359
|
configurable: false
|
|
371
360
|
});
|
|
372
|
-
|
|
373
361
|
//#endregion
|
|
374
362
|
//#region src/types.ts
|
|
375
|
-
let MessageType = /* @__PURE__ */ function(MessageType
|
|
376
|
-
MessageType
|
|
377
|
-
MessageType
|
|
378
|
-
MessageType
|
|
379
|
-
return MessageType
|
|
363
|
+
let MessageType = /* @__PURE__ */ function(MessageType) {
|
|
364
|
+
MessageType["System"] = "system";
|
|
365
|
+
MessageType["JoinGroup"] = "joinGroup";
|
|
366
|
+
MessageType["SendToGroup"] = "sendToGroup";
|
|
367
|
+
return MessageType;
|
|
380
368
|
}({});
|
|
381
|
-
let MessageDataType = /* @__PURE__ */ function(MessageDataType
|
|
382
|
-
MessageDataType
|
|
383
|
-
MessageDataType
|
|
384
|
-
MessageDataType
|
|
385
|
-
return MessageDataType
|
|
369
|
+
let MessageDataType = /* @__PURE__ */ function(MessageDataType) {
|
|
370
|
+
MessageDataType["Init"] = "init";
|
|
371
|
+
MessageDataType["Sync"] = "sync";
|
|
372
|
+
MessageDataType["Awareness"] = "awareness";
|
|
373
|
+
return MessageDataType;
|
|
386
374
|
}({});
|
|
387
|
-
|
|
388
375
|
//#endregion
|
|
389
376
|
//#region src/yjs.ts
|
|
390
|
-
var yjs_default = Y
|
|
391
|
-
|
|
377
|
+
var yjs_default = Y;
|
|
392
378
|
//#endregion
|
|
393
379
|
//#region src/server/event-handler/utils.ts
|
|
394
380
|
function isJsonObject(obj) {
|
|
@@ -411,7 +397,7 @@ function fromBase64JsonString(base64String) {
|
|
|
411
397
|
function getHttpHeader(req, key) {
|
|
412
398
|
if (!key) return void 0;
|
|
413
399
|
const value = req.headers[key.toLowerCase()];
|
|
414
|
-
if (value === void 0) return
|
|
400
|
+
if (value === void 0) return;
|
|
415
401
|
if (typeof value === "string") return value;
|
|
416
402
|
return value[0];
|
|
417
403
|
}
|
|
@@ -422,21 +408,18 @@ function readRequestBody(req) {
|
|
|
422
408
|
chunks.push(chunk);
|
|
423
409
|
});
|
|
424
410
|
req.on("end", function() {
|
|
425
|
-
|
|
426
|
-
resolve(buffer);
|
|
411
|
+
resolve(Buffer.concat(chunks));
|
|
427
412
|
});
|
|
428
413
|
req.on("error", function(err) {
|
|
429
414
|
reject(err);
|
|
430
415
|
});
|
|
431
416
|
});
|
|
432
417
|
}
|
|
433
|
-
|
|
434
418
|
//#endregion
|
|
435
419
|
//#region ../../node_modules/@typespec/ts-http-runtime/dist/esm/logger/log.js
|
|
436
420
|
function log(message, ...args) {
|
|
437
421
|
process.stderr.write(`${util.format(message, ...args)}${EOL}`);
|
|
438
422
|
}
|
|
439
|
-
|
|
440
423
|
//#endregion
|
|
441
424
|
//#region ../../node_modules/@typespec/ts-http-runtime/dist/esm/env.js
|
|
442
425
|
/**
|
|
@@ -447,15 +430,8 @@ function log(message, ...args) {
|
|
|
447
430
|
function getEnvironmentVariable(name) {
|
|
448
431
|
return process.env[name];
|
|
449
432
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
*/
|
|
453
|
-
const isDeno = typeof process.versions.deno === "string" && process.versions.deno.length > 0;
|
|
454
|
-
/**
|
|
455
|
-
* A constant that indicates whether the environment the code is running is Bun.sh.
|
|
456
|
-
*/
|
|
457
|
-
const isBun = typeof process.versions.bun === "string" && process.versions.bun.length > 0;
|
|
458
|
-
|
|
433
|
+
typeof process.versions.deno === "string" && process.versions.deno.length;
|
|
434
|
+
typeof process.versions.bun === "string" && process.versions.bun.length;
|
|
459
435
|
//#endregion
|
|
460
436
|
//#region ../../node_modules/@typespec/ts-http-runtime/dist/esm/logger/debug.js
|
|
461
437
|
const debugEnvVariable = getEnvironmentVariable("DEBUG");
|
|
@@ -578,8 +554,6 @@ function extend(namespace) {
|
|
|
578
554
|
newDebugger.log = this.log;
|
|
579
555
|
return newDebugger;
|
|
580
556
|
}
|
|
581
|
-
var debug_default = debugObj;
|
|
582
|
-
|
|
583
557
|
//#endregion
|
|
584
558
|
//#region ../../node_modules/@typespec/ts-http-runtime/dist/esm/logger/logger.js
|
|
585
559
|
const TYPESPEC_RUNTIME_LOG_LEVELS = [
|
|
@@ -608,34 +582,36 @@ function isTypeSpecRuntimeLogLevel(level) {
|
|
|
608
582
|
* @returns The logger context.
|
|
609
583
|
*/
|
|
610
584
|
function createLoggerContext(options) {
|
|
611
|
-
const registeredLoggers = new Set();
|
|
585
|
+
const registeredLoggers = /* @__PURE__ */ new Set();
|
|
612
586
|
const logLevelFromEnv = getEnvironmentVariable(options.logLevelEnvVarName);
|
|
613
587
|
let logLevel;
|
|
614
|
-
const clientLogger =
|
|
588
|
+
const clientLogger = debugObj(options.namespace);
|
|
615
589
|
clientLogger.log = (...args) => {
|
|
616
|
-
|
|
590
|
+
debugObj.log(...args);
|
|
617
591
|
};
|
|
618
592
|
function contextSetLogLevel(level) {
|
|
619
593
|
if (level && !isTypeSpecRuntimeLogLevel(level)) throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
|
|
620
594
|
logLevel = level;
|
|
621
|
-
const enabledNamespaces
|
|
622
|
-
for (const logger
|
|
623
|
-
|
|
595
|
+
const enabledNamespaces = [];
|
|
596
|
+
for (const logger of registeredLoggers) if (shouldEnable(logger)) enabledNamespaces.push(logger.namespace);
|
|
597
|
+
debugObj.enable(enabledNamespaces.join(","));
|
|
598
|
+
}
|
|
599
|
+
if (logLevelFromEnv) {
|
|
600
|
+
if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) contextSetLogLevel(logLevelFromEnv);
|
|
601
|
+
else console.error(`${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
|
|
624
602
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
function shouldEnable(logger$1) {
|
|
628
|
-
return Boolean(logLevel && levelMap[logger$1.level] <= levelMap[logLevel]);
|
|
603
|
+
function shouldEnable(logger) {
|
|
604
|
+
return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);
|
|
629
605
|
}
|
|
630
606
|
function createLogger(parent, level) {
|
|
631
|
-
const logger
|
|
632
|
-
patchLogMethod(parent, logger
|
|
633
|
-
if (shouldEnable(logger
|
|
634
|
-
const enabledNamespaces
|
|
635
|
-
|
|
607
|
+
const logger = Object.assign(parent.extend(level), { level });
|
|
608
|
+
patchLogMethod(parent, logger);
|
|
609
|
+
if (shouldEnable(logger)) {
|
|
610
|
+
const enabledNamespaces = debugObj.disable();
|
|
611
|
+
debugObj.enable(enabledNamespaces + "," + logger.namespace);
|
|
636
612
|
}
|
|
637
|
-
registeredLoggers.add(logger
|
|
638
|
-
return logger
|
|
613
|
+
registeredLoggers.add(logger);
|
|
614
|
+
return logger;
|
|
639
615
|
}
|
|
640
616
|
function contextGetLogLevel() {
|
|
641
617
|
return logLevel;
|
|
@@ -657,33 +633,17 @@ function createLoggerContext(options) {
|
|
|
657
633
|
logger: clientLogger
|
|
658
634
|
};
|
|
659
635
|
}
|
|
660
|
-
|
|
636
|
+
createLoggerContext({
|
|
661
637
|
logLevelEnvVarName: "TYPESPEC_RUNTIME_LOG_LEVEL",
|
|
662
638
|
namespace: "typeSpecRuntime"
|
|
663
|
-
});
|
|
664
|
-
/**
|
|
665
|
-
* Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
|
|
666
|
-
* @param level - The log level to enable for logging.
|
|
667
|
-
* Options from most verbose to least verbose are:
|
|
668
|
-
* - verbose
|
|
669
|
-
* - info
|
|
670
|
-
* - warning
|
|
671
|
-
* - error
|
|
672
|
-
*/
|
|
673
|
-
const TypeSpecRuntimeLogger = context$1.logger;
|
|
674
|
-
|
|
639
|
+
}).logger;
|
|
675
640
|
//#endregion
|
|
676
641
|
//#region ../../node_modules/@azure/logger/dist/esm/index.js
|
|
677
642
|
const context = createLoggerContext({
|
|
678
643
|
logLevelEnvVarName: "AZURE_LOG_LEVEL",
|
|
679
644
|
namespace: "azure"
|
|
680
645
|
});
|
|
681
|
-
|
|
682
|
-
* The AzureLogger provides a mechanism for overriding where logs are output to.
|
|
683
|
-
* By default, logs are sent to stderr.
|
|
684
|
-
* Override the `log` method to redirect logs to another location.
|
|
685
|
-
*/
|
|
686
|
-
const AzureLogger = context.logger;
|
|
646
|
+
context.logger;
|
|
687
647
|
/**
|
|
688
648
|
* Creates a logger for use by the Azure SDKs that inherits from `AzureLogger`.
|
|
689
649
|
* @param namespace - The name of the SDK package.
|
|
@@ -692,173 +652,162 @@ const AzureLogger = context.logger;
|
|
|
692
652
|
function createClientLogger(namespace) {
|
|
693
653
|
return context.createClientLogger(namespace);
|
|
694
654
|
}
|
|
695
|
-
|
|
696
655
|
//#endregion
|
|
697
656
|
//#region src/server/event-handler/logger.ts
|
|
698
657
|
const logger = createClientLogger("store-azure-web-pubsub");
|
|
699
|
-
|
|
700
658
|
//#endregion
|
|
701
659
|
//#region src/server/event-handler/enum/mqtt-error-codes/mqtt-v311-connect-return-code.ts
|
|
702
660
|
/**
|
|
703
661
|
* MQTT 3.1.1 Connect Return Codes.
|
|
704
662
|
*/
|
|
705
|
-
let MqttV311ConnectReturnCode = /* @__PURE__ */ function(MqttV311ConnectReturnCode
|
|
663
|
+
let MqttV311ConnectReturnCode = /* @__PURE__ */ function(MqttV311ConnectReturnCode) {
|
|
706
664
|
/**
|
|
707
665
|
* 0x01: Connection refused, unacceptable protocol version
|
|
708
666
|
* The Server does not support the level of the MQTT protocol requested by the Client.
|
|
709
667
|
*/
|
|
710
|
-
MqttV311ConnectReturnCode
|
|
668
|
+
MqttV311ConnectReturnCode[MqttV311ConnectReturnCode["UnacceptableProtocolVersion"] = 1] = "UnacceptableProtocolVersion";
|
|
711
669
|
/**
|
|
712
670
|
* 0x02: Connection refused, identifier rejected
|
|
713
671
|
* The Client identifier is correct UTF-8 but not allowed by the Server.
|
|
714
672
|
*/
|
|
715
|
-
MqttV311ConnectReturnCode
|
|
673
|
+
MqttV311ConnectReturnCode[MqttV311ConnectReturnCode["IdentifierRejected"] = 2] = "IdentifierRejected";
|
|
716
674
|
/**
|
|
717
675
|
* 0x03: Connection refused, server unavailable
|
|
718
676
|
* The Network Connection has been made but the MQTT service is unavailable.
|
|
719
677
|
*/
|
|
720
|
-
MqttV311ConnectReturnCode
|
|
678
|
+
MqttV311ConnectReturnCode[MqttV311ConnectReturnCode["ServerUnavailable"] = 3] = "ServerUnavailable";
|
|
721
679
|
/**
|
|
722
680
|
* 0x04: Connection refused, bad user name or password
|
|
723
681
|
* The data in the user name or password is malformed.
|
|
724
682
|
*/
|
|
725
|
-
MqttV311ConnectReturnCode
|
|
683
|
+
MqttV311ConnectReturnCode[MqttV311ConnectReturnCode["BadUsernameOrPassword"] = 4] = "BadUsernameOrPassword";
|
|
726
684
|
/**
|
|
727
685
|
* 0x05: Connection refused, not authorized
|
|
728
686
|
* The Client is not authorized to connect.
|
|
729
687
|
*/
|
|
730
|
-
MqttV311ConnectReturnCode
|
|
731
|
-
return MqttV311ConnectReturnCode
|
|
688
|
+
MqttV311ConnectReturnCode[MqttV311ConnectReturnCode["NotAuthorized"] = 5] = "NotAuthorized";
|
|
689
|
+
return MqttV311ConnectReturnCode;
|
|
732
690
|
}({});
|
|
733
|
-
|
|
734
691
|
//#endregion
|
|
735
692
|
//#region src/server/event-handler/enum/mqtt-error-codes/mqtt-v500-connect-reason-code.ts
|
|
736
693
|
/**
|
|
737
694
|
* MQTT Connect Reason Codes
|
|
738
695
|
* These codes represent the reasons for the outcome of an MQTT CONNECT packet as per MQTT 5.0 specification.
|
|
739
696
|
*/
|
|
740
|
-
let MqttV500ConnectReasonCode = /* @__PURE__ */ function(MqttV500ConnectReasonCode
|
|
697
|
+
let MqttV500ConnectReasonCode = /* @__PURE__ */ function(MqttV500ConnectReasonCode) {
|
|
741
698
|
/**
|
|
742
699
|
* 0x80 - Unspecified error
|
|
743
700
|
* Description: The Server does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.
|
|
744
701
|
*/
|
|
745
|
-
MqttV500ConnectReasonCode
|
|
702
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["UnspecifiedError"] = 128] = "UnspecifiedError";
|
|
746
703
|
/**
|
|
747
704
|
* 0x81 - Malformed Packet
|
|
748
705
|
* Description: Data within the CONNECT packet could not be correctly parsed.
|
|
749
706
|
*/
|
|
750
|
-
MqttV500ConnectReasonCode
|
|
707
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["MalformedPacket"] = 129] = "MalformedPacket";
|
|
751
708
|
/**
|
|
752
709
|
* 0x82 - Protocol Error
|
|
753
710
|
* Description: Data in the CONNECT packet does not conform to this specification.
|
|
754
711
|
*/
|
|
755
|
-
MqttV500ConnectReasonCode
|
|
712
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ProtocolError"] = 130] = "ProtocolError";
|
|
756
713
|
/**
|
|
757
714
|
* 0x83 - Implementation specific error
|
|
758
715
|
* Description: The CONNECT is valid but is not accepted by this Server.
|
|
759
716
|
*/
|
|
760
|
-
MqttV500ConnectReasonCode
|
|
717
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ImplementationSpecificError"] = 131] = "ImplementationSpecificError";
|
|
761
718
|
/**
|
|
762
719
|
* 0x84 - Unsupported Protocol Version
|
|
763
720
|
* Description: The Server does not support the version of the MQTT protocol requested by the Client.
|
|
764
721
|
*/
|
|
765
|
-
MqttV500ConnectReasonCode
|
|
722
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["UnsupportedProtocolVersion"] = 132] = "UnsupportedProtocolVersion";
|
|
766
723
|
/**
|
|
767
724
|
* 0x85 - Client Identifier not valid
|
|
768
725
|
* Description: The Client Identifier is a valid string but is not allowed by the Server.
|
|
769
726
|
*/
|
|
770
|
-
MqttV500ConnectReasonCode
|
|
727
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ClientIdentifierNotValid"] = 133] = "ClientIdentifierNotValid";
|
|
771
728
|
/**
|
|
772
729
|
* 0x86 - Bad User Name or Password
|
|
773
730
|
* Description: The Server does not accept the User Name or Password specified by the Client.
|
|
774
731
|
*/
|
|
775
|
-
MqttV500ConnectReasonCode
|
|
732
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["BadUserNameOrPassword"] = 134] = "BadUserNameOrPassword";
|
|
776
733
|
/**
|
|
777
734
|
* 0x87 - Not authorized
|
|
778
735
|
* Description: The Client is not authorized to connect.
|
|
779
736
|
*/
|
|
780
|
-
MqttV500ConnectReasonCode
|
|
737
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["NotAuthorized"] = 135] = "NotAuthorized";
|
|
781
738
|
/**
|
|
782
739
|
* 0x88 - Server unavailable
|
|
783
740
|
* Description: The MQTT Server is not available.
|
|
784
741
|
*/
|
|
785
|
-
MqttV500ConnectReasonCode
|
|
742
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ServerUnavailable"] = 136] = "ServerUnavailable";
|
|
786
743
|
/**
|
|
787
744
|
* 0x89 - Server busy
|
|
788
745
|
* Description: The Server is busy. Try again later.
|
|
789
746
|
*/
|
|
790
|
-
MqttV500ConnectReasonCode
|
|
747
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ServerBusy"] = 137] = "ServerBusy";
|
|
791
748
|
/**
|
|
792
749
|
* 0x8A - Banned
|
|
793
750
|
* Description: This Client has been banned by administrative action. Contact the server administrator.
|
|
794
751
|
*/
|
|
795
|
-
MqttV500ConnectReasonCode
|
|
752
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["Banned"] = 138] = "Banned";
|
|
796
753
|
/**
|
|
797
754
|
* 0x8C - Bad authentication method
|
|
798
755
|
* Description: The authentication method is not supported or does not match the authentication method currently in use.
|
|
799
756
|
*/
|
|
800
|
-
MqttV500ConnectReasonCode
|
|
757
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["BadAuthenticationMethod"] = 140] = "BadAuthenticationMethod";
|
|
801
758
|
/**
|
|
802
759
|
* 0x90 - Topic Name invalid
|
|
803
760
|
* Description: The Will Topic Name is not malformed, but is not accepted by this Server.
|
|
804
761
|
*/
|
|
805
|
-
MqttV500ConnectReasonCode
|
|
762
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["TopicNameInvalid"] = 144] = "TopicNameInvalid";
|
|
806
763
|
/**
|
|
807
764
|
* 0x95 - Packet too large
|
|
808
765
|
* Description: The CONNECT packet exceeded the maximum permissible size.
|
|
809
766
|
*/
|
|
810
|
-
MqttV500ConnectReasonCode
|
|
767
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["PacketTooLarge"] = 149] = "PacketTooLarge";
|
|
811
768
|
/**
|
|
812
769
|
* 0x97 - Quota exceeded
|
|
813
770
|
* Description: An implementation or administrative imposed limit has been exceeded.
|
|
814
771
|
*/
|
|
815
|
-
MqttV500ConnectReasonCode
|
|
772
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["QuotaExceeded"] = 151] = "QuotaExceeded";
|
|
816
773
|
/**
|
|
817
774
|
* 0x99 - Payload format invalid
|
|
818
775
|
* Description: The Will Payload does not match the specified Payload Format Indicator.
|
|
819
776
|
*/
|
|
820
|
-
MqttV500ConnectReasonCode
|
|
777
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["PayloadFormatInvalid"] = 153] = "PayloadFormatInvalid";
|
|
821
778
|
/**
|
|
822
779
|
* 0x9A - Retain not supported
|
|
823
780
|
* Description: The Server does not support retained messages, and Will Retain was set to 1.
|
|
824
781
|
*/
|
|
825
|
-
MqttV500ConnectReasonCode
|
|
782
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["RetainNotSupported"] = 154] = "RetainNotSupported";
|
|
826
783
|
/**
|
|
827
784
|
* 0x9B - QoS not supported
|
|
828
785
|
* Description: The Server does not support the QoS set in Will QoS.
|
|
829
786
|
*/
|
|
830
|
-
MqttV500ConnectReasonCode
|
|
787
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["QosNotSupported"] = 155] = "QosNotSupported";
|
|
831
788
|
/**
|
|
832
789
|
* 0x9C - Use another server
|
|
833
790
|
* Description: The Client should temporarily use another server.
|
|
834
791
|
*/
|
|
835
|
-
MqttV500ConnectReasonCode
|
|
792
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["UseAnotherServer"] = 156] = "UseAnotherServer";
|
|
836
793
|
/**
|
|
837
794
|
* 0x9D - Server moved
|
|
838
795
|
* Description: The Client should permanently use another server.
|
|
839
796
|
*/
|
|
840
|
-
MqttV500ConnectReasonCode
|
|
797
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ServerMoved"] = 157] = "ServerMoved";
|
|
841
798
|
/**
|
|
842
799
|
* 0x9F - Connection rate exceeded
|
|
843
800
|
* Description: The connection rate limit has been exceeded.
|
|
844
801
|
*/
|
|
845
|
-
MqttV500ConnectReasonCode
|
|
846
|
-
return MqttV500ConnectReasonCode
|
|
802
|
+
MqttV500ConnectReasonCode[MqttV500ConnectReasonCode["ConnectionRateExceeded"] = 159] = "ConnectionRateExceeded";
|
|
803
|
+
return MqttV500ConnectReasonCode;
|
|
847
804
|
}({});
|
|
848
|
-
|
|
849
805
|
//#endregion
|
|
850
806
|
//#region src/server/event-handler/cloud-events-dispatcher.ts
|
|
851
|
-
var EventType = /* @__PURE__ */ function(EventType$1) {
|
|
852
|
-
EventType$1[EventType$1["Connect"] = 0] = "Connect";
|
|
853
|
-
EventType$1[EventType$1["Connected"] = 1] = "Connected";
|
|
854
|
-
EventType$1[EventType$1["Disconnected"] = 2] = "Disconnected";
|
|
855
|
-
EventType$1[EventType$1["UserEvent"] = 3] = "UserEvent";
|
|
856
|
-
return EventType$1;
|
|
857
|
-
}(EventType || {});
|
|
858
807
|
function getConnectResponseHandler(connectRequest, response) {
|
|
859
808
|
const states = connectRequest.context.states;
|
|
860
809
|
let modified = false;
|
|
861
|
-
|
|
810
|
+
return {
|
|
862
811
|
setState(name, value) {
|
|
863
812
|
states[name] = value;
|
|
864
813
|
modified = true;
|
|
@@ -885,12 +834,11 @@ function getConnectResponseHandler(connectRequest, response) {
|
|
|
885
834
|
} else handleConnectErrorResponse(connectRequest, response, res.code, res.detail);
|
|
886
835
|
}
|
|
887
836
|
};
|
|
888
|
-
return handler;
|
|
889
837
|
}
|
|
890
838
|
function getUserEventResponseHandler(userRequest, response) {
|
|
891
839
|
const states = userRequest.context.states;
|
|
892
840
|
let modified = false;
|
|
893
|
-
|
|
841
|
+
return {
|
|
894
842
|
setState(name, value) {
|
|
895
843
|
modified = true;
|
|
896
844
|
states[name] = value;
|
|
@@ -905,9 +853,7 @@ function getUserEventResponseHandler(userRequest, response) {
|
|
|
905
853
|
case "text":
|
|
906
854
|
response.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
907
855
|
break;
|
|
908
|
-
default:
|
|
909
|
-
response.setHeader("Content-Type", "application/octet-stream");
|
|
910
|
-
break;
|
|
856
|
+
default: response.setHeader("Content-Type", "application/octet-stream");
|
|
911
857
|
}
|
|
912
858
|
response.end(data ?? "");
|
|
913
859
|
},
|
|
@@ -916,7 +862,6 @@ function getUserEventResponseHandler(userRequest, response) {
|
|
|
916
862
|
response.end(detail ?? "");
|
|
917
863
|
}
|
|
918
864
|
};
|
|
919
|
-
return handler;
|
|
920
865
|
}
|
|
921
866
|
function getContext(request, origin) {
|
|
922
867
|
const baseContext = {
|
|
@@ -948,47 +893,47 @@ function tryGetWebPubSubEvent(req) {
|
|
|
948
893
|
const disconnectd = "azure.webpubsub.sys.disconnected";
|
|
949
894
|
const userPrefix = "azure.webpubsub.user.";
|
|
950
895
|
const type = getHttpHeader(req, "ce-type");
|
|
951
|
-
if (!type?.startsWith(prefix)) return
|
|
952
|
-
if (type.startsWith(userPrefix)) return
|
|
896
|
+
if (!type?.startsWith(prefix)) return;
|
|
897
|
+
if (type.startsWith(userPrefix)) return 3;
|
|
953
898
|
switch (type) {
|
|
954
|
-
case connect: return
|
|
955
|
-
case connected: return
|
|
956
|
-
case disconnectd: return
|
|
957
|
-
default: return
|
|
899
|
+
case connect: return 0;
|
|
900
|
+
case connected: return 1;
|
|
901
|
+
case disconnectd: return 2;
|
|
902
|
+
default: return;
|
|
958
903
|
}
|
|
959
904
|
}
|
|
960
905
|
function getStatusCodeFromMqttConnectCode(mqttConnectCode) {
|
|
961
906
|
if (mqttConnectCode < 128) switch (mqttConnectCode) {
|
|
962
|
-
case
|
|
963
|
-
case
|
|
964
|
-
case
|
|
965
|
-
case
|
|
966
|
-
case
|
|
907
|
+
case 1:
|
|
908
|
+
case 2: return 400;
|
|
909
|
+
case 3: return 503;
|
|
910
|
+
case 4:
|
|
911
|
+
case 5: return 401;
|
|
967
912
|
default:
|
|
968
913
|
logger.warning(`Invalid MQTT connect return code: ${mqttConnectCode}.`);
|
|
969
914
|
return 500;
|
|
970
915
|
}
|
|
971
916
|
else switch (mqttConnectCode) {
|
|
972
|
-
case
|
|
973
|
-
case
|
|
974
|
-
case
|
|
975
|
-
case
|
|
976
|
-
case
|
|
977
|
-
case
|
|
978
|
-
case
|
|
979
|
-
case
|
|
980
|
-
case
|
|
981
|
-
case
|
|
982
|
-
case
|
|
983
|
-
case
|
|
984
|
-
case
|
|
985
|
-
case
|
|
986
|
-
case
|
|
987
|
-
case
|
|
988
|
-
case
|
|
989
|
-
case
|
|
990
|
-
case
|
|
991
|
-
case
|
|
917
|
+
case 135:
|
|
918
|
+
case 134: return 401;
|
|
919
|
+
case 133:
|
|
920
|
+
case 129:
|
|
921
|
+
case 132:
|
|
922
|
+
case 140:
|
|
923
|
+
case 144:
|
|
924
|
+
case 153:
|
|
925
|
+
case 131:
|
|
926
|
+
case 149:
|
|
927
|
+
case 154:
|
|
928
|
+
case 155: return 400;
|
|
929
|
+
case 151:
|
|
930
|
+
case 159: return 429;
|
|
931
|
+
case 138: return 403;
|
|
932
|
+
case 156:
|
|
933
|
+
case 157:
|
|
934
|
+
case 136:
|
|
935
|
+
case 137:
|
|
936
|
+
case 128: return 500;
|
|
992
937
|
default:
|
|
993
938
|
logger.warning(`Invalid MQTT connect return code: ${mqttConnectCode}.`);
|
|
994
939
|
return 500;
|
|
@@ -996,29 +941,28 @@ function getStatusCodeFromMqttConnectCode(mqttConnectCode) {
|
|
|
996
941
|
}
|
|
997
942
|
function getMqttConnectCodeFromStatusCode(statusCode, protocolVersion) {
|
|
998
943
|
if (protocolVersion === 4) switch (statusCode) {
|
|
999
|
-
case 400: return
|
|
1000
|
-
case 401: return
|
|
1001
|
-
case 500: return
|
|
944
|
+
case 400: return 4;
|
|
945
|
+
case 401: return 5;
|
|
946
|
+
case 500: return 3;
|
|
1002
947
|
default:
|
|
1003
948
|
logger.warning(`Unsupported HTTP Status Code: ${statusCode}.`);
|
|
1004
|
-
return
|
|
949
|
+
return 3;
|
|
1005
950
|
}
|
|
1006
951
|
else if (protocolVersion === 5) switch (statusCode) {
|
|
1007
|
-
case 400: return
|
|
1008
|
-
case 401: return
|
|
1009
|
-
case 500: return
|
|
952
|
+
case 400: return 134;
|
|
953
|
+
case 401: return 135;
|
|
954
|
+
case 500: return 128;
|
|
1010
955
|
default:
|
|
1011
956
|
logger.warning(`Unsupported HTTP Status Code: ${statusCode}.`);
|
|
1012
|
-
return
|
|
957
|
+
return 128;
|
|
1013
958
|
}
|
|
1014
959
|
else {
|
|
1015
960
|
logger.warning(`Invalid MQTT protocol version: ${protocolVersion}.`);
|
|
1016
|
-
return
|
|
961
|
+
return 1;
|
|
1017
962
|
}
|
|
1018
963
|
}
|
|
1019
964
|
function handleConnectErrorResponse(connectRequest, response, code, detail) {
|
|
1020
|
-
|
|
1021
|
-
if (isMqttReq) {
|
|
965
|
+
if (connectRequest.context.clientProtocol === "mqtt") {
|
|
1022
966
|
const protocolVersion = connectRequest.mqtt.protocolVersion;
|
|
1023
967
|
const mqttErrorResponse = { mqtt: {
|
|
1024
968
|
code: getMqttConnectCodeFromStatusCode(code, protocolVersion),
|
|
@@ -1042,9 +986,8 @@ function isMqttRequest(req) {
|
|
|
1042
986
|
}
|
|
1043
987
|
async function readUserEventRequest(request, origin) {
|
|
1044
988
|
const contentTypeheader = getHttpHeader(request, "content-type");
|
|
1045
|
-
if (contentTypeheader === void 0) return
|
|
1046
|
-
|
|
1047
|
-
switch (contentType) {
|
|
989
|
+
if (contentTypeheader === void 0) return;
|
|
990
|
+
switch (contentTypeheader.split(";")[0].trim()) {
|
|
1048
991
|
case "application/octet-stream": return {
|
|
1049
992
|
context: getContext(request, origin),
|
|
1050
993
|
data: bufferToArrayBufferCopy(await readRequestBody(request)),
|
|
@@ -1060,7 +1003,7 @@ async function readUserEventRequest(request, origin) {
|
|
|
1060
1003
|
data: (await readRequestBody(request)).toString(),
|
|
1061
1004
|
dataType: "text"
|
|
1062
1005
|
};
|
|
1063
|
-
default: return
|
|
1006
|
+
default: return;
|
|
1064
1007
|
}
|
|
1065
1008
|
}
|
|
1066
1009
|
async function readSystemEventRequest(request, origin) {
|
|
@@ -1073,6 +1016,8 @@ async function readSystemEventRequest(request, origin) {
|
|
|
1073
1016
|
* @internal
|
|
1074
1017
|
*/
|
|
1075
1018
|
var CloudEventsDispatcher = class {
|
|
1019
|
+
hub;
|
|
1020
|
+
eventHandler;
|
|
1076
1021
|
_allowAll = true;
|
|
1077
1022
|
_allowedOrigins = [];
|
|
1078
1023
|
_accessKeys = [];
|
|
@@ -1109,8 +1054,7 @@ var CloudEventsDispatcher = class {
|
|
|
1109
1054
|
}
|
|
1110
1055
|
handlePreflight(req, res) {
|
|
1111
1056
|
if (!isWebPubSubRequest(req)) return false;
|
|
1112
|
-
|
|
1113
|
-
if (origin === void 0) {
|
|
1057
|
+
if (getHttpHeader(req, "webhook-request-origin") === void 0) {
|
|
1114
1058
|
logger.warning("Expecting webhook-request-origin header.");
|
|
1115
1059
|
res.statusCode = 400;
|
|
1116
1060
|
} else if (this._allowAll) res.setHeader("WebHook-Allowed-Origin", "*");
|
|
@@ -1136,8 +1080,7 @@ var CloudEventsDispatcher = class {
|
|
|
1136
1080
|
}
|
|
1137
1081
|
const eventType = tryGetWebPubSubEvent(request);
|
|
1138
1082
|
if (eventType === void 0) return false;
|
|
1139
|
-
|
|
1140
|
-
if (hub?.toUpperCase() !== this.hub.toUpperCase()) return false;
|
|
1083
|
+
if (getHttpHeader(request, "ce-hub")?.toUpperCase() !== this.hub.toUpperCase()) return false;
|
|
1141
1084
|
const sigHeader = getHttpHeader(request, "ce-signature");
|
|
1142
1085
|
const connectionId = getHttpHeader(request, "ce-connectionid");
|
|
1143
1086
|
if (this._accessKeys.length > 0) {
|
|
@@ -1149,26 +1092,26 @@ var CloudEventsDispatcher = class {
|
|
|
1149
1092
|
} else logger.warning("CloudEventsDispatcher: no accessKey configured — ce-signature is not verified. Restrict ingress to Azure Web PubSub IP ranges or provide an accessKey.");
|
|
1150
1093
|
const isMqtt = isMqttRequest(request);
|
|
1151
1094
|
switch (eventType) {
|
|
1152
|
-
case
|
|
1095
|
+
case 0:
|
|
1153
1096
|
if (!this.eventHandler?.handleConnect) {
|
|
1154
1097
|
if (isMqtt) response.statusCode = 204;
|
|
1155
1098
|
response.end();
|
|
1156
1099
|
return true;
|
|
1157
1100
|
}
|
|
1158
1101
|
break;
|
|
1159
|
-
case
|
|
1102
|
+
case 1:
|
|
1160
1103
|
if (!this.eventHandler?.onConnected) {
|
|
1161
1104
|
response.end();
|
|
1162
1105
|
return true;
|
|
1163
1106
|
}
|
|
1164
1107
|
break;
|
|
1165
|
-
case
|
|
1108
|
+
case 2:
|
|
1166
1109
|
if (!this.eventHandler?.onDisconnected) {
|
|
1167
1110
|
response.end();
|
|
1168
1111
|
return true;
|
|
1169
1112
|
}
|
|
1170
1113
|
break;
|
|
1171
|
-
case
|
|
1114
|
+
case 3:
|
|
1172
1115
|
if (!this.eventHandler?.handleUserEvent) {
|
|
1173
1116
|
response.end();
|
|
1174
1117
|
return true;
|
|
@@ -1179,28 +1122,28 @@ var CloudEventsDispatcher = class {
|
|
|
1179
1122
|
return false;
|
|
1180
1123
|
}
|
|
1181
1124
|
switch (eventType) {
|
|
1182
|
-
case
|
|
1125
|
+
case 0: {
|
|
1183
1126
|
const connectRequest = isMqtt ? await readSystemEventRequest(request, origin) : await readSystemEventRequest(request, origin);
|
|
1184
1127
|
connectRequest.queries = connectRequest.queries ?? {};
|
|
1185
1128
|
logger.verbose(connectRequest);
|
|
1186
1129
|
this.eventHandler.handleConnect(connectRequest, getConnectResponseHandler(connectRequest, response));
|
|
1187
1130
|
return true;
|
|
1188
1131
|
}
|
|
1189
|
-
case
|
|
1132
|
+
case 1: {
|
|
1190
1133
|
response.end();
|
|
1191
1134
|
const connectedRequest = await readSystemEventRequest(request, origin);
|
|
1192
1135
|
logger.verbose(connectedRequest);
|
|
1193
1136
|
this.eventHandler.onConnected(connectedRequest);
|
|
1194
1137
|
return true;
|
|
1195
1138
|
}
|
|
1196
|
-
case
|
|
1139
|
+
case 2: {
|
|
1197
1140
|
response.end();
|
|
1198
1141
|
const disconnectedRequest = isMqtt ? await readSystemEventRequest(request, origin) : await readSystemEventRequest(request, origin);
|
|
1199
1142
|
logger.verbose(disconnectedRequest);
|
|
1200
1143
|
this.eventHandler.onDisconnected(disconnectedRequest);
|
|
1201
1144
|
return true;
|
|
1202
1145
|
}
|
|
1203
|
-
case
|
|
1146
|
+
case 3: {
|
|
1204
1147
|
const userRequest = await readUserEventRequest(request, origin);
|
|
1205
1148
|
if (userRequest === void 0) {
|
|
1206
1149
|
logger.warning(`Unsupported content type ${getHttpHeader(request, "content-type")}`);
|
|
@@ -1219,13 +1162,18 @@ var CloudEventsDispatcher = class {
|
|
|
1219
1162
|
function bufferToArrayBufferCopy(buf) {
|
|
1220
1163
|
return Uint8Array.from(buf).buffer;
|
|
1221
1164
|
}
|
|
1222
|
-
|
|
1223
1165
|
//#endregion
|
|
1224
1166
|
//#region src/server/event-handler/web-pubsub-event-handler.ts
|
|
1225
1167
|
/**
|
|
1226
1168
|
* The handler to handle incoming CloudEvents messages
|
|
1227
1169
|
*/
|
|
1228
1170
|
var WebPubSubEventHandler = class {
|
|
1171
|
+
hub;
|
|
1172
|
+
/**
|
|
1173
|
+
* The path this CloudEvents handler listens to
|
|
1174
|
+
*/
|
|
1175
|
+
path;
|
|
1176
|
+
_cloudEventsHandler;
|
|
1229
1177
|
/**
|
|
1230
1178
|
* Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages.
|
|
1231
1179
|
*
|
|
@@ -1299,232 +1247,188 @@ var WebPubSubEventHandler = class {
|
|
|
1299
1247
|
};
|
|
1300
1248
|
}
|
|
1301
1249
|
};
|
|
1302
|
-
|
|
1303
1250
|
//#endregion
|
|
1304
1251
|
//#region src/server/event-handler/enum/mqtt-error-codes/mqtt-disconnect-reason-code.ts
|
|
1305
1252
|
/**
|
|
1306
1253
|
* MQTT 5.0 Disconnect Reason Codes.
|
|
1307
1254
|
*/
|
|
1308
|
-
let MqttDisconnectReasonCode = /* @__PURE__ */ function(MqttDisconnectReasonCode
|
|
1255
|
+
let MqttDisconnectReasonCode = /* @__PURE__ */ function(MqttDisconnectReasonCode) {
|
|
1309
1256
|
/**
|
|
1310
1257
|
* 0x00 - Normal disconnection
|
|
1311
1258
|
* Sent by: Client or Server
|
|
1312
1259
|
* Description: Close the connection normally. Do not send the Will Message.
|
|
1313
1260
|
*/
|
|
1314
|
-
MqttDisconnectReasonCode
|
|
1261
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["NormalDisconnection"] = 0] = "NormalDisconnection";
|
|
1315
1262
|
/**
|
|
1316
1263
|
* 0x04 - Disconnect with Will Message
|
|
1317
1264
|
* Sent by: Client
|
|
1318
1265
|
* Description: The Client wishes to disconnect but requires that the Server also publishes its Will Message.
|
|
1319
1266
|
*/
|
|
1320
|
-
MqttDisconnectReasonCode
|
|
1267
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["DisconnectWithWillMessage"] = 4] = "DisconnectWithWillMessage";
|
|
1321
1268
|
/**
|
|
1322
1269
|
* 0x80 - Unspecified error
|
|
1323
1270
|
* Sent by: Client or Server
|
|
1324
1271
|
* Description: The Connection is closed but the sender either does not wish to reveal the reason, or none of the other Reason Codes apply.
|
|
1325
1272
|
*/
|
|
1326
|
-
MqttDisconnectReasonCode
|
|
1273
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["UnspecifiedError"] = 128] = "UnspecifiedError";
|
|
1327
1274
|
/**
|
|
1328
1275
|
* 0x81 - Malformed Packet
|
|
1329
1276
|
* Sent by: Client or Server
|
|
1330
1277
|
* Description: The received packet does not conform to this specification.
|
|
1331
1278
|
*/
|
|
1332
|
-
MqttDisconnectReasonCode
|
|
1279
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["MalformedPacket"] = 129] = "MalformedPacket";
|
|
1333
1280
|
/**
|
|
1334
1281
|
* 0x82 - Protocol Error
|
|
1335
1282
|
* Sent by: Client or Server
|
|
1336
1283
|
* Description: An unexpected or out of order packet was received.
|
|
1337
1284
|
*/
|
|
1338
|
-
MqttDisconnectReasonCode
|
|
1285
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["ProtocolError"] = 130] = "ProtocolError";
|
|
1339
1286
|
/**
|
|
1340
1287
|
* 0x83 - Implementation specific error
|
|
1341
1288
|
* Sent by: Client or Server
|
|
1342
1289
|
* Description: The packet received is valid but cannot be processed by this implementation.
|
|
1343
1290
|
*/
|
|
1344
|
-
MqttDisconnectReasonCode
|
|
1291
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["ImplementationSpecificError"] = 131] = "ImplementationSpecificError";
|
|
1345
1292
|
/**
|
|
1346
1293
|
* 0x87 - Not authorized
|
|
1347
1294
|
* Sent by: Server
|
|
1348
1295
|
* Description: The request is not authorized.
|
|
1349
1296
|
*/
|
|
1350
|
-
MqttDisconnectReasonCode
|
|
1297
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["NotAuthorized"] = 135] = "NotAuthorized";
|
|
1351
1298
|
/**
|
|
1352
1299
|
* 0x89 - Server busy
|
|
1353
1300
|
* Sent by: Server
|
|
1354
1301
|
* Description: The Server is busy and cannot continue processing requests from this Client.
|
|
1355
1302
|
*/
|
|
1356
|
-
MqttDisconnectReasonCode
|
|
1303
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["ServerBusy"] = 137] = "ServerBusy";
|
|
1357
1304
|
/**
|
|
1358
1305
|
* 0x8B - Server shutting down
|
|
1359
1306
|
* Sent by: Server
|
|
1360
1307
|
* Description: The Server is shutting down.
|
|
1361
1308
|
*/
|
|
1362
|
-
MqttDisconnectReasonCode
|
|
1309
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["ServerShuttingDown"] = 139] = "ServerShuttingDown";
|
|
1363
1310
|
/**
|
|
1364
1311
|
* 0x8D - Keep Alive timeout
|
|
1365
1312
|
* Sent by: Server
|
|
1366
1313
|
* Description: The Connection is closed because no packet has been received for 1.5 times the Keepalive time.
|
|
1367
1314
|
*/
|
|
1368
|
-
MqttDisconnectReasonCode
|
|
1315
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["KeepAliveTimeout"] = 141] = "KeepAliveTimeout";
|
|
1369
1316
|
/**
|
|
1370
1317
|
* 0x8E - Session taken over
|
|
1371
1318
|
* Sent by: Server
|
|
1372
1319
|
* Description: Another Connection using the same ClientID has connected causing this Connection to be closed.
|
|
1373
1320
|
*/
|
|
1374
|
-
MqttDisconnectReasonCode
|
|
1321
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["SessionTakenOver"] = 142] = "SessionTakenOver";
|
|
1375
1322
|
/**
|
|
1376
1323
|
* 0x8F - Topic Filter invalid
|
|
1377
1324
|
* Sent by: Server
|
|
1378
1325
|
* Description: The Topic Filter is correctly formed, but is not accepted by this Server.
|
|
1379
1326
|
*/
|
|
1380
|
-
MqttDisconnectReasonCode
|
|
1327
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["TopicFilterInvalid"] = 143] = "TopicFilterInvalid";
|
|
1381
1328
|
/**
|
|
1382
1329
|
* 0x90 - Topic Name invalid
|
|
1383
1330
|
* Sent by: Client or Server
|
|
1384
1331
|
* Description: The Topic Name is correctly formed, but is not accepted by this Client or Server.
|
|
1385
1332
|
*/
|
|
1386
|
-
MqttDisconnectReasonCode
|
|
1333
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["TopicNameInvalid"] = 144] = "TopicNameInvalid";
|
|
1387
1334
|
/**
|
|
1388
1335
|
* 0x93 - Receive Maximum exceeded
|
|
1389
1336
|
* Sent by: Client or Server
|
|
1390
1337
|
* Description: The Client or Server has received more than Receive Maximum publication for which it has not sent PUBACK or PUBCOMP.
|
|
1391
1338
|
*/
|
|
1392
|
-
MqttDisconnectReasonCode
|
|
1339
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["ReceiveMaximumExceeded"] = 147] = "ReceiveMaximumExceeded";
|
|
1393
1340
|
/**
|
|
1394
1341
|
* 0x94 - Topic Alias invalid
|
|
1395
1342
|
* Sent by: Client or Server
|
|
1396
1343
|
* Description: The Client or Server has received a PUBLISH packet containing a Topic Alias which is greater than the Maximum Topic Alias it sent in the CONNECT or CONNACK packet.
|
|
1397
1344
|
*/
|
|
1398
|
-
MqttDisconnectReasonCode
|
|
1345
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["TopicAliasInvalid"] = 148] = "TopicAliasInvalid";
|
|
1399
1346
|
/**
|
|
1400
1347
|
* 0x95 - Packet too large
|
|
1401
1348
|
* Sent by: Client or Server
|
|
1402
1349
|
* Description: The packet size is greater than Maximum Packet Size for this Client or Server.
|
|
1403
1350
|
*/
|
|
1404
|
-
MqttDisconnectReasonCode
|
|
1351
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["PacketTooLarge"] = 149] = "PacketTooLarge";
|
|
1405
1352
|
/**
|
|
1406
1353
|
* 0x96 - Message rate too high
|
|
1407
1354
|
* Sent by: Client or Server
|
|
1408
1355
|
* Description: The received data rate is too high.
|
|
1409
1356
|
*/
|
|
1410
|
-
MqttDisconnectReasonCode
|
|
1357
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["MessageRateTooHigh"] = 150] = "MessageRateTooHigh";
|
|
1411
1358
|
/**
|
|
1412
1359
|
* 0x97 - Quota exceeded
|
|
1413
1360
|
* Sent by: Client or Server
|
|
1414
1361
|
* Description: An implementation or administrative imposed limit has been exceeded.
|
|
1415
1362
|
*/
|
|
1416
|
-
MqttDisconnectReasonCode
|
|
1363
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["QuotaExceeded"] = 151] = "QuotaExceeded";
|
|
1417
1364
|
/**
|
|
1418
1365
|
* 0x98 - Administrative action
|
|
1419
1366
|
* Sent by: Client or Server
|
|
1420
1367
|
* Description: The Connection is closed due to an administrative action.
|
|
1421
1368
|
*/
|
|
1422
|
-
MqttDisconnectReasonCode
|
|
1369
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["AdministrativeAction"] = 152] = "AdministrativeAction";
|
|
1423
1370
|
/**
|
|
1424
1371
|
* 0x99 - Payload format invalid
|
|
1425
1372
|
* Sent by: Client or Server
|
|
1426
1373
|
* Description: The payload format does not match the one specified by the Payload Format Indicator.
|
|
1427
1374
|
*/
|
|
1428
|
-
MqttDisconnectReasonCode
|
|
1375
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["PayloadFormatInvalid"] = 153] = "PayloadFormatInvalid";
|
|
1429
1376
|
/**
|
|
1430
1377
|
* 0x9A - Retain not supported
|
|
1431
1378
|
* Sent by: Server
|
|
1432
1379
|
* Description: The Server does not support retained messages.
|
|
1433
1380
|
*/
|
|
1434
|
-
MqttDisconnectReasonCode
|
|
1381
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["RetainNotSupported"] = 154] = "RetainNotSupported";
|
|
1435
1382
|
/**
|
|
1436
1383
|
* 0x9B - QoS not supported
|
|
1437
1384
|
* Sent by: Server
|
|
1438
1385
|
* Description: The Client specified a QoS greater than the QoS specified in a Maximum QoS in the CONNACK.
|
|
1439
1386
|
*/
|
|
1440
|
-
MqttDisconnectReasonCode
|
|
1387
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["QosNotSupported"] = 155] = "QosNotSupported";
|
|
1441
1388
|
/**
|
|
1442
1389
|
* 0x9C - Use another server
|
|
1443
1390
|
* Sent by: Server
|
|
1444
1391
|
* Description: The Client should temporarily change its Server.
|
|
1445
1392
|
*/
|
|
1446
|
-
MqttDisconnectReasonCode
|
|
1393
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["UseAnotherServer"] = 156] = "UseAnotherServer";
|
|
1447
1394
|
/**
|
|
1448
1395
|
* 0x9D - Server moved
|
|
1449
1396
|
* Sent by: Server
|
|
1450
1397
|
* Description: The Server is moved and the Client should permanently change its server location.
|
|
1451
1398
|
*/
|
|
1452
|
-
MqttDisconnectReasonCode
|
|
1399
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["ServerMoved"] = 157] = "ServerMoved";
|
|
1453
1400
|
/**
|
|
1454
1401
|
* 0x9E - Shared Subscriptions not supported
|
|
1455
1402
|
* Sent by: Server
|
|
1456
1403
|
* Description: The Server does not support Shared Subscriptions.
|
|
1457
1404
|
*/
|
|
1458
|
-
MqttDisconnectReasonCode
|
|
1405
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["SharedSubscriptionsNotSupported"] = 158] = "SharedSubscriptionsNotSupported";
|
|
1459
1406
|
/**
|
|
1460
1407
|
* 0x9F - Connection rate exceeded
|
|
1461
1408
|
* Sent by: Server
|
|
1462
1409
|
* Description: This connection is closed because the connection rate is too high.
|
|
1463
1410
|
*/
|
|
1464
|
-
MqttDisconnectReasonCode
|
|
1411
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["ConnectionRateExceeded"] = 159] = "ConnectionRateExceeded";
|
|
1465
1412
|
/**
|
|
1466
1413
|
* 0xA0 - Maximum connect time
|
|
1467
1414
|
* Sent by: Server
|
|
1468
1415
|
* Description: The maximum connection time authorized for this connection has been exceeded.
|
|
1469
1416
|
*/
|
|
1470
|
-
MqttDisconnectReasonCode
|
|
1417
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["MaximumConnectTime"] = 160] = "MaximumConnectTime";
|
|
1471
1418
|
/**
|
|
1472
1419
|
* 0xA1 - Subscription Identifiers not supported
|
|
1473
1420
|
* Sent by: Server
|
|
1474
1421
|
* Description: The Server does not support Subscription Identifiers; the subscription is not accepted.
|
|
1475
1422
|
*/
|
|
1476
|
-
MqttDisconnectReasonCode
|
|
1423
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["SubscriptionIdentifiersNotSupported"] = 161] = "SubscriptionIdentifiersNotSupported";
|
|
1477
1424
|
/**
|
|
1478
1425
|
* 0xA2 - Wildcard Subscriptions not supported
|
|
1479
1426
|
* Sent by: Server
|
|
1480
1427
|
* Description: The Server does not support Wildcard Subscriptions; the subscription is not accepted.
|
|
1481
1428
|
*/
|
|
1482
|
-
MqttDisconnectReasonCode
|
|
1483
|
-
return MqttDisconnectReasonCode
|
|
1429
|
+
MqttDisconnectReasonCode[MqttDisconnectReasonCode["WildcardSubscriptionsNotSupported"] = 162] = "WildcardSubscriptionsNotSupported";
|
|
1430
|
+
return MqttDisconnectReasonCode;
|
|
1484
1431
|
}({});
|
|
1485
|
-
|
|
1486
|
-
//#endregion
|
|
1487
|
-
//#region ../../node_modules/lib0/binary.js
|
|
1488
|
-
const BIT8 = 128;
|
|
1489
|
-
const BIT18 = 1 << 17;
|
|
1490
|
-
const BIT19 = 1 << 18;
|
|
1491
|
-
const BIT20 = 1 << 19;
|
|
1492
|
-
const BIT21 = 1 << 20;
|
|
1493
|
-
const BIT22 = 1 << 21;
|
|
1494
|
-
const BIT23 = 1 << 22;
|
|
1495
|
-
const BIT24 = 1 << 23;
|
|
1496
|
-
const BIT25 = 1 << 24;
|
|
1497
|
-
const BIT26 = 1 << 25;
|
|
1498
|
-
const BIT27 = 1 << 26;
|
|
1499
|
-
const BIT28 = 1 << 27;
|
|
1500
|
-
const BIT29 = 1 << 28;
|
|
1501
|
-
const BIT30 = 1 << 29;
|
|
1502
|
-
const BIT31 = 1 << 30;
|
|
1503
|
-
const BIT32 = 1 << 31;
|
|
1504
|
-
const BITS7 = 127;
|
|
1505
|
-
const BITS17 = BIT18 - 1;
|
|
1506
|
-
const BITS18 = BIT19 - 1;
|
|
1507
|
-
const BITS19 = BIT20 - 1;
|
|
1508
|
-
const BITS20 = BIT21 - 1;
|
|
1509
|
-
const BITS21 = BIT22 - 1;
|
|
1510
|
-
const BITS22 = BIT23 - 1;
|
|
1511
|
-
const BITS23 = BIT24 - 1;
|
|
1512
|
-
const BITS24 = BIT25 - 1;
|
|
1513
|
-
const BITS25 = BIT26 - 1;
|
|
1514
|
-
const BITS26 = BIT27 - 1;
|
|
1515
|
-
const BITS27 = BIT28 - 1;
|
|
1516
|
-
const BITS28 = BIT29 - 1;
|
|
1517
|
-
const BITS29 = BIT30 - 1;
|
|
1518
|
-
const BITS30 = BIT31 - 1;
|
|
1519
|
-
/**
|
|
1520
|
-
* @type {number}
|
|
1521
|
-
*/
|
|
1522
|
-
const BITS31 = 2147483647;
|
|
1523
|
-
/**
|
|
1524
|
-
* @type {number}
|
|
1525
|
-
*/
|
|
1526
|
-
const BITS32 = 4294967295;
|
|
1527
|
-
|
|
1528
1432
|
//#endregion
|
|
1529
1433
|
//#region ../../node_modules/lib0/math.js
|
|
1530
1434
|
/**
|
|
@@ -1547,20 +1451,19 @@ const min = (a, b) => a < b ? a : b;
|
|
|
1547
1451
|
* @return {number} The bigger element of a and b
|
|
1548
1452
|
*/
|
|
1549
1453
|
const max = (a, b) => a > b ? a : b;
|
|
1550
|
-
|
|
1551
|
-
|
|
1454
|
+
Number.isNaN;
|
|
1552
1455
|
//#endregion
|
|
1553
1456
|
//#region ../../node_modules/lib0/number.js
|
|
1457
|
+
/**
|
|
1458
|
+
* Utility helpers for working with numbers.
|
|
1459
|
+
*
|
|
1460
|
+
* @module number
|
|
1461
|
+
*/
|
|
1554
1462
|
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
/* c8 ignore next */
|
|
1560
|
-
const isInteger = Number.isInteger || ((num) => typeof num === "number" && isFinite(num) && floor(num) === num);
|
|
1561
|
-
const isNaN = Number.isNaN;
|
|
1562
|
-
const parseInt = Number.parseInt;
|
|
1563
|
-
|
|
1463
|
+
Number.MIN_SAFE_INTEGER;
|
|
1464
|
+
Number.isInteger;
|
|
1465
|
+
Number.isNaN;
|
|
1466
|
+
Number.parseInt;
|
|
1564
1467
|
//#endregion
|
|
1565
1468
|
//#region ../../node_modules/lib0/set.js
|
|
1566
1469
|
/**
|
|
@@ -1568,8 +1471,7 @@ const parseInt = Number.parseInt;
|
|
|
1568
1471
|
*
|
|
1569
1472
|
* @module set
|
|
1570
1473
|
*/
|
|
1571
|
-
const create$2 = () => new Set();
|
|
1572
|
-
|
|
1474
|
+
const create$2 = () => /* @__PURE__ */ new Set();
|
|
1573
1475
|
//#endregion
|
|
1574
1476
|
//#region ../../node_modules/lib0/array.js
|
|
1575
1477
|
/**
|
|
@@ -1581,8 +1483,7 @@ const create$2 = () => new Set();
|
|
|
1581
1483
|
* @return {T}
|
|
1582
1484
|
*/
|
|
1583
1485
|
const from = Array.from;
|
|
1584
|
-
|
|
1585
|
-
|
|
1486
|
+
Array.isArray;
|
|
1586
1487
|
//#endregion
|
|
1587
1488
|
//#region ../../node_modules/lib0/string.js
|
|
1588
1489
|
/**
|
|
@@ -1591,12 +1492,8 @@ const isArray$1 = Array.isArray;
|
|
|
1591
1492
|
* @module string
|
|
1592
1493
|
*/
|
|
1593
1494
|
const fromCharCode = String.fromCharCode;
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
* The largest utf16 character.
|
|
1597
|
-
* Corresponds to Uint8Array([255, 255]) or charcodeof(2x2^8)
|
|
1598
|
-
*/
|
|
1599
|
-
const MAX_UTF16_CHARACTER = fromCharCode(65535);
|
|
1495
|
+
String.fromCodePoint;
|
|
1496
|
+
fromCharCode(65535);
|
|
1600
1497
|
/**
|
|
1601
1498
|
* @param {string} str
|
|
1602
1499
|
* @return {Uint8Array<ArrayBuffer>}
|
|
@@ -1627,10 +1524,9 @@ let utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecode
|
|
|
1627
1524
|
ignoreBOM: true
|
|
1628
1525
|
});
|
|
1629
1526
|
/* c8 ignore start */
|
|
1630
|
-
if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1)
|
|
1527
|
+
if (utf8TextDecoder && utf8TextDecoder.decode(/* @__PURE__ */ new Uint8Array()).length === 1)
|
|
1631
1528
|
/* c8 ignore next */
|
|
1632
1529
|
utf8TextDecoder = null;
|
|
1633
|
-
|
|
1634
1530
|
//#endregion
|
|
1635
1531
|
//#region ../../node_modules/lib0/error.js
|
|
1636
1532
|
/**
|
|
@@ -1644,16 +1540,42 @@ utf8TextDecoder = null;
|
|
|
1644
1540
|
*/
|
|
1645
1541
|
/* c8 ignore next */
|
|
1646
1542
|
const create$1 = (s) => new Error(s);
|
|
1647
|
-
|
|
1648
1543
|
//#endregion
|
|
1649
1544
|
//#region ../../node_modules/lib0/encoding.js
|
|
1650
1545
|
/**
|
|
1546
|
+
* Efficient schema-less binary encoding with support for variable length encoding.
|
|
1547
|
+
*
|
|
1548
|
+
* Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.
|
|
1549
|
+
*
|
|
1550
|
+
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
1551
|
+
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
1552
|
+
* which is also used in Protocol Buffers.
|
|
1553
|
+
*
|
|
1554
|
+
* ```js
|
|
1555
|
+
* // encoding step
|
|
1556
|
+
* const encoder = encoding.createEncoder()
|
|
1557
|
+
* encoding.writeVarUint(encoder, 256)
|
|
1558
|
+
* encoding.writeVarString(encoder, 'Hello world!')
|
|
1559
|
+
* const buf = encoding.toUint8Array(encoder)
|
|
1560
|
+
* ```
|
|
1561
|
+
*
|
|
1562
|
+
* ```js
|
|
1563
|
+
* // decoding step
|
|
1564
|
+
* const decoder = decoding.createDecoder(buf)
|
|
1565
|
+
* decoding.readVarUint(decoder) // => 256
|
|
1566
|
+
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
1567
|
+
* decoding.hasContent(decoder) // => false - all data is read
|
|
1568
|
+
* ```
|
|
1569
|
+
*
|
|
1570
|
+
* @module encoding
|
|
1571
|
+
*/
|
|
1572
|
+
/**
|
|
1651
1573
|
* A BinaryEncoder handles the encoding to an Uint8Array.
|
|
1652
1574
|
*/
|
|
1653
1575
|
var Encoder = class {
|
|
1654
1576
|
constructor() {
|
|
1655
1577
|
this.cpos = 0;
|
|
1656
|
-
this.cbuf = new Uint8Array(100);
|
|
1578
|
+
this.cbuf = /* @__PURE__ */ new Uint8Array(100);
|
|
1657
1579
|
/**
|
|
1658
1580
|
* @type {Array<Uint8Array>}
|
|
1659
1581
|
*/
|
|
@@ -1719,16 +1641,16 @@ const write = (encoder, num) => {
|
|
|
1719
1641
|
* @param {number} num The number that is to be encoded.
|
|
1720
1642
|
*/
|
|
1721
1643
|
const writeVarUint = (encoder, num) => {
|
|
1722
|
-
while (num >
|
|
1723
|
-
write(encoder,
|
|
1644
|
+
while (num > 127) {
|
|
1645
|
+
write(encoder, 128 | 127 & num);
|
|
1724
1646
|
num = floor(num / 128);
|
|
1725
1647
|
}
|
|
1726
|
-
write(encoder,
|
|
1648
|
+
write(encoder, 127 & num);
|
|
1727
1649
|
};
|
|
1728
1650
|
/**
|
|
1729
1651
|
* A cache to store strings temporarily
|
|
1730
1652
|
*/
|
|
1731
|
-
const _strBuffer = new Uint8Array(3e4);
|
|
1653
|
+
const _strBuffer = /* @__PURE__ */ new Uint8Array(3e4);
|
|
1732
1654
|
const _maxStrBSize = _strBuffer.length / 3;
|
|
1733
1655
|
/**
|
|
1734
1656
|
* Write a variable length string.
|
|
@@ -1756,11 +1678,7 @@ const _writeVarStringPolyfill = (encoder, str) => {
|
|
|
1756
1678
|
const encodedString = unescape(encodeURIComponent(str));
|
|
1757
1679
|
const len = encodedString.length;
|
|
1758
1680
|
writeVarUint(encoder, len);
|
|
1759
|
-
for (let i = 0; i < len; i++) write(
|
|
1760
|
-
encoder,
|
|
1761
|
-
/** @type {number} */
|
|
1762
|
-
encodedString.codePointAt(i)
|
|
1763
|
-
);
|
|
1681
|
+
for (let i = 0; i < len; i++) write(encoder, encodedString.codePointAt(i));
|
|
1764
1682
|
};
|
|
1765
1683
|
/**
|
|
1766
1684
|
* Write a variable length string.
|
|
@@ -1803,10 +1721,35 @@ const writeVarUint8Array = (encoder, uint8Array) => {
|
|
|
1803
1721
|
writeVarUint(encoder, uint8Array.byteLength);
|
|
1804
1722
|
writeUint8Array(encoder, uint8Array);
|
|
1805
1723
|
};
|
|
1806
|
-
const floatTestBed = new DataView(new ArrayBuffer(4));
|
|
1807
|
-
|
|
1808
1724
|
//#endregion
|
|
1809
1725
|
//#region ../../node_modules/lib0/decoding.js
|
|
1726
|
+
/**
|
|
1727
|
+
* Efficient schema-less binary decoding with support for variable length encoding.
|
|
1728
|
+
*
|
|
1729
|
+
* Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.
|
|
1730
|
+
*
|
|
1731
|
+
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
1732
|
+
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
1733
|
+
* which is also used in Protocol Buffers.
|
|
1734
|
+
*
|
|
1735
|
+
* ```js
|
|
1736
|
+
* // encoding step
|
|
1737
|
+
* const encoder = encoding.createEncoder()
|
|
1738
|
+
* encoding.writeVarUint(encoder, 256)
|
|
1739
|
+
* encoding.writeVarString(encoder, 'Hello world!')
|
|
1740
|
+
* const buf = encoding.toUint8Array(encoder)
|
|
1741
|
+
* ```
|
|
1742
|
+
*
|
|
1743
|
+
* ```js
|
|
1744
|
+
* // decoding step
|
|
1745
|
+
* const decoder = decoding.createDecoder(buf)
|
|
1746
|
+
* decoding.readVarUint(decoder) // => 256
|
|
1747
|
+
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
1748
|
+
* decoding.hasContent(decoder) // => false - all data is read
|
|
1749
|
+
* ```
|
|
1750
|
+
*
|
|
1751
|
+
* @module decoding
|
|
1752
|
+
*/
|
|
1810
1753
|
const errorUnexpectedEndOfArray = create$1("Unexpected end of array");
|
|
1811
1754
|
const errorIntegerOutOfRange = create$1("Integer out of Range");
|
|
1812
1755
|
/**
|
|
@@ -1891,9 +1834,9 @@ const readVarUint = (decoder) => {
|
|
|
1891
1834
|
const len = decoder.arr.length;
|
|
1892
1835
|
while (decoder.pos < len) {
|
|
1893
1836
|
const r = decoder.arr[decoder.pos++];
|
|
1894
|
-
num = num + (r &
|
|
1837
|
+
num = num + (r & 127) * mult;
|
|
1895
1838
|
mult *= 128;
|
|
1896
|
-
if (r <
|
|
1839
|
+
if (r < 128) return num;
|
|
1897
1840
|
/* c8 ignore start */
|
|
1898
1841
|
if (num > MAX_SAFE_INTEGER) throw errorIntegerOutOfRange;
|
|
1899
1842
|
}
|
|
@@ -1923,11 +1866,7 @@ const _readVarStringPolyfill = (decoder) => {
|
|
|
1923
1866
|
const nextLen = remainingLen < 1e4 ? remainingLen : 1e4;
|
|
1924
1867
|
const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen);
|
|
1925
1868
|
decoder.pos += nextLen;
|
|
1926
|
-
encodedString += String.fromCodePoint.apply(
|
|
1927
|
-
null,
|
|
1928
|
-
/** @type {any} */
|
|
1929
|
-
bytes
|
|
1930
|
-
);
|
|
1869
|
+
encodedString += String.fromCodePoint.apply(null, bytes);
|
|
1931
1870
|
remainingLen -= nextLen;
|
|
1932
1871
|
}
|
|
1933
1872
|
return decodeURIComponent(escape(encodedString));
|
|
@@ -1951,39 +1890,6 @@ const _readVarStringNative = (decoder) => utf8TextDecoder.decode(readVarUint8Arr
|
|
|
1951
1890
|
*/
|
|
1952
1891
|
/* c8 ignore next */
|
|
1953
1892
|
const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
1954
|
-
|
|
1955
|
-
//#endregion
|
|
1956
|
-
//#region ../../node_modules/y-protocols/sync.js
|
|
1957
|
-
/**
|
|
1958
|
-
* @typedef {Map<number, number>} StateMap
|
|
1959
|
-
*/
|
|
1960
|
-
/**
|
|
1961
|
-
* Core Yjs defines two message types:
|
|
1962
|
-
* • YjsSyncStep1: Includes the State Set of the sending client. When received, the client should reply with YjsSyncStep2.
|
|
1963
|
-
* • YjsSyncStep2: Includes all missing structs and the complete delete set. When received, the client is assured that it
|
|
1964
|
-
* received all information from the remote client.
|
|
1965
|
-
*
|
|
1966
|
-
* In a peer-to-peer network, you may want to introduce a SyncDone message type. Both parties should initiate the connection
|
|
1967
|
-
* with SyncStep1. When a client received SyncStep2, it should reply with SyncDone. When the local client received both
|
|
1968
|
-
* SyncStep2 and SyncDone, it is assured that it is synced to the remote client.
|
|
1969
|
-
*
|
|
1970
|
-
* In a client-server model, you want to handle this differently: The client should initiate the connection with SyncStep1.
|
|
1971
|
-
* When the server receives SyncStep1, it should reply with SyncStep2 immediately followed by SyncStep1. The client replies
|
|
1972
|
-
* with SyncStep2 when it receives SyncStep1. Optionally the server may send a SyncDone after it received SyncStep2, so the
|
|
1973
|
-
* client knows that the sync is finished. There are two reasons for this more elaborated sync model: 1. This protocol can
|
|
1974
|
-
* easily be implemented on top of http and websockets. 2. The server should only reply to requests, and not initiate them.
|
|
1975
|
-
* Therefore it is necessary that the client initiates the sync.
|
|
1976
|
-
*
|
|
1977
|
-
* Construction of a message:
|
|
1978
|
-
* [messageType : varUint, message definition..]
|
|
1979
|
-
*
|
|
1980
|
-
* Note: A message does not include information about the room name. This must to be handled by the upper layer protocol!
|
|
1981
|
-
*
|
|
1982
|
-
* stringify[messageType] stringifies a message definition (messageType is already read from the bufffer)
|
|
1983
|
-
*/
|
|
1984
|
-
const messageYjsSyncStep1 = 0;
|
|
1985
|
-
const messageYjsSyncStep2 = 1;
|
|
1986
|
-
const messageYjsUpdate = 2;
|
|
1987
1893
|
/**
|
|
1988
1894
|
* Create a sync step 1 message based on the state of the current shared document.
|
|
1989
1895
|
*
|
|
@@ -1991,7 +1897,7 @@ const messageYjsUpdate = 2;
|
|
|
1991
1897
|
* @param {Y.Doc} doc
|
|
1992
1898
|
*/
|
|
1993
1899
|
const writeSyncStep1 = (encoder, doc) => {
|
|
1994
|
-
writeVarUint(encoder,
|
|
1900
|
+
writeVarUint(encoder, 0);
|
|
1995
1901
|
const sv = Y.encodeStateVector(doc);
|
|
1996
1902
|
writeVarUint8Array(encoder, sv);
|
|
1997
1903
|
};
|
|
@@ -2001,7 +1907,7 @@ const writeSyncStep1 = (encoder, doc) => {
|
|
|
2001
1907
|
* @param {Uint8Array} [encodedStateVector]
|
|
2002
1908
|
*/
|
|
2003
1909
|
const writeSyncStep2 = (encoder, doc, encodedStateVector) => {
|
|
2004
|
-
writeVarUint(encoder,
|
|
1910
|
+
writeVarUint(encoder, 1);
|
|
2005
1911
|
writeVarUint8Array(encoder, Y.encodeStateAsUpdate(doc, encodedStateVector));
|
|
2006
1912
|
};
|
|
2007
1913
|
/**
|
|
@@ -2024,10 +1930,7 @@ const readSyncStep2 = (decoder, doc, transactionOrigin, errorHandler) => {
|
|
|
2024
1930
|
try {
|
|
2025
1931
|
Y.applyUpdate(doc, readVarUint8Array(decoder), transactionOrigin);
|
|
2026
1932
|
} catch (error) {
|
|
2027
|
-
if (errorHandler != null) errorHandler(
|
|
2028
|
-
/** @type {Error} */
|
|
2029
|
-
error
|
|
2030
|
-
);
|
|
1933
|
+
if (errorHandler != null) errorHandler(error);
|
|
2031
1934
|
console.error("Caught error while handling a Yjs update", error);
|
|
2032
1935
|
}
|
|
2033
1936
|
};
|
|
@@ -2036,7 +1939,7 @@ const readSyncStep2 = (decoder, doc, transactionOrigin, errorHandler) => {
|
|
|
2036
1939
|
* @param {Uint8Array} update
|
|
2037
1940
|
*/
|
|
2038
1941
|
const writeUpdate = (encoder, update) => {
|
|
2039
|
-
writeVarUint(encoder,
|
|
1942
|
+
writeVarUint(encoder, 2);
|
|
2040
1943
|
writeVarUint8Array(encoder, update);
|
|
2041
1944
|
};
|
|
2042
1945
|
/**
|
|
@@ -2058,20 +1961,19 @@ const readUpdate = readSyncStep2;
|
|
|
2058
1961
|
const readSyncMessage = (decoder, encoder, doc, transactionOrigin, errorHandler) => {
|
|
2059
1962
|
const messageType = readVarUint(decoder);
|
|
2060
1963
|
switch (messageType) {
|
|
2061
|
-
case
|
|
1964
|
+
case 0:
|
|
2062
1965
|
readSyncStep1(decoder, encoder, doc);
|
|
2063
1966
|
break;
|
|
2064
|
-
case
|
|
1967
|
+
case 1:
|
|
2065
1968
|
readSyncStep2(decoder, doc, transactionOrigin, errorHandler);
|
|
2066
1969
|
break;
|
|
2067
|
-
case
|
|
1970
|
+
case 2:
|
|
2068
1971
|
readUpdate(decoder, doc, transactionOrigin, errorHandler);
|
|
2069
1972
|
break;
|
|
2070
1973
|
default: throw new Error("Unknown message type");
|
|
2071
1974
|
}
|
|
2072
1975
|
return messageType;
|
|
2073
1976
|
};
|
|
2074
|
-
|
|
2075
1977
|
//#endregion
|
|
2076
1978
|
//#region ../../node_modules/lib0/time.js
|
|
2077
1979
|
/**
|
|
@@ -2080,7 +1982,6 @@ const readSyncMessage = (decoder, encoder, doc, transactionOrigin, errorHandler)
|
|
|
2080
1982
|
* @return {number}
|
|
2081
1983
|
*/
|
|
2082
1984
|
const getUnixTime = Date.now;
|
|
2083
|
-
|
|
2084
1985
|
//#endregion
|
|
2085
1986
|
//#region ../../node_modules/lib0/map.js
|
|
2086
1987
|
/**
|
|
@@ -2101,7 +2002,7 @@ const getUnixTime = Date.now;
|
|
|
2101
2002
|
*
|
|
2102
2003
|
* @function
|
|
2103
2004
|
*/
|
|
2104
|
-
const create = () => new Map();
|
|
2005
|
+
const create = () => /* @__PURE__ */ new Map();
|
|
2105
2006
|
/**
|
|
2106
2007
|
* Get map property. Create T if property is undefined and set T on map.
|
|
2107
2008
|
*
|
|
@@ -2123,9 +2024,13 @@ const setIfUndefined = (map, key, createT) => {
|
|
|
2123
2024
|
if (set === void 0) map.set(key, set = createT());
|
|
2124
2025
|
return set;
|
|
2125
2026
|
};
|
|
2126
|
-
|
|
2127
2027
|
//#endregion
|
|
2128
2028
|
//#region ../../node_modules/lib0/observable.js
|
|
2029
|
+
/**
|
|
2030
|
+
* Observable class prototype.
|
|
2031
|
+
*
|
|
2032
|
+
* @module observable
|
|
2033
|
+
*/
|
|
2129
2034
|
/* c8 ignore start */
|
|
2130
2035
|
/**
|
|
2131
2036
|
* Handles named events.
|
|
@@ -2190,11 +2095,9 @@ var Observable = class {
|
|
|
2190
2095
|
}
|
|
2191
2096
|
};
|
|
2192
2097
|
/* c8 ignore end */
|
|
2193
|
-
|
|
2194
2098
|
//#endregion
|
|
2195
2099
|
//#region ../../node_modules/lib0/trait/equality.js
|
|
2196
2100
|
const EqualityTraitSymbol = Symbol("Equality");
|
|
2197
|
-
|
|
2198
2101
|
//#endregion
|
|
2199
2102
|
//#region ../../node_modules/lib0/object.js
|
|
2200
2103
|
/**
|
|
@@ -2214,7 +2117,6 @@ const size = (obj) => keys(obj).length;
|
|
|
2214
2117
|
* @return {boolean}
|
|
2215
2118
|
*/
|
|
2216
2119
|
const hasProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
2217
|
-
|
|
2218
2120
|
//#endregion
|
|
2219
2121
|
//#region ../../node_modules/lib0/function.js
|
|
2220
2122
|
/* c8 ignore start */
|
|
@@ -2231,21 +2133,18 @@ const equalityDeep = (a, b) => {
|
|
|
2231
2133
|
case ArrayBuffer:
|
|
2232
2134
|
a = new Uint8Array(a);
|
|
2233
2135
|
b = new Uint8Array(b);
|
|
2234
|
-
case Uint8Array:
|
|
2136
|
+
case Uint8Array:
|
|
2235
2137
|
if (a.byteLength !== b.byteLength) return false;
|
|
2236
2138
|
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
2237
2139
|
break;
|
|
2238
|
-
|
|
2239
|
-
case Set: {
|
|
2140
|
+
case Set:
|
|
2240
2141
|
if (a.size !== b.size) return false;
|
|
2241
2142
|
for (const value of a) if (!b.has(value)) return false;
|
|
2242
2143
|
break;
|
|
2243
|
-
|
|
2244
|
-
case Map: {
|
|
2144
|
+
case Map:
|
|
2245
2145
|
if (a.size !== b.size) return false;
|
|
2246
2146
|
for (const key of a.keys()) if (!b.has(key) || !equalityDeep(a.get(key), b.get(key))) return false;
|
|
2247
2147
|
break;
|
|
2248
|
-
}
|
|
2249
2148
|
case void 0:
|
|
2250
2149
|
case Object:
|
|
2251
2150
|
if (size(a) !== size(b)) return false;
|
|
@@ -2259,11 +2158,11 @@ const equalityDeep = (a, b) => {
|
|
|
2259
2158
|
}
|
|
2260
2159
|
return true;
|
|
2261
2160
|
};
|
|
2262
|
-
/* c8 ignore stop */
|
|
2263
|
-
const isArray = isArray$1;
|
|
2264
|
-
|
|
2265
2161
|
//#endregion
|
|
2266
2162
|
//#region ../../node_modules/y-protocols/awareness.js
|
|
2163
|
+
/**
|
|
2164
|
+
* @module awareness-protocol
|
|
2165
|
+
*/
|
|
2267
2166
|
const outdatedTimeout = 3e4;
|
|
2268
2167
|
/**
|
|
2269
2168
|
* @typedef {Object} MetaClientState
|
|
@@ -2303,20 +2202,20 @@ var Awareness = class extends Observable {
|
|
|
2303
2202
|
* Maps from client id to client state
|
|
2304
2203
|
* @type {Map<number, Object<string, any>>}
|
|
2305
2204
|
*/
|
|
2306
|
-
this.states = new Map();
|
|
2205
|
+
this.states = /* @__PURE__ */ new Map();
|
|
2307
2206
|
/**
|
|
2308
2207
|
* @type {Map<number, MetaClientState>}
|
|
2309
2208
|
*/
|
|
2310
|
-
this.meta = new Map();
|
|
2209
|
+
this.meta = /* @__PURE__ */ new Map();
|
|
2311
2210
|
this._checkInterval = setInterval(() => {
|
|
2312
2211
|
const now = getUnixTime();
|
|
2313
|
-
if (this.getLocalState() !== null &&
|
|
2212
|
+
if (this.getLocalState() !== null && 15e3 <= now - this.meta.get(this.clientID).lastUpdated) this.setLocalState(this.getLocalState());
|
|
2314
2213
|
/**
|
|
2315
2214
|
* @type {Array<number>}
|
|
2316
2215
|
*/
|
|
2317
2216
|
const remove = [];
|
|
2318
2217
|
this.meta.forEach((meta, clientid) => {
|
|
2319
|
-
if (clientid !== this.clientID &&
|
|
2218
|
+
if (clientid !== this.clientID && 3e4 <= now - meta.lastUpdated && this.states.has(clientid)) remove.push(clientid);
|
|
2320
2219
|
});
|
|
2321
2220
|
if (remove.length > 0) removeAwarenessStates(this, remove, "timeout");
|
|
2322
2221
|
}, floor(outdatedTimeout / 10));
|
|
@@ -2468,9 +2367,10 @@ const applyAwarenessUpdate = (awareness, update, origin) => {
|
|
|
2468
2367
|
const prevState = awareness.states.get(clientID);
|
|
2469
2368
|
const currClock = clientMeta === void 0 ? 0 : clientMeta.clock;
|
|
2470
2369
|
if (currClock < clock || currClock === clock && state === null && awareness.states.has(clientID)) {
|
|
2471
|
-
if (state === null)
|
|
2472
|
-
|
|
2473
|
-
|
|
2370
|
+
if (state === null) {
|
|
2371
|
+
if (clientID === awareness.clientID && awareness.getLocalState() != null) clock++;
|
|
2372
|
+
else awareness.states.delete(clientID);
|
|
2373
|
+
} else awareness.states.set(clientID, state);
|
|
2474
2374
|
awareness.meta.set(clientID, {
|
|
2475
2375
|
clock,
|
|
2476
2376
|
lastUpdated: timestamp
|
|
@@ -2494,7 +2394,6 @@ const applyAwarenessUpdate = (awareness, update, origin) => {
|
|
|
2494
2394
|
removed
|
|
2495
2395
|
}, origin]);
|
|
2496
2396
|
};
|
|
2497
|
-
|
|
2498
2397
|
//#endregion
|
|
2499
2398
|
//#region src/utils.ts
|
|
2500
2399
|
function handleChunkedMessage(chunkedMessagesMap, messageData) {
|
|
@@ -2511,7 +2410,6 @@ function handleChunkedMessage(chunkedMessagesMap, messageData) {
|
|
|
2511
2410
|
}
|
|
2512
2411
|
return joined;
|
|
2513
2412
|
}
|
|
2514
|
-
|
|
2515
2413
|
//#endregion
|
|
2516
2414
|
//#region src/constants.ts
|
|
2517
2415
|
const WEAVE_STORE_AZURE_WEB_PUBSUB = "store-azure-web-pubsub";
|
|
@@ -2544,7 +2442,6 @@ const WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_HOST_DEFAULT_OPTIONS = {
|
|
|
2544
2442
|
attemptsLimit: 12
|
|
2545
2443
|
}
|
|
2546
2444
|
};
|
|
2547
|
-
|
|
2548
2445
|
//#endregion
|
|
2549
2446
|
//#region src/server/azure-web-pubsub-host.ts
|
|
2550
2447
|
const expirationTimeInMinutes = 60;
|
|
@@ -2553,10 +2450,24 @@ const messageAwareness = 1;
|
|
|
2553
2450
|
const AzureWebPubSubJsonProtocol = "json.webpubsub.azure.v1";
|
|
2554
2451
|
const HostUserId = "host";
|
|
2555
2452
|
var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
2453
|
+
server;
|
|
2454
|
+
syncHandler;
|
|
2455
|
+
doc;
|
|
2456
|
+
topic;
|
|
2457
|
+
topicAwarenessChannel;
|
|
2458
|
+
_client;
|
|
2459
|
+
_conn;
|
|
2556
2460
|
_reconnectAttempts = 0;
|
|
2557
2461
|
_forceClose = false;
|
|
2462
|
+
_awareness;
|
|
2463
|
+
_chunkedMessages;
|
|
2464
|
+
_syncHostOptions;
|
|
2465
|
+
_heartbeatIntervalId;
|
|
2466
|
+
_reconnectionTimeoutId;
|
|
2558
2467
|
_resyncAttempt = 0;
|
|
2559
2468
|
_resyncIntervalId = null;
|
|
2469
|
+
_updateHandler;
|
|
2470
|
+
_awarenessUpdateHandler;
|
|
2560
2471
|
constructor(server, syncHandler, client, topic, doc, syncHostOptions) {
|
|
2561
2472
|
this._syncHostOptions = mergeExceptArrays(WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_HOST_DEFAULT_OPTIONS, syncHostOptions ?? {});
|
|
2562
2473
|
this.server = server;
|
|
@@ -2565,7 +2476,7 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2565
2476
|
this.topic = topic;
|
|
2566
2477
|
this.topicAwarenessChannel = `${topic}-awareness`;
|
|
2567
2478
|
this._client = client;
|
|
2568
|
-
this._chunkedMessages = new Map();
|
|
2479
|
+
this._chunkedMessages = /* @__PURE__ */ new Map();
|
|
2569
2480
|
this._heartbeatIntervalId = null;
|
|
2570
2481
|
this._reconnectionTimeoutId = null;
|
|
2571
2482
|
this._conn = null;
|
|
@@ -2613,7 +2524,7 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2613
2524
|
setupHeartbeat() {
|
|
2614
2525
|
this._heartbeatIntervalId = setInterval(() => {
|
|
2615
2526
|
this._conn?.send?.(JSON.stringify({
|
|
2616
|
-
type:
|
|
2527
|
+
type: "sendToGroup",
|
|
2617
2528
|
group: this.topic,
|
|
2618
2529
|
noEcho: true,
|
|
2619
2530
|
data: { type: "heartbeat" }
|
|
@@ -2635,7 +2546,7 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2635
2546
|
connectionAttempt
|
|
2636
2547
|
});
|
|
2637
2548
|
ws.send(JSON.stringify({
|
|
2638
|
-
type:
|
|
2549
|
+
type: "joinGroup",
|
|
2639
2550
|
group: `${group}.host`
|
|
2640
2551
|
}));
|
|
2641
2552
|
this.server.emitEvent("onWsJoinGroup", {
|
|
@@ -2644,7 +2555,7 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2644
2555
|
});
|
|
2645
2556
|
const handleResync = () => {
|
|
2646
2557
|
ws.send(JSON.stringify({
|
|
2647
|
-
type:
|
|
2558
|
+
type: "sendToGroup",
|
|
2648
2559
|
group,
|
|
2649
2560
|
noEcho: true,
|
|
2650
2561
|
data: { type: "resync" }
|
|
@@ -2671,15 +2582,15 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2671
2582
|
const joinedMessagePayload = handleChunkedMessage(this._chunkedMessages, event.data);
|
|
2672
2583
|
if (event.data.type === "chunk") return;
|
|
2673
2584
|
switch (event.data.t) {
|
|
2674
|
-
case
|
|
2585
|
+
case "init":
|
|
2675
2586
|
this.onClientInit(group, event.data);
|
|
2676
2587
|
this.onClientSync(group, event.data.f, joinedMessagePayload ?? event.data.c);
|
|
2677
2588
|
this.sendInitAwarenessInfo(event.data.f);
|
|
2678
2589
|
return;
|
|
2679
|
-
case
|
|
2590
|
+
case "sync":
|
|
2680
2591
|
this.onClientSync(group, event.data.f, joinedMessagePayload ?? event.data.c);
|
|
2681
2592
|
return;
|
|
2682
|
-
case
|
|
2593
|
+
case "awareness":
|
|
2683
2594
|
this.onAwareness(group, event.data.c);
|
|
2684
2595
|
return;
|
|
2685
2596
|
}
|
|
@@ -2747,27 +2658,24 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2747
2658
|
}
|
|
2748
2659
|
}
|
|
2749
2660
|
simulateWebsocketError() {
|
|
2750
|
-
if (this._conn) this._conn.emit("error", new Error("Simulated connection failure"));
|
|
2661
|
+
if (this._conn) this._conn.emit("error", /* @__PURE__ */ new Error("Simulated connection failure"));
|
|
2751
2662
|
}
|
|
2752
2663
|
safeSend(data) {
|
|
2753
|
-
|
|
2754
|
-
const bytes = new TextEncoder().encode(data);
|
|
2755
|
-
if (bytes.byteLength > MAX_BYTES) return false;
|
|
2664
|
+
if (new TextEncoder().encode(data).byteLength > 524288) return false;
|
|
2756
2665
|
return true;
|
|
2757
2666
|
}
|
|
2758
|
-
chunkString(str, size
|
|
2667
|
+
chunkString(str, size) {
|
|
2759
2668
|
const chunks = [];
|
|
2760
|
-
for (let i = 0; i < str.length; i += size
|
|
2669
|
+
for (let i = 0; i < str.length; i += size) chunks.push(str.slice(i, i + size));
|
|
2761
2670
|
return chunks;
|
|
2762
2671
|
}
|
|
2763
|
-
chunkedBroadcast(group, from
|
|
2672
|
+
chunkedBroadcast(group, from, u8) {
|
|
2764
2673
|
const base64Data = Buffer.from(u8).toString("base64");
|
|
2765
|
-
const
|
|
2766
|
-
const chunks = this.chunkString(base64Data, CHUNK_SIZE);
|
|
2674
|
+
const chunks = this.chunkString(base64Data, 524288);
|
|
2767
2675
|
const payloadId = crypto.randomUUID();
|
|
2768
2676
|
for (let i = 0; i < chunks.length; i++) {
|
|
2769
|
-
const payload
|
|
2770
|
-
type:
|
|
2677
|
+
const payload = JSON.stringify({
|
|
2678
|
+
type: "sendToGroup",
|
|
2771
2679
|
group,
|
|
2772
2680
|
noEcho: true,
|
|
2773
2681
|
data: {
|
|
@@ -2775,37 +2683,37 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2775
2683
|
type: "chunk",
|
|
2776
2684
|
index: i,
|
|
2777
2685
|
totalChunks: chunks.length,
|
|
2778
|
-
f: from
|
|
2686
|
+
f: from,
|
|
2779
2687
|
c: chunks[i]
|
|
2780
2688
|
}
|
|
2781
2689
|
});
|
|
2782
|
-
this._conn?.send?.(payload
|
|
2690
|
+
this._conn?.send?.(payload);
|
|
2783
2691
|
}
|
|
2784
2692
|
const payload = JSON.stringify({
|
|
2785
|
-
type:
|
|
2693
|
+
type: "sendToGroup",
|
|
2786
2694
|
group,
|
|
2787
2695
|
noEcho: true,
|
|
2788
2696
|
data: {
|
|
2789
2697
|
payloadId,
|
|
2790
2698
|
type: "end",
|
|
2791
|
-
f: from
|
|
2699
|
+
f: from
|
|
2792
2700
|
}
|
|
2793
2701
|
});
|
|
2794
2702
|
this._conn?.send?.(payload);
|
|
2795
2703
|
}
|
|
2796
|
-
broadcast(group, from
|
|
2704
|
+
broadcast(group, from, u8) {
|
|
2797
2705
|
try {
|
|
2798
2706
|
const payload = JSON.stringify({
|
|
2799
|
-
type:
|
|
2707
|
+
type: "sendToGroup",
|
|
2800
2708
|
group,
|
|
2801
2709
|
noEcho: true,
|
|
2802
2710
|
data: {
|
|
2803
|
-
f: from
|
|
2711
|
+
f: from,
|
|
2804
2712
|
c: Buffer.from(u8).toString("base64")
|
|
2805
2713
|
}
|
|
2806
2714
|
});
|
|
2807
2715
|
if (!this.safeSend(payload)) {
|
|
2808
|
-
this.chunkedBroadcast(group, from
|
|
2716
|
+
this.chunkedBroadcast(group, from, u8);
|
|
2809
2717
|
return;
|
|
2810
2718
|
}
|
|
2811
2719
|
this._conn?.send?.(payload);
|
|
@@ -2815,12 +2723,11 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2815
2723
|
}
|
|
2816
2724
|
chunkedSend(group, to, u8) {
|
|
2817
2725
|
const base64Data = Buffer.from(u8).toString("base64");
|
|
2818
|
-
const
|
|
2819
|
-
const chunks = this.chunkString(base64Data, CHUNK_SIZE);
|
|
2726
|
+
const chunks = this.chunkString(base64Data, 524288);
|
|
2820
2727
|
const payloadId = crypto.randomUUID();
|
|
2821
2728
|
for (let i = 0; i < chunks.length; i++) {
|
|
2822
|
-
const payload
|
|
2823
|
-
type:
|
|
2729
|
+
const payload = JSON.stringify({
|
|
2730
|
+
type: "sendToGroup",
|
|
2824
2731
|
group,
|
|
2825
2732
|
noEcho: true,
|
|
2826
2733
|
data: {
|
|
@@ -2832,10 +2739,10 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2832
2739
|
c: chunks[i]
|
|
2833
2740
|
}
|
|
2834
2741
|
});
|
|
2835
|
-
this._conn?.send?.(payload
|
|
2742
|
+
this._conn?.send?.(payload);
|
|
2836
2743
|
}
|
|
2837
2744
|
const payload = JSON.stringify({
|
|
2838
|
-
type:
|
|
2745
|
+
type: "sendToGroup",
|
|
2839
2746
|
group,
|
|
2840
2747
|
noEcho: true,
|
|
2841
2748
|
data: {
|
|
@@ -2849,7 +2756,7 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2849
2756
|
send(group, to, u8) {
|
|
2850
2757
|
try {
|
|
2851
2758
|
const payload = JSON.stringify({
|
|
2852
|
-
type:
|
|
2759
|
+
type: "sendToGroup",
|
|
2853
2760
|
group,
|
|
2854
2761
|
noEcho: true,
|
|
2855
2762
|
data: {
|
|
@@ -2869,24 +2776,22 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2869
2776
|
async onClientInit(group, data) {
|
|
2870
2777
|
if (!this.doc) return;
|
|
2871
2778
|
const encoder = createEncoder();
|
|
2872
|
-
writeVarUint(encoder,
|
|
2779
|
+
writeVarUint(encoder, 0);
|
|
2873
2780
|
writeSyncStep1(encoder, this.doc);
|
|
2874
2781
|
const u8 = toUint8Array(encoder);
|
|
2875
2782
|
this.send(group, data.f, u8);
|
|
2876
2783
|
}
|
|
2877
|
-
onClientSync(group, from
|
|
2784
|
+
onClientSync(group, from, data) {
|
|
2878
2785
|
try {
|
|
2879
2786
|
if (!this.doc) return;
|
|
2880
2787
|
const buf = Buffer.from(data, "base64");
|
|
2881
2788
|
const encoder = createEncoder();
|
|
2882
2789
|
const decoder = createDecoder(buf);
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
if (length(encoder) > 1) this.send(group, from$1, toUint8Array(encoder));
|
|
2889
|
-
break;
|
|
2790
|
+
switch (readVarUint(decoder)) {
|
|
2791
|
+
case 0:
|
|
2792
|
+
writeVarUint(encoder, 0);
|
|
2793
|
+
readSyncMessage(decoder, encoder, this.doc, from);
|
|
2794
|
+
if (length(encoder) > 1) this.send(group, from, toUint8Array(encoder));
|
|
2890
2795
|
}
|
|
2891
2796
|
} catch (err) {
|
|
2892
2797
|
this.doc.emit("error", [err]);
|
|
@@ -2910,36 +2815,37 @@ var WeaveStoreAzureWebPubSubSyncHost = class {
|
|
|
2910
2815
|
`webpubsub.joinLeaveGroup.${group}`,
|
|
2911
2816
|
`webpubsub.joinLeaveGroup.${group}.host`
|
|
2912
2817
|
];
|
|
2913
|
-
|
|
2818
|
+
return await this._client.getClientAccessToken({
|
|
2914
2819
|
expirationTimeInMinutes,
|
|
2915
2820
|
userId: HostUserId,
|
|
2916
2821
|
roles
|
|
2917
2822
|
});
|
|
2918
|
-
return res;
|
|
2919
2823
|
}
|
|
2920
2824
|
};
|
|
2921
|
-
|
|
2922
2825
|
//#endregion
|
|
2923
2826
|
//#region src/server/utils.ts
|
|
2924
2827
|
function getStateAsJson(actualState) {
|
|
2925
2828
|
const document = new yjs_default.Doc();
|
|
2926
2829
|
yjs_default.applyUpdate(document, actualState);
|
|
2927
2830
|
const actualStateString = JSON.stringify(document.getMap("weave").toJSON());
|
|
2928
|
-
|
|
2929
|
-
return actualStateJson;
|
|
2831
|
+
return JSON.parse(actualStateString);
|
|
2930
2832
|
}
|
|
2931
2833
|
function hashJson(obj) {
|
|
2932
2834
|
const jsonString = JSON.stringify(obj);
|
|
2933
2835
|
return crypto.createHash("sha256").update(jsonString).digest("hex");
|
|
2934
2836
|
}
|
|
2935
|
-
|
|
2936
2837
|
//#endregion
|
|
2937
2838
|
//#region src/server/azure-web-pubsub-sync-handler.ts
|
|
2938
2839
|
var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2840
|
+
_client;
|
|
2841
|
+
_rooms = /* @__PURE__ */ new Map();
|
|
2842
|
+
_roomsSyncHost = /* @__PURE__ */ new Map();
|
|
2843
|
+
_store_persistence = /* @__PURE__ */ new Map();
|
|
2844
|
+
syncHostOptions;
|
|
2845
|
+
syncOptions;
|
|
2846
|
+
initialState;
|
|
2847
|
+
server;
|
|
2848
|
+
roomsLastState = /* @__PURE__ */ new Map();
|
|
2943
2849
|
constructor(hub, server, client, initialState, syncHandlerOptions, eventHandlerOptions, syncHostOptions) {
|
|
2944
2850
|
super(hub, {
|
|
2945
2851
|
...eventHandlerOptions,
|
|
@@ -2977,8 +2883,7 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
2977
2883
|
if (documentData) yjs_default.applyUpdate(doc, documentData);
|
|
2978
2884
|
else this.initialState(doc);
|
|
2979
2885
|
this._roomsSyncHost.set(roomId, new WeaveStoreAzureWebPubSubSyncHost(this.server, this, this._client, roomId, doc, this.syncHostOptions));
|
|
2980
|
-
|
|
2981
|
-
await connection.start();
|
|
2886
|
+
await this._roomsSyncHost.get(roomId).start();
|
|
2982
2887
|
if (this.isPersistingOnInterval()) this.setupRoomInstancePersistence(roomId);
|
|
2983
2888
|
this._rooms.set(roomId, doc);
|
|
2984
2889
|
}
|
|
@@ -3001,12 +2906,7 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
3001
2906
|
if (!this.isPersistingOnInterval()) {
|
|
3002
2907
|
const savedRoomData = this.roomsLastState.get(roomId);
|
|
3003
2908
|
if (savedRoomData) {
|
|
3004
|
-
|
|
3005
|
-
const savedHash = hashJson(savedStateJson);
|
|
3006
|
-
const actualStateJson = getStateAsJson(actualState);
|
|
3007
|
-
const actualHash = hashJson(actualStateJson);
|
|
3008
|
-
const same = savedHash === actualHash;
|
|
3009
|
-
if (same) return;
|
|
2909
|
+
if (hashJson(getStateAsJson(savedRoomData)) === hashJson(getStateAsJson(actualState))) return;
|
|
3010
2910
|
this.roomsLastState.set(roomId, actualState);
|
|
3011
2911
|
}
|
|
3012
2912
|
}
|
|
@@ -3053,17 +2953,14 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
3053
2953
|
}
|
|
3054
2954
|
async clientConnect(roomId, connectionOptions) {
|
|
3055
2955
|
await this.getHostConnection(roomId);
|
|
3056
|
-
|
|
2956
|
+
return `${(await this._client.getClientAccessToken({
|
|
3057
2957
|
groups: [roomId],
|
|
3058
2958
|
roles: [`webpubsub.joinLeaveGroup.${roomId}`, `webpubsub.sendToGroup.${roomId}.host`],
|
|
3059
2959
|
...connectionOptions
|
|
3060
|
-
})
|
|
3061
|
-
const finalURL = `${token.url}&group=${roomId}`;
|
|
3062
|
-
return finalURL;
|
|
2960
|
+
})).url}&group=${roomId}`;
|
|
3063
2961
|
}
|
|
3064
2962
|
async clientDisconnect(roomId) {
|
|
3065
|
-
|
|
3066
|
-
if (roomSyncHost) await this.destroyRoomInstance(roomId);
|
|
2963
|
+
if (this._roomsSyncHost.get(roomId)) await this.destroyRoomInstance(roomId);
|
|
3067
2964
|
}
|
|
3068
2965
|
async clientTransportConnect(roomId) {
|
|
3069
2966
|
const roomSyncHost = this._roomsSyncHost.get(roomId);
|
|
@@ -3074,10 +2971,11 @@ var WeaveAzureWebPubsubSyncHandler = class extends WebPubSubEventHandler {
|
|
|
3074
2971
|
if (roomSyncHost) roomSyncHost.stop();
|
|
3075
2972
|
}
|
|
3076
2973
|
};
|
|
3077
|
-
|
|
3078
2974
|
//#endregion
|
|
3079
2975
|
//#region src/server/azure-web-pubsub-server.ts
|
|
3080
2976
|
var WeaveAzureWebPubsubServer = class extends Emittery {
|
|
2977
|
+
syncClient;
|
|
2978
|
+
syncHandler;
|
|
3081
2979
|
persistRoom = void 0;
|
|
3082
2980
|
fetchRoom = void 0;
|
|
3083
2981
|
constructor({ pubSubConfig, eventsHandlerConfig, initialState = defaultInitialState, persistRoom, fetchRoom, syncHostConfig }) {
|
|
@@ -3131,6 +3029,5 @@ var WeaveAzureWebPubsubServer = class extends Emittery {
|
|
|
3131
3029
|
this.syncHandler.clientTransportDisconnect(roomId);
|
|
3132
3030
|
}
|
|
3133
3031
|
};
|
|
3134
|
-
|
|
3135
3032
|
//#endregion
|
|
3136
|
-
export { MessageDataType, MessageType, MqttDisconnectReasonCode, MqttV311ConnectReturnCode, MqttV500ConnectReasonCode, WEAVE_STORE_AZURE_WEB_PUBSUB, WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS, WEAVE_STORE_AZURE_WEB_PUBSUB_DESTROY_ROOM_STATUS, WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_CLIENT_DEFAULT_OPTIONS, WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_HOST_DEFAULT_OPTIONS, WEAVE_STORE_HORIZONTAL_SYNC_HANDLER_CLIENT_TYPE, WeaveAzureWebPubsubServer, WeaveStoreAzureWebPubSubSyncHost, WebPubSubEventHandler };
|
|
3033
|
+
export { MessageDataType, MessageType, MqttDisconnectReasonCode, MqttV311ConnectReturnCode, MqttV500ConnectReasonCode, WEAVE_STORE_AZURE_WEB_PUBSUB, WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS, WEAVE_STORE_AZURE_WEB_PUBSUB_DESTROY_ROOM_STATUS, WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_CLIENT_DEFAULT_OPTIONS, WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_HOST_DEFAULT_OPTIONS, WEAVE_STORE_HORIZONTAL_SYNC_HANDLER_CLIENT_TYPE, WeaveAzureWebPubsubServer, WeaveStoreAzureWebPubSubSyncHost, WebPubSubEventHandler };
|