@realsee/live 0.5.0-alpha.1 → 0.5.0-alpha.4

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.
@@ -785,6 +785,23 @@ function parseLiveMsg(jsonTxt) {
785
785
  }
786
786
  }
787
787
 
788
+ var LiveState;
789
+ (function (LiveState) {
790
+ LiveState[LiveState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
791
+ /**
792
+ * 正在链接中
793
+ */
794
+ LiveState[LiveState["CONNECTING"] = 0] = "CONNECTING";
795
+ /**
796
+ * 已经链接并且可以通讯
797
+ */
798
+ LiveState[LiveState["OPEN"] = 1] = "OPEN";
799
+ /**
800
+ * 连接已关闭或者链接失败
801
+ */
802
+ LiveState[LiveState["CLOSED"] = 3] = "CLOSED";
803
+ })(LiveState || (LiveState = {}));
804
+
788
805
  /**
789
806
  * 用户当前状态枚举。
790
807
  */
@@ -942,23 +959,6 @@ exports.default = LogLevel;
942
959
 
943
960
  var LogLevel = /*@__PURE__*/getDefaultExportFromCjs(LogLevel_1);
944
961
 
945
- var LiveState;
946
- (function (LiveState) {
947
- LiveState[LiveState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
948
- /**
949
- * 正在链接中
950
- */
951
- LiveState[LiveState["CONNECTING"] = 0] = "CONNECTING";
952
- /**
953
- * 已经链接并且可以通讯
954
- */
955
- LiveState[LiveState["OPEN"] = 1] = "OPEN";
956
- /**
957
- * 连接已关闭或者链接失败
958
- */
959
- LiveState[LiveState["CLOSED"] = 3] = "CLOSED";
960
- })(LiveState || (LiveState = {}));
961
-
962
962
  function appendUri(uri, query) {
963
963
  const hasQuery = uri.indexOf('?') !== -1;
964
964
  const newQuery = Object.keys(query).reduce((accu, curr, idx) => `${accu}${(idx === 0 && !hasQuery) ? '?' : '&'}${curr}=${query[curr]}`, '');
@@ -1228,7 +1228,12 @@ class RobustWebSocket extends Subscribe {
1228
1228
  * @param data
1229
1229
  * @returns
1230
1230
  */
1231
- this.send = (data) => { var _a; return (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.send(data); };
1231
+ this.send = (data) => {
1232
+ var _a, _b, _c;
1233
+ if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
1234
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
1235
+ }
1236
+ };
1232
1237
  /**
1233
1238
  * 关闭连接
1234
1239
  * @param code 代码
@@ -1272,6 +1277,7 @@ class RobustWebSocket extends Subscribe {
1272
1277
  if (!newUrl)
1273
1278
  return;
1274
1279
  this._pendingReconnect = undefined;
1280
+ this._removeWebSocketEvent();
1275
1281
  this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
1276
1282
  this._attempts = this._attempts + 1;
1277
1283
  this.emit('connecting', new CustomEvent('connecting', {
@@ -1293,6 +1299,16 @@ class RobustWebSocket extends Subscribe {
1293
1299
  this._attachConnectivityEvents();
1294
1300
  }
1295
1301
  };
1302
+ /**
1303
+ * 断开ws事件
1304
+ */
1305
+ this._removeWebSocketEvent = () => {
1306
+ var _a, _b, _c, _d;
1307
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
1308
+ (_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
1309
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
1310
+ (_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
1311
+ };
1296
1312
  /**
1297
1313
  * 分发ws事件
1298
1314
  */
@@ -2333,5 +2349,5 @@ function createLiveReact(options) {
2333
2349
  };
2334
2350
  }
2335
2351
 
2336
- export { BrowserRTC, BrowserRTC4Chime, BuiltInRTCType, BuiltinActionType, BuiltinEventType, Command, CoreRTC, MemUserStatus, MicroStatus, RTCJoinedInfoCodeEnum, RTCType, UserStatus, VRWebViewRTC, WebSocketCloseError, WebSocketErrorType, WebSocketState, createLive, createLiveReact, parseLiveMsg, parseWSClsErr };
2352
+ export { BrowserRTC, BrowserRTC4Chime, BuiltInRTCType, BuiltinActionType, BuiltinEventType, Command, CoreRTC, LiveState, MemUserStatus, MicroStatus, RTCJoinedInfoCodeEnum, RTCType, UserStatus, VRWebViewRTC, WebSocketCloseError, WebSocketErrorType, WebSocketState, createLive, createLiveReact, parseLiveMsg, parseWSClsErr };
2337
2353
  //# sourceMappingURL=realsee-live.esm.js.map