@realsee/live 0.6.8-dev.5 → 0.6.8-dev.6
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/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +13 -30
- package/dist/index.es.js.map +1 -1
- package/dist/utils/RobustWebSocket.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -633,7 +633,7 @@ class mr extends ue {
|
|
|
633
633
|
timeout: 1e4,
|
|
634
634
|
shouldReconnect: (e, i) => {
|
|
635
635
|
if (!(e.code === 1008 || e.code === 1011))
|
|
636
|
-
return [
|
|
636
|
+
return [1e3, 3e3, 6e3][i.attempts % 3];
|
|
637
637
|
},
|
|
638
638
|
should1000Reconnect: !1,
|
|
639
639
|
ignoreConnectivityEvents: !1,
|
|
@@ -653,6 +653,12 @@ class mr extends ue {
|
|
|
653
653
|
o(this, "_healthCheck", async () => {
|
|
654
654
|
this._realWebSocket && this._realWebSocket.readyState !== this._readyState && (this._readyState = this._realWebSocket.readyState, this._readyState === Le.CLOSING && this.emit("closing")), await new Promise((e) => setTimeout(e, 2e3)), this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
|
|
655
655
|
});
|
|
656
|
+
/**
|
|
657
|
+
* 清理超时计时器
|
|
658
|
+
*/
|
|
659
|
+
o(this, "_clearConnectTimeoutIfNeed", () => {
|
|
660
|
+
this._connectTimeout && (clearTimeout(this._connectTimeout), this._connectTimeout = void 0);
|
|
661
|
+
});
|
|
656
662
|
/**
|
|
657
663
|
* 清理健康检查
|
|
658
664
|
*/
|
|
@@ -737,7 +743,7 @@ class mr extends ue {
|
|
|
737
743
|
const e = typeof this._url == "string" ? this._url : (n = this._url) == null ? void 0 : n.call(this, this);
|
|
738
744
|
if (!e)
|
|
739
745
|
return;
|
|
740
|
-
this.
|
|
746
|
+
this._clearConnectTimeoutIfNeed(), this._clearPendingReconnectIfNeeded(), this._removeWebSocketEvent(), this._realWebSocket = new WebSocket(e, this._protocols || void 0), this._attempts = this._attempts + 1, this.emit(
|
|
741
747
|
"connecting",
|
|
742
748
|
new CustomEvent("connecting", {
|
|
743
749
|
detail: { attempts: this._attempts, reconnects: this._reconnects }
|
|
@@ -761,29 +767,14 @@ class mr extends ue {
|
|
|
761
767
|
*/
|
|
762
768
|
o(this, "_removeWebSocketEvent", () => {
|
|
763
769
|
var e, i, n, c;
|
|
764
|
-
(e = this._realWebSocket) == null || e.removeEventListener(
|
|
765
|
-
"open",
|
|
766
|
-
this._webSocketOpenHandler
|
|
767
|
-
), (i = this._realWebSocket) == null || i.removeEventListener(
|
|
768
|
-
"close",
|
|
769
|
-
this._webSocketCloseHandler
|
|
770
|
-
), (n = this._realWebSocket) == null || n.removeEventListener(
|
|
771
|
-
"error",
|
|
772
|
-
this._webSocketErrorHandler
|
|
773
|
-
), (c = this._realWebSocket) == null || c.removeEventListener(
|
|
774
|
-
"message",
|
|
775
|
-
this._webSocketMessageHandler
|
|
776
|
-
);
|
|
770
|
+
(e = this._realWebSocket) == null || e.removeEventListener("open", this._webSocketOpenHandler), (i = this._realWebSocket) == null || i.removeEventListener("close", this._webSocketCloseHandler), (n = this._realWebSocket) == null || n.removeEventListener("error", this._webSocketErrorHandler), (c = this._realWebSocket) == null || c.removeEventListener("message", this._webSocketMessageHandler);
|
|
777
771
|
});
|
|
778
772
|
/**
|
|
779
773
|
* 分发ws事件
|
|
780
774
|
*/
|
|
781
775
|
o(this, "_dispatchWebSocketEvent", () => {
|
|
782
776
|
var e, i, n, c;
|
|
783
|
-
(e = this._realWebSocket) == null || e.addEventListener("open", this._webSocketOpenHandler), (i = this._realWebSocket) == null || i.addEventListener("close", this._webSocketCloseHandler), (n = this._realWebSocket) == null || n.addEventListener("error", this._webSocketErrorHandler), (c = this._realWebSocket) == null || c.addEventListener(
|
|
784
|
-
"message",
|
|
785
|
-
this._webSocketMessageHandler
|
|
786
|
-
);
|
|
777
|
+
(e = this._realWebSocket) == null || e.addEventListener("open", this._webSocketOpenHandler), (i = this._realWebSocket) == null || i.addEventListener("close", this._webSocketCloseHandler), (n = this._realWebSocket) == null || n.addEventListener("error", this._webSocketErrorHandler), (c = this._realWebSocket) == null || c.addEventListener("message", this._webSocketMessageHandler);
|
|
787
778
|
});
|
|
788
779
|
/**
|
|
789
780
|
* ws连接事件
|
|
@@ -792,10 +783,7 @@ class mr extends ue {
|
|
|
792
783
|
o(this, "_webSocketOpenHandler", (e) => {
|
|
793
784
|
this._connectTimeout && (clearTimeout(this._connectTimeout), this._connectTimeout = void 0);
|
|
794
785
|
const i = ++this._reconnects, n = this._attempts;
|
|
795
|
-
return this._attempts = 0, this._reconnectWhenOnlineAgain = !1, this._startHealthCheck(), this.emit(
|
|
796
|
-
"open",
|
|
797
|
-
Object.assign(e, { detail: { reconnects: i, attempts: n } })
|
|
798
|
-
);
|
|
786
|
+
return this._attempts = 0, this._reconnectWhenOnlineAgain = !1, this._startHealthCheck(), this.emit("open", Object.assign(e, { detail: { reconnects: i, attempts: n } }));
|
|
799
787
|
});
|
|
800
788
|
/**
|
|
801
789
|
* ws 关闭事件
|
|
@@ -808,10 +796,7 @@ class mr extends ue {
|
|
|
808
796
|
* @param event
|
|
809
797
|
* @returns
|
|
810
798
|
*/
|
|
811
|
-
o(this, "_webSocketErrorHandler", (e) => this.emit(
|
|
812
|
-
"error",
|
|
813
|
-
new CustomEvent("error", { detail: { error: e } })
|
|
814
|
-
));
|
|
799
|
+
o(this, "_webSocketErrorHandler", (e) => this.emit("error", new CustomEvent("error", { detail: { error: e } })));
|
|
815
800
|
/**
|
|
816
801
|
* ws消息
|
|
817
802
|
* @param event
|
|
@@ -829,9 +814,7 @@ class mr extends ue {
|
|
|
829
814
|
this._url = e.url, this._protocols = e.protocols;
|
|
830
815
|
const i = Object.assign(this._options, e.robustOptions || {});
|
|
831
816
|
if (typeof (i == null ? void 0 : i.timeout) != "number")
|
|
832
|
-
throw new Error(
|
|
833
|
-
"timeout must be the number of milliseconds to timeout a connection attempt"
|
|
834
|
-
);
|
|
817
|
+
throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");
|
|
835
818
|
if (typeof (i == null ? void 0 : i.shouldReconnect) != "function")
|
|
836
819
|
throw new Error(
|
|
837
820
|
"shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect."
|