@realsee/live 0.6.8-dev.1 → 0.6.8-dev.3

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.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 [3e3, 6e3, 1e4][i.attempts % 3];
636
+ return [0, 3e3, 1e4][i.attempts % 3];
637
637
  },
638
638
  should1000Reconnect: !1,
639
639
  ignoreConnectivityEvents: !1,
@@ -737,7 +737,7 @@ class mr extends ue {
737
737
  const e = typeof this._url == "string" ? this._url : (n = this._url) == null ? void 0 : n.call(this, this);
738
738
  if (!e)
739
739
  return;
740
- this._clearPendingReconnectIfNeeded(), this._removeWebSocketEvent(), this._realWebSocket = new WebSocket(e, this._protocols || void 0), this._attempts = this._attempts + 1, this.emit(
740
+ this._pendingReconnect = void 0, this._removeWebSocketEvent(), this._realWebSocket = new WebSocket(e, this._protocols || void 0), this._attempts = this._attempts + 1, this.emit(
741
741
  "connecting",
742
742
  new CustomEvent("connecting", {
743
743
  detail: { attempts: this._attempts, reconnects: this._reconnects }
@@ -746,13 +746,13 @@ class mr extends ue {
746
746
  const i = () => {
747
747
  this._connectTimeout = void 0, this._detachConnectivityEvents(), this.emit(
748
748
  "timeout",
749
- new CustomEvent("timeout", {
749
+ new CustomEvent("connecting", {
750
750
  detail: {
751
751
  attempts: this._attempts,
752
752
  reconnects: this._reconnects
753
753
  }
754
754
  })
755
- ), this.open(this._url);
755
+ );
756
756
  };
757
757
  this._connectTimeout = setTimeout(i, (c = this._options) == null ? void 0 : c.timeout), this._dispatchWebSocketEvent(), (u = this._options) != null && u.ignoreConnectivityEvents || this._attachConnectivityEvents();
758
758
  });
@@ -761,23 +761,41 @@ class mr extends ue {
761
761
  */
762
762
  o(this, "_removeWebSocketEvent", () => {
763
763
  var e, i, n, c;
764
- (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);
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
+ );
765
777
  });
766
778
  /**
767
779
  * 分发ws事件
768
780
  */
769
781
  o(this, "_dispatchWebSocketEvent", () => {
770
782
  var e, i, n, c;
771
- (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);
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
+ );
772
787
  });
773
788
  /**
774
789
  * ws连接事件
775
790
  * @returns
776
791
  */
777
792
  o(this, "_webSocketOpenHandler", (e) => {
778
- this._clearPendingReconnectIfNeeded(), this._connectTimeout && (clearTimeout(this._connectTimeout), this._connectTimeout = void 0);
793
+ this._connectTimeout && (clearTimeout(this._connectTimeout), this._connectTimeout = void 0);
779
794
  const i = ++this._reconnects, n = this._attempts;
780
- return this._attempts = 0, this._reconnectWhenOnlineAgain = !1, this._startHealthCheck(), this.emit("open", Object.assign(e, { detail: { reconnects: i, attempts: n } }));
795
+ return this._attempts = 0, this._reconnectWhenOnlineAgain = !1, this._startHealthCheck(), this.emit(
796
+ "open",
797
+ Object.assign(e, { detail: { reconnects: i, attempts: n } })
798
+ );
781
799
  });
782
800
  /**
783
801
  * ws 关闭事件
@@ -790,7 +808,10 @@ class mr extends ue {
790
808
  * @param event
791
809
  * @returns
792
810
  */
793
- o(this, "_webSocketErrorHandler", (e) => this.emit("error", new CustomEvent("error", { detail: { error: e } })));
811
+ o(this, "_webSocketErrorHandler", (e) => this.emit(
812
+ "error",
813
+ new CustomEvent("error", { detail: { error: e } })
814
+ ));
794
815
  /**
795
816
  * ws消息
796
817
  * @param event
@@ -808,7 +829,9 @@ class mr extends ue {
808
829
  this._url = e.url, this._protocols = e.protocols;
809
830
  const i = Object.assign(this._options, e.robustOptions || {});
810
831
  if (typeof (i == null ? void 0 : i.timeout) != "number")
811
- throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");
832
+ throw new Error(
833
+ "timeout must be the number of milliseconds to timeout a connection attempt"
834
+ );
812
835
  if (typeof (i == null ? void 0 : i.shouldReconnect) != "function")
813
836
  throw new Error(
814
837
  "shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect."
@@ -841,7 +864,8 @@ class vr extends ue {
841
864
  * ws代理器
842
865
  */
843
866
  o(this, "_ws", new mr({
844
- url: ""
867
+ url: "",
868
+ robustOptions: { timeout: 1e4, should1000Reconnect: !0 }
845
869
  }));
846
870
  /**
847
871
  * 带看连接状态
@@ -864,7 +888,9 @@ class vr extends ue {
864
888
  * @param event
865
889
  */
866
890
  o(this, "_handleCloseEvent", (e) => {
867
- O.info(`live room closed bacause of ${e.code}-${e.reason || nr(e.code)}`), this.state = x.CLOSED;
891
+ O.info(
892
+ `live room closed bacause of ${e.code}-${e.reason || nr(e.code)}`
893
+ ), this.state = x.CLOSED;
868
894
  });
869
895
  /**
870
896
  * 处理房间正在关闭事件(这个时候可能是断网了)