@realsee/live 0.5.0-alpha.3 → 0.5.0-alpha.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.
@@ -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');
@@ -49501,6 +49504,7 @@
49501
49504
  if (!newUrl)
49502
49505
  return;
49503
49506
  this._pendingReconnect = undefined;
49507
+ this._removeWebSocketEvent();
49504
49508
  this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
49505
49509
  this._attempts = this._attempts + 1;
49506
49510
  this.emit('connecting', new CustomEvent('connecting', {
@@ -49522,6 +49526,16 @@
49522
49526
  this._attachConnectivityEvents();
49523
49527
  }
49524
49528
  };
49529
+ /**
49530
+ * 断开ws事件
49531
+ */
49532
+ this._removeWebSocketEvent = () => {
49533
+ var _a, _b, _c, _d;
49534
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
49535
+ (_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
49536
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
49537
+ (_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
49538
+ };
49525
49539
  /**
49526
49540
  * 分发ws事件
49527
49541
  */
@@ -50859,6 +50873,7 @@
50859
50873
  constructor(options) {
50860
50874
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
50861
50875
  super();
50876
+ this._readyState = exports.WebSocketState.NOTINITIALIZED;
50862
50877
  this._options = {
50863
50878
  timeout: 10000,
50864
50879
  shouldReconnect: (event, ws) => {
@@ -50875,6 +50890,43 @@
50875
50890
  this._reconnectWhenOnlineAgain = false;
50876
50891
  this._explicitlyClosed = false;
50877
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
+ };
50878
50930
  /**
50879
50931
  * 清理连接中的请求
50880
50932
  */
@@ -50900,7 +50952,7 @@
50900
50952
  this._offline = () => {
50901
50953
  var _a;
50902
50954
  this._reconnectWhenOnlineAgain = true;
50903
- (_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');
50904
50956
  };
50905
50957
  /**
50906
50958
  * 解除网络监听事件
@@ -50976,6 +51028,7 @@
50976
51028
  if (!newUrl)
50977
51029
  return;
50978
51030
  this._pendingReconnect = undefined;
51031
+ this._removeWebSocketEvent();
50979
51032
  this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
50980
51033
  this._attempts = this._attempts + 1;
50981
51034
  this.emit('connecting', new CustomEvent('connecting', {
@@ -50997,6 +51050,16 @@
50997
51050
  this._attachConnectivityEvents();
50998
51051
  }
50999
51052
  };
51053
+ /**
51054
+ * 断开ws事件
51055
+ */
51056
+ this._removeWebSocketEvent = () => {
51057
+ var _a, _b, _c, _d;
51058
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
51059
+ (_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
51060
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
51061
+ (_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
51062
+ };
51000
51063
  /**
51001
51064
  * 分发ws事件
51002
51065
  */
@@ -51020,6 +51083,7 @@
51020
51083
  const attempts = this._attempts;
51021
51084
  this._attempts = 0;
51022
51085
  this._reconnectWhenOnlineAgain = false;
51086
+ this._startHealthCheck();
51023
51087
  return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
51024
51088
  };
51025
51089
  /**
@@ -51029,6 +51093,7 @@
51029
51093
  */
51030
51094
  this._webSocketCloseHandler = (event) => {
51031
51095
  this._reconnect(event);
51096
+ this._stopHealthCheck();
51032
51097
  return this.emit('close', event);
51033
51098
  };
51034
51099
  /**
@@ -51050,6 +51115,7 @@
51050
51115
  if (options) {
51051
51116
  this.setOptions(options);
51052
51117
  }
51118
+ this._startHealthCheck();
51053
51119
  }
51054
51120
  get attempts() {
51055
51121
  return this._attempts;
@@ -51110,6 +51176,7 @@
51110
51176
  */
51111
51177
  this._addWebSocketEventListeners = () => {
51112
51178
  this._ws.on('close', this._handleCloseEvent);
51179
+ this._ws.on('closing', this._handleClosingEvent);
51113
51180
  this._ws.on('connecting', this._handleConnectingEvent);
51114
51181
  this._ws.on('error', this._handleErrorEvent);
51115
51182
  this._ws.on('message', this._handleMessageEvent);
@@ -51121,6 +51188,7 @@
51121
51188
  */
51122
51189
  this._removeWebSocketEventListeners = () => {
51123
51190
  this._ws.off('close', this._handleCloseEvent);
51191
+ this._ws.off('closing', this._handleClosingEvent);
51124
51192
  this._ws.off('connecting', this._handleConnectingEvent);
51125
51193
  this._ws.off('error', this._handleErrorEvent);
51126
51194
  this._ws.off('message', this._handleMessageEvent);
@@ -51135,12 +51203,20 @@
51135
51203
  logger$1.info(`live room closed bacause of ${event.code}-${event.reason || parseWSClsErr(event.code)}`);
51136
51204
  this.state = exports.LiveState.CLOSED;
51137
51205
  };
51206
+ /**
51207
+ * 处理房间正在关闭事件(这个时候可能是断网了)
51208
+ */
51209
+ this._handleClosingEvent = () => {
51210
+ var _a;
51211
+ 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);
51212
+ this.state = exports.LiveState.CLOSED;
51213
+ };
51138
51214
  /**
51139
51215
  * 连接中
51140
51216
  * @param event
51141
51217
  */
51142
- this._handleConnectingEvent = (event) => {
51143
- logger$1.info(`live room is connecting`, event.detail);
51218
+ this._handleConnectingEvent = () => {
51219
+ logger$1.info(`live room is connecting`);
51144
51220
  this.state = exports.LiveState.CONNECTING;
51145
51221
  };
51146
51222
  /**
@@ -51174,6 +51250,9 @@
51174
51250
  this._handleOpenEvent = (event) => {
51175
51251
  logger$1.info('live room open', event.detail);
51176
51252
  this.state = exports.LiveState.OPEN;
51253
+ if (event.detail.reconnects > 0) {
51254
+ this.emit('reconnected', event.detail);
51255
+ }
51177
51256
  };
51178
51257
  /**
51179
51258
  * 处理超时
@@ -51314,6 +51393,10 @@
51314
51393
  * @returns
51315
51394
  */
51316
51395
  this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
51396
+ /**
51397
+ * 消息接收
51398
+ * @param liveMsg
51399
+ */
51317
51400
  this._handleMessage = (liveMsg) => __awaiter$$(this, void 0, void 0, function* () {
51318
51401
  var _b, _c, _d, _e, _f, _g;
51319
51402
  if (typeof liveMsg === 'object') {
@@ -51345,6 +51428,7 @@
51345
51428
  */
51346
51429
  case exports.Command.RTCInfo: {
51347
51430
  const { voice_id: voiceId, type } = data;
51431
+ this._buildInData.rtcInfo = { voiceId, type };
51348
51432
  if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
51349
51433
  const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
51350
51434
  voiceId,