@everymatrix/nuts-inbox-widget 1.98.18 → 1.98.19

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/hydrate/index.js CHANGED
@@ -3745,39 +3745,29 @@ if (withEventListeners) {
3745
3745
  }
3746
3746
  /**
3747
3747
  * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
3748
- * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
3748
+ * with one of the available low-level transports, like HTTP long-polling, WebSocket, or WebTransport.
3749
3749
  *
3750
- * This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
3751
- * successfully establishes the connection.
3752
- *
3753
- * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
3750
+ * This class comes with an upgrade mechanism, which means that once the connection is established with the first
3751
+ * low-level transport, it will try to upgrade to a better transport.
3754
3752
  *
3755
3753
  * @example
3756
- * import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
3754
+ * import { Socket } from "engine.io-client";
3757
3755
  *
3758
- * const socket = new SocketWithoutUpgrade({
3759
- * transports: [WebSocket]
3760
- * });
3756
+ * const socket = new Socket();
3761
3757
  *
3762
3758
  * socket.on("open", () => {
3763
3759
  * socket.send("hello");
3764
3760
  * });
3765
3761
  *
3766
- * @see SocketWithUpgrade
3767
- * @see Socket
3768
3762
  */
3769
- class SocketWithoutUpgrade extends Emitter {
3770
- /**
3771
- * Socket constructor.
3772
- *
3773
- * @param {String|Object} uri - uri or options
3774
- * @param {Object} opts - options
3775
- */
3776
- constructor(uri, opts) {
3763
+ class Socket$1 extends Emitter {
3764
+ constructor(uri, opts = {}) {
3765
+ var _a, _b;
3777
3766
  super();
3778
3767
  this.binaryType = defaultBinaryType;
3779
3768
  this.writeBuffer = [];
3780
3769
  this._prevBufferLen = 0;
3770
+ this._upgrades = [];
3781
3771
  this._pingInterval = -1;
3782
3772
  this._pingTimeout = -1;
3783
3773
  this._maxPayload = -1;
@@ -3821,13 +3811,26 @@ class SocketWithoutUpgrade extends Emitter {
3821
3811
  : this.secure
3822
3812
  ? "443"
3823
3813
  : "80");
3824
- this.transports = [];
3825
- this._transportsByName = {};
3826
- opts.transports.forEach((t) => {
3827
- const transportName = t.prototype.name;
3828
- this.transports.push(transportName);
3829
- this._transportsByName[transportName] = t;
3830
- });
3814
+ if (opts.transportImplementations && opts.transports) {
3815
+ throw new Error("specifying both 'transportImplementations' and 'transports' options is not supported");
3816
+ }
3817
+ if (opts.transportImplementations ||
3818
+ (((_a = opts.transports) === null || _a === void 0 ? void 0 : _a.length) && typeof opts.transports[0] === "function")) {
3819
+ // 'transports' option as an array of transport implementations is kept for backward compatibility
3820
+ this.transports = [];
3821
+ this._transportsByName = Object.create(null);
3822
+ ((_b = opts.transportImplementations) !== null && _b !== void 0 ? _b : opts.transports).forEach((t) => {
3823
+ const transportName = t.prototype.name;
3824
+ this.transports.push(transportName);
3825
+ this._transportsByName[transportName] = t;
3826
+ });
3827
+ }
3828
+ else {
3829
+ this.transports = opts.transports
3830
+ ? [...opts.transports]
3831
+ : ["polling", "websocket", "webtransport"];
3832
+ this._transportsByName = transports;
3833
+ }
3831
3834
  this.opts = Object.assign({
3832
3835
  path: "/engine.io",
3833
3836
  agent: false,
@@ -3916,7 +3919,7 @@ class SocketWithoutUpgrade extends Emitter {
3916
3919
  return;
3917
3920
  }
3918
3921
  const transportName = this.opts.rememberUpgrade &&
3919
- SocketWithoutUpgrade.priorWebsocketSuccess &&
3922
+ Socket$1.priorWebsocketSuccess &&
3920
3923
  this.transports.indexOf("websocket") !== -1
3921
3924
  ? "websocket"
3922
3925
  : this.transports[0];
@@ -3943,6 +3946,107 @@ class SocketWithoutUpgrade extends Emitter {
3943
3946
  .on("error", this._onError.bind(this))
3944
3947
  .on("close", (reason) => this._onClose("transport close", reason));
3945
3948
  }
3949
+ /**
3950
+ * Probes a transport.
3951
+ *
3952
+ * @param {String} name - transport name
3953
+ * @private
3954
+ */
3955
+ _probe(name) {
3956
+ let transport = this.createTransport(name);
3957
+ let failed = false;
3958
+ Socket$1.priorWebsocketSuccess = false;
3959
+ const onTransportOpen = () => {
3960
+ if (failed)
3961
+ return;
3962
+ transport.send([{ type: "ping", data: "probe" }]);
3963
+ transport.once("packet", (msg) => {
3964
+ if (failed)
3965
+ return;
3966
+ if ("pong" === msg.type && "probe" === msg.data) {
3967
+ this.upgrading = true;
3968
+ this.emitReserved("upgrading", transport);
3969
+ if (!transport)
3970
+ return;
3971
+ Socket$1.priorWebsocketSuccess = "websocket" === transport.name;
3972
+ this.transport.pause(() => {
3973
+ if (failed)
3974
+ return;
3975
+ if ("closed" === this.readyState)
3976
+ return;
3977
+ cleanup();
3978
+ this.setTransport(transport);
3979
+ transport.send([{ type: "upgrade" }]);
3980
+ this.emitReserved("upgrade", transport);
3981
+ transport = null;
3982
+ this.upgrading = false;
3983
+ this.flush();
3984
+ });
3985
+ }
3986
+ else {
3987
+ const err = new Error("probe error");
3988
+ // @ts-ignore
3989
+ err.transport = transport.name;
3990
+ this.emitReserved("upgradeError", err);
3991
+ }
3992
+ });
3993
+ };
3994
+ function freezeTransport() {
3995
+ if (failed)
3996
+ return;
3997
+ // Any callback called by transport should be ignored since now
3998
+ failed = true;
3999
+ cleanup();
4000
+ transport.close();
4001
+ transport = null;
4002
+ }
4003
+ // Handle any error that happens while probing
4004
+ const onerror = (err) => {
4005
+ const error = new Error("probe error: " + err);
4006
+ // @ts-ignore
4007
+ error.transport = transport.name;
4008
+ freezeTransport();
4009
+ this.emitReserved("upgradeError", error);
4010
+ };
4011
+ function onTransportClose() {
4012
+ onerror("transport closed");
4013
+ }
4014
+ // When the socket is closed while we're probing
4015
+ function onclose() {
4016
+ onerror("socket closed");
4017
+ }
4018
+ // When the socket is upgraded while we're probing
4019
+ function onupgrade(to) {
4020
+ if (transport && to.name !== transport.name) {
4021
+ freezeTransport();
4022
+ }
4023
+ }
4024
+ // Remove all listeners on the transport and on self
4025
+ const cleanup = () => {
4026
+ transport.removeListener("open", onTransportOpen);
4027
+ transport.removeListener("error", onerror);
4028
+ transport.removeListener("close", onTransportClose);
4029
+ this.off("close", onclose);
4030
+ this.off("upgrading", onupgrade);
4031
+ };
4032
+ transport.once("open", onTransportOpen);
4033
+ transport.once("error", onerror);
4034
+ transport.once("close", onTransportClose);
4035
+ this.once("close", onclose);
4036
+ this.once("upgrading", onupgrade);
4037
+ if (this._upgrades.indexOf("webtransport") !== -1 &&
4038
+ name !== "webtransport") {
4039
+ // favor WebTransport
4040
+ this.setTimeoutFn(() => {
4041
+ if (!failed) {
4042
+ transport.open();
4043
+ }
4044
+ }, 200);
4045
+ }
4046
+ else {
4047
+ transport.open();
4048
+ }
4049
+ }
3946
4050
  /**
3947
4051
  * Called when connection is deemed open.
3948
4052
  *
@@ -3950,10 +4054,14 @@ class SocketWithoutUpgrade extends Emitter {
3950
4054
  */
3951
4055
  onOpen() {
3952
4056
  this.readyState = "open";
3953
- SocketWithoutUpgrade.priorWebsocketSuccess =
3954
- "websocket" === this.transport.name;
4057
+ Socket$1.priorWebsocketSuccess = "websocket" === this.transport.name;
3955
4058
  this.emitReserved("open");
3956
4059
  this.flush();
4060
+ if ("open" === this.readyState && this.opts.upgrade) {
4061
+ for (let i = 0; i < this._upgrades.length; i++) {
4062
+ this._probe(this._upgrades[i]);
4063
+ }
4064
+ }
3957
4065
  }
3958
4066
  /**
3959
4067
  * Handles a packet.
@@ -4000,6 +4108,7 @@ class SocketWithoutUpgrade extends Emitter {
4000
4108
  this.emitReserved("handshake", data);
4001
4109
  this.id = data.sid;
4002
4110
  this.transport.query.sid = data.sid;
4111
+ this._upgrades = this._filterUpgrades(data.upgrades);
4003
4112
  this._pingInterval = data.pingInterval;
4004
4113
  this._pingTimeout = data.pingTimeout;
4005
4114
  this._maxPayload = data.maxPayload;
@@ -4211,7 +4320,7 @@ class SocketWithoutUpgrade extends Emitter {
4211
4320
  * @private
4212
4321
  */
4213
4322
  _onError(err) {
4214
- SocketWithoutUpgrade.priorWebsocketSuccess = false;
4323
+ Socket$1.priorWebsocketSuccess = false;
4215
4324
  if (this.opts.tryAllTransports &&
4216
4325
  this.transports.length > 1 &&
4217
4326
  this.readyState === "opening") {
@@ -4261,150 +4370,6 @@ class SocketWithoutUpgrade extends Emitter {
4261
4370
  this._prevBufferLen = 0;
4262
4371
  }
4263
4372
  }
4264
- }
4265
- SocketWithoutUpgrade.protocol = protocol$1;
4266
- /**
4267
- * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
4268
- * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
4269
- *
4270
- * This class comes with an upgrade mechanism, which means that once the connection is established with the first
4271
- * low-level transport, it will try to upgrade to a better transport.
4272
- *
4273
- * In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
4274
- *
4275
- * @example
4276
- * import { SocketWithUpgrade, WebSocket } from "engine.io-client";
4277
- *
4278
- * const socket = new SocketWithUpgrade({
4279
- * transports: [WebSocket]
4280
- * });
4281
- *
4282
- * socket.on("open", () => {
4283
- * socket.send("hello");
4284
- * });
4285
- *
4286
- * @see SocketWithoutUpgrade
4287
- * @see Socket
4288
- */
4289
- class SocketWithUpgrade extends SocketWithoutUpgrade {
4290
- constructor() {
4291
- super(...arguments);
4292
- this._upgrades = [];
4293
- }
4294
- onOpen() {
4295
- super.onOpen();
4296
- if ("open" === this.readyState && this.opts.upgrade) {
4297
- for (let i = 0; i < this._upgrades.length; i++) {
4298
- this._probe(this._upgrades[i]);
4299
- }
4300
- }
4301
- }
4302
- /**
4303
- * Probes a transport.
4304
- *
4305
- * @param {String} name - transport name
4306
- * @private
4307
- */
4308
- _probe(name) {
4309
- let transport = this.createTransport(name);
4310
- let failed = false;
4311
- SocketWithoutUpgrade.priorWebsocketSuccess = false;
4312
- const onTransportOpen = () => {
4313
- if (failed)
4314
- return;
4315
- transport.send([{ type: "ping", data: "probe" }]);
4316
- transport.once("packet", (msg) => {
4317
- if (failed)
4318
- return;
4319
- if ("pong" === msg.type && "probe" === msg.data) {
4320
- this.upgrading = true;
4321
- this.emitReserved("upgrading", transport);
4322
- if (!transport)
4323
- return;
4324
- SocketWithoutUpgrade.priorWebsocketSuccess =
4325
- "websocket" === transport.name;
4326
- this.transport.pause(() => {
4327
- if (failed)
4328
- return;
4329
- if ("closed" === this.readyState)
4330
- return;
4331
- cleanup();
4332
- this.setTransport(transport);
4333
- transport.send([{ type: "upgrade" }]);
4334
- this.emitReserved("upgrade", transport);
4335
- transport = null;
4336
- this.upgrading = false;
4337
- this.flush();
4338
- });
4339
- }
4340
- else {
4341
- const err = new Error("probe error");
4342
- // @ts-ignore
4343
- err.transport = transport.name;
4344
- this.emitReserved("upgradeError", err);
4345
- }
4346
- });
4347
- };
4348
- function freezeTransport() {
4349
- if (failed)
4350
- return;
4351
- // Any callback called by transport should be ignored since now
4352
- failed = true;
4353
- cleanup();
4354
- transport.close();
4355
- transport = null;
4356
- }
4357
- // Handle any error that happens while probing
4358
- const onerror = (err) => {
4359
- const error = new Error("probe error: " + err);
4360
- // @ts-ignore
4361
- error.transport = transport.name;
4362
- freezeTransport();
4363
- this.emitReserved("upgradeError", error);
4364
- };
4365
- function onTransportClose() {
4366
- onerror("transport closed");
4367
- }
4368
- // When the socket is closed while we're probing
4369
- function onclose() {
4370
- onerror("socket closed");
4371
- }
4372
- // When the socket is upgraded while we're probing
4373
- function onupgrade(to) {
4374
- if (transport && to.name !== transport.name) {
4375
- freezeTransport();
4376
- }
4377
- }
4378
- // Remove all listeners on the transport and on self
4379
- const cleanup = () => {
4380
- transport.removeListener("open", onTransportOpen);
4381
- transport.removeListener("error", onerror);
4382
- transport.removeListener("close", onTransportClose);
4383
- this.off("close", onclose);
4384
- this.off("upgrading", onupgrade);
4385
- };
4386
- transport.once("open", onTransportOpen);
4387
- transport.once("error", onerror);
4388
- transport.once("close", onTransportClose);
4389
- this.once("close", onclose);
4390
- this.once("upgrading", onupgrade);
4391
- if (this._upgrades.indexOf("webtransport") !== -1 &&
4392
- name !== "webtransport") {
4393
- // favor WebTransport
4394
- this.setTimeoutFn(() => {
4395
- if (!failed) {
4396
- transport.open();
4397
- }
4398
- }, 200);
4399
- }
4400
- else {
4401
- transport.open();
4402
- }
4403
- }
4404
- onHandshake(data) {
4405
- this._upgrades = this._filterUpgrades(data.upgrades);
4406
- super.onHandshake(data);
4407
- }
4408
4373
  /**
4409
4374
  * Filters upgrades, returning only those matching client transports.
4410
4375
  *
@@ -4420,38 +4385,7 @@ class SocketWithUpgrade extends SocketWithoutUpgrade {
4420
4385
  return filteredUpgrades;
4421
4386
  }
4422
4387
  }
4423
- /**
4424
- * This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
4425
- * with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
4426
- *
4427
- * This class comes with an upgrade mechanism, which means that once the connection is established with the first
4428
- * low-level transport, it will try to upgrade to a better transport.
4429
- *
4430
- * @example
4431
- * import { Socket } from "engine.io-client";
4432
- *
4433
- * const socket = new Socket();
4434
- *
4435
- * socket.on("open", () => {
4436
- * socket.send("hello");
4437
- * });
4438
- *
4439
- * @see SocketWithoutUpgrade
4440
- * @see SocketWithUpgrade
4441
- */
4442
- class Socket$1 extends SocketWithUpgrade {
4443
- constructor(uri, opts = {}) {
4444
- const isOptionsOnly = typeof uri === "object";
4445
- const o = isOptionsOnly ? { ...uri } : { ...opts };
4446
- if (!o.transports ||
4447
- (o.transports && typeof o.transports[0] === "string")) {
4448
- o.transports = (o.transports || ["polling", "websocket", "webtransport"])
4449
- .map((transportName) => transports[transportName])
4450
- .filter((t) => !!t);
4451
- }
4452
- super(isOptionsOnly ? o : uri, o);
4453
- }
4454
- }
4388
+ Socket$1.protocol = protocol$1;
4455
4389
 
4456
4390
  /**
4457
4391
  * URL parser.