@everymatrix/nuts-inbox-widget 1.98.18 → 1.98.20

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