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

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.
@@ -48512,9 +48512,12 @@
48512
48512
  this.micro = false;
48513
48513
  this.voiceId = '';
48514
48514
  this.options = { jsBridge, getVoiceSign };
48515
- this.jsBridge.callAndListen('live/userVolumes', (userVolumes) => {
48516
- this.emit('userVolumes', userVolumes);
48517
- });
48515
+ // TO-DO: 在微信小程序下有个音量上报的BUG会导致消息体过大从而jsbridge异常断开
48516
+ if (this.jsBridge.webViewType !== "WxMiniProgramWebView") {
48517
+ this.jsBridge.callAndListen('live/userVolumes', (userVolumes) => {
48518
+ this.emit('userVolumes', userVolumes);
48519
+ });
48520
+ }
48518
48521
  this.jsBridge.callAndListen('live/weakNetwork', (weakNetwork) => {
48519
48522
  if (weakNetwork)
48520
48523
  this.emit('weakNetwork');
@@ -50870,6 +50873,7 @@
50870
50873
  constructor(options) {
50871
50874
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
50872
50875
  super();
50876
+ this._readyState = exports.WebSocketState.NOTINITIALIZED;
50873
50877
  this._options = {
50874
50878
  timeout: 10000,
50875
50879
  shouldReconnect: (event, ws) => {
@@ -50886,6 +50890,43 @@
50886
50890
  this._reconnectWhenOnlineAgain = false;
50887
50891
  this._explicitlyClosed = false;
50888
50892
  this._connectivityEventsAttached = false;
50893
+ /**
50894
+ * 做一个健康检查
50895
+ */
50896
+ this._healthCheck = () => __awaiter$$(this, void 0, void 0, function* () {
50897
+ if (this._realWebSocket &&
50898
+ this._realWebSocket.readyState !== this._readyState) {
50899
+ this._readyState = this._realWebSocket.readyState;
50900
+ // 太惨了,断网的时候,ws不会直接closed,而是处于closing的状态
50901
+ if (this._readyState === exports.WebSocketState.CLOSING) {
50902
+ this.emit('closing');
50903
+ }
50904
+ }
50905
+ yield new Promise((resolve) => setTimeout(resolve, 2000));
50906
+ this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
50907
+ });
50908
+ /**
50909
+ * 清理健康检查
50910
+ */
50911
+ this._clearHeathCheckIfNeed = () => {
50912
+ if (this._heathCheckTimer) {
50913
+ cancelAnimationFrame(this._heathCheckTimer);
50914
+ this._heathCheckTimer = undefined;
50915
+ }
50916
+ };
50917
+ /**
50918
+ * 开启健康检查
50919
+ */
50920
+ this._startHealthCheck = () => {
50921
+ this._clearHeathCheckIfNeed();
50922
+ this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
50923
+ };
50924
+ /**
50925
+ * 停止健康检查
50926
+ */
50927
+ this._stopHealthCheck = () => {
50928
+ this._clearHeathCheckIfNeed();
50929
+ };
50889
50930
  /**
50890
50931
  * 清理连接中的请求
50891
50932
  */
@@ -50911,7 +50952,7 @@
50911
50952
  this._offline = () => {
50912
50953
  var _a;
50913
50954
  this._reconnectWhenOnlineAgain = true;
50914
- (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000);
50955
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000, 'offline');
50915
50956
  };
50916
50957
  /**
50917
50958
  * 解除网络监听事件
@@ -51042,6 +51083,7 @@
51042
51083
  const attempts = this._attempts;
51043
51084
  this._attempts = 0;
51044
51085
  this._reconnectWhenOnlineAgain = false;
51086
+ this._startHealthCheck();
51045
51087
  return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
51046
51088
  };
51047
51089
  /**
@@ -51051,6 +51093,7 @@
51051
51093
  */
51052
51094
  this._webSocketCloseHandler = (event) => {
51053
51095
  this._reconnect(event);
51096
+ this._stopHealthCheck();
51054
51097
  return this.emit('close', event);
51055
51098
  };
51056
51099
  /**
@@ -51072,6 +51115,7 @@
51072
51115
  if (options) {
51073
51116
  this.setOptions(options);
51074
51117
  }
51118
+ this._startHealthCheck();
51075
51119
  }
51076
51120
  get attempts() {
51077
51121
  return this._attempts;
@@ -51122,7 +51166,10 @@
51122
51166
  /**
51123
51167
  * ws代理器
51124
51168
  */
51125
- this._ws = new RobustWebSocket();
51169
+ this._ws = new RobustWebSocket({
51170
+ url: '',
51171
+ robustOptions: { timeout: 180000 },
51172
+ });
51126
51173
  /**
51127
51174
  * 带看连接状态
51128
51175
  */
@@ -51132,6 +51179,7 @@
51132
51179
  */
51133
51180
  this._addWebSocketEventListeners = () => {
51134
51181
  this._ws.on('close', this._handleCloseEvent);
51182
+ this._ws.on('closing', this._handleClosingEvent);
51135
51183
  this._ws.on('connecting', this._handleConnectingEvent);
51136
51184
  this._ws.on('error', this._handleErrorEvent);
51137
51185
  this._ws.on('message', this._handleMessageEvent);
@@ -51143,6 +51191,7 @@
51143
51191
  */
51144
51192
  this._removeWebSocketEventListeners = () => {
51145
51193
  this._ws.off('close', this._handleCloseEvent);
51194
+ this._ws.off('closing', this._handleClosingEvent);
51146
51195
  this._ws.off('connecting', this._handleConnectingEvent);
51147
51196
  this._ws.off('error', this._handleErrorEvent);
51148
51197
  this._ws.off('message', this._handleMessageEvent);
@@ -51157,12 +51206,20 @@
51157
51206
  logger$1.info(`live room closed bacause of ${event.code}-${event.reason || parseWSClsErr(event.code)}`);
51158
51207
  this.state = exports.LiveState.CLOSED;
51159
51208
  };
51209
+ /**
51210
+ * 处理房间正在关闭事件(这个时候可能是断网了)
51211
+ */
51212
+ this._handleClosingEvent = () => {
51213
+ var _a;
51214
+ logger$1.info(`live room is closing, onLine:`, (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _a === void 0 ? void 0 : _a.onLine);
51215
+ this.state = exports.LiveState.CLOSED;
51216
+ };
51160
51217
  /**
51161
51218
  * 连接中
51162
51219
  * @param event
51163
51220
  */
51164
- this._handleConnectingEvent = (event) => {
51165
- logger$1.info(`live room is connecting`, event.detail);
51221
+ this._handleConnectingEvent = () => {
51222
+ logger$1.info(`live room is connecting`);
51166
51223
  this.state = exports.LiveState.CONNECTING;
51167
51224
  };
51168
51225
  /**
@@ -51196,6 +51253,9 @@
51196
51253
  this._handleOpenEvent = (event) => {
51197
51254
  logger$1.info('live room open', event.detail);
51198
51255
  this.state = exports.LiveState.OPEN;
51256
+ if (event.detail.reconnects > 0) {
51257
+ this.emit('reconnected', event.detail);
51258
+ }
51199
51259
  };
51200
51260
  /**
51201
51261
  * 处理超时
@@ -51336,6 +51396,10 @@
51336
51396
  * @returns
51337
51397
  */
51338
51398
  this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
51399
+ /**
51400
+ * 消息接收
51401
+ * @param liveMsg
51402
+ */
51339
51403
  this._handleMessage = (liveMsg) => __awaiter$$(this, void 0, void 0, function* () {
51340
51404
  var _b, _c, _d, _e, _f, _g;
51341
51405
  if (typeof liveMsg === 'object') {
@@ -51367,6 +51431,7 @@
51367
51431
  */
51368
51432
  case exports.Command.RTCInfo: {
51369
51433
  const { voice_id: voiceId, type } = data;
51434
+ this._buildInData.rtcInfo = { voiceId, type };
51370
51435
  if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
51371
51436
  const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
51372
51437
  voiceId,