@realsee/live 0.5.0-alpha.5 → 0.5.0-alpha.8

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');
@@ -48525,25 +48528,37 @@
48525
48528
  }
48526
48529
  join(options) {
48527
48530
  return __awaiter$$(this, void 0, void 0, function* () {
48528
- this.emit('joinWillStart');
48529
- const { sdkAppId, userId, userSig } = yield this.options.getVoiceSign(options);
48530
- this.type = options.type;
48531
- const [res, error] = yield this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${sdkAppId}&userID=${userId}&roomID=${Number(options.voiceId)}&userSig=${userSig}`);
48532
- if (!res) {
48533
- this.emit('error', error ? error : new Error('加入房间失败:未知异常。'));
48534
- this.joined = false;
48535
- }
48536
- else {
48537
- if (res.code === exports.RTCJoinedInfoCodeEnum.Success) {
48538
- this.emit('joined');
48539
- this.joined = true;
48531
+ try {
48532
+ this.emit('joinWillStart');
48533
+ const { sdkAppId, userId, userSig } = yield this.options.getVoiceSign(options);
48534
+ if (!(Boolean(sdkAppId) && Boolean(userId) && Boolean(userSig))) {
48535
+ this.emit('error', new Error('加入房间失败:rtc 签名请求异常'));
48536
+ this.joined = false;
48537
+ return this.joined;
48540
48538
  }
48541
- else {
48542
- this.emit('error', res);
48539
+ this.type = options.type;
48540
+ const [res, error] = yield this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${sdkAppId}&userID=${userId}&roomID=${Number(options.voiceId)}&userSig=${userSig}`);
48541
+ if (!res) {
48542
+ this.emit('error', error ? error : new Error('加入房间失败:未知异常。'));
48543
48543
  this.joined = false;
48544
48544
  }
48545
+ else {
48546
+ if (res.code === exports.RTCJoinedInfoCodeEnum.Success) {
48547
+ this.emit('joined');
48548
+ this.joined = true;
48549
+ }
48550
+ else {
48551
+ this.emit('error', res);
48552
+ this.joined = false;
48553
+ }
48554
+ }
48555
+ return this.joined;
48556
+ }
48557
+ catch (e) {
48558
+ this.emit('error', new Error('加入房间失败:' + e.message));
48559
+ this.joined = false;
48560
+ return this.joined;
48545
48561
  }
48546
- return this.joined;
48547
48562
  });
48548
48563
  }
48549
48564
  quit() {
@@ -50870,6 +50885,7 @@
50870
50885
  constructor(options) {
50871
50886
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
50872
50887
  super();
50888
+ this._readyState = exports.WebSocketState.NOTINITIALIZED;
50873
50889
  this._options = {
50874
50890
  timeout: 10000,
50875
50891
  shouldReconnect: (event, ws) => {
@@ -50886,6 +50902,43 @@
50886
50902
  this._reconnectWhenOnlineAgain = false;
50887
50903
  this._explicitlyClosed = false;
50888
50904
  this._connectivityEventsAttached = false;
50905
+ /**
50906
+ * 做一个健康检查
50907
+ */
50908
+ this._healthCheck = () => __awaiter$$(this, void 0, void 0, function* () {
50909
+ if (this._realWebSocket &&
50910
+ this._realWebSocket.readyState !== this._readyState) {
50911
+ this._readyState = this._realWebSocket.readyState;
50912
+ // 太惨了,断网的时候,ws不会直接closed,而是处于closing的状态
50913
+ if (this._readyState === exports.WebSocketState.CLOSING) {
50914
+ this.emit('closing');
50915
+ }
50916
+ }
50917
+ yield new Promise((resolve) => setTimeout(resolve, 2000));
50918
+ this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
50919
+ });
50920
+ /**
50921
+ * 清理健康检查
50922
+ */
50923
+ this._clearHeathCheckIfNeed = () => {
50924
+ if (this._heathCheckTimer) {
50925
+ cancelAnimationFrame(this._heathCheckTimer);
50926
+ this._heathCheckTimer = undefined;
50927
+ }
50928
+ };
50929
+ /**
50930
+ * 开启健康检查
50931
+ */
50932
+ this._startHealthCheck = () => {
50933
+ this._clearHeathCheckIfNeed();
50934
+ this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
50935
+ };
50936
+ /**
50937
+ * 停止健康检查
50938
+ */
50939
+ this._stopHealthCheck = () => {
50940
+ this._clearHeathCheckIfNeed();
50941
+ };
50889
50942
  /**
50890
50943
  * 清理连接中的请求
50891
50944
  */
@@ -50911,7 +50964,7 @@
50911
50964
  this._offline = () => {
50912
50965
  var _a;
50913
50966
  this._reconnectWhenOnlineAgain = true;
50914
- (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000);
50967
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000, 'offline');
50915
50968
  };
50916
50969
  /**
50917
50970
  * 解除网络监听事件
@@ -51042,6 +51095,7 @@
51042
51095
  const attempts = this._attempts;
51043
51096
  this._attempts = 0;
51044
51097
  this._reconnectWhenOnlineAgain = false;
51098
+ this._startHealthCheck();
51045
51099
  return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
51046
51100
  };
51047
51101
  /**
@@ -51051,6 +51105,7 @@
51051
51105
  */
51052
51106
  this._webSocketCloseHandler = (event) => {
51053
51107
  this._reconnect(event);
51108
+ this._stopHealthCheck();
51054
51109
  return this.emit('close', event);
51055
51110
  };
51056
51111
  /**
@@ -51072,6 +51127,7 @@
51072
51127
  if (options) {
51073
51128
  this.setOptions(options);
51074
51129
  }
51130
+ this._startHealthCheck();
51075
51131
  }
51076
51132
  get attempts() {
51077
51133
  return this._attempts;
@@ -51122,7 +51178,10 @@
51122
51178
  /**
51123
51179
  * ws代理器
51124
51180
  */
51125
- this._ws = new RobustWebSocket();
51181
+ this._ws = new RobustWebSocket({
51182
+ url: '',
51183
+ robustOptions: { timeout: 180000 },
51184
+ });
51126
51185
  /**
51127
51186
  * 带看连接状态
51128
51187
  */
@@ -51132,6 +51191,7 @@
51132
51191
  */
51133
51192
  this._addWebSocketEventListeners = () => {
51134
51193
  this._ws.on('close', this._handleCloseEvent);
51194
+ this._ws.on('closing', this._handleClosingEvent);
51135
51195
  this._ws.on('connecting', this._handleConnectingEvent);
51136
51196
  this._ws.on('error', this._handleErrorEvent);
51137
51197
  this._ws.on('message', this._handleMessageEvent);
@@ -51143,6 +51203,7 @@
51143
51203
  */
51144
51204
  this._removeWebSocketEventListeners = () => {
51145
51205
  this._ws.off('close', this._handleCloseEvent);
51206
+ this._ws.off('closing', this._handleClosingEvent);
51146
51207
  this._ws.off('connecting', this._handleConnectingEvent);
51147
51208
  this._ws.off('error', this._handleErrorEvent);
51148
51209
  this._ws.off('message', this._handleMessageEvent);
@@ -51157,12 +51218,20 @@
51157
51218
  logger$1.info(`live room closed bacause of ${event.code}-${event.reason || parseWSClsErr(event.code)}`);
51158
51219
  this.state = exports.LiveState.CLOSED;
51159
51220
  };
51221
+ /**
51222
+ * 处理房间正在关闭事件(这个时候可能是断网了)
51223
+ */
51224
+ this._handleClosingEvent = () => {
51225
+ var _a;
51226
+ 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);
51227
+ this.state = exports.LiveState.CLOSED;
51228
+ };
51160
51229
  /**
51161
51230
  * 连接中
51162
51231
  * @param event
51163
51232
  */
51164
- this._handleConnectingEvent = (event) => {
51165
- logger$1.info(`live room is connecting`, event.detail);
51233
+ this._handleConnectingEvent = () => {
51234
+ logger$1.info(`live room is connecting`);
51166
51235
  this.state = exports.LiveState.CONNECTING;
51167
51236
  };
51168
51237
  /**
@@ -51325,7 +51394,6 @@
51325
51394
  this._addLiveControllerEventListeners = () => {
51326
51395
  this._controller.on('stateChange', this._handleStateChange);
51327
51396
  this._controller.on('message', this._handleMessage);
51328
- this._controller.on('reconnected', this._handleReconnected);
51329
51397
  };
51330
51398
  /**
51331
51399
  * 移除带看控制的事件监听
@@ -51333,7 +51401,6 @@
51333
51401
  this._removeLiveControllerEventListeners = () => {
51334
51402
  this._controller.off('stateChange', this._handleStateChange);
51335
51403
  this._controller.off('message', this._handleMessage);
51336
- this._controller.off('reconnected', this._handleReconnected);
51337
51404
  };
51338
51405
  /**
51339
51406
  * 带看状态变化
@@ -51488,32 +51555,6 @@
51488
51555
  }
51489
51556
  }
51490
51557
  });
51491
- /**
51492
- * 处理重连
51493
- * @param detail
51494
- */
51495
- this._handleReconnected = (detail) => __awaiter$$(this, void 0, void 0, function* () {
51496
- var _h, _j, _k, _l, _m, _o, _p;
51497
- // 已经重连上ws,尝试重连语音
51498
- this.$RTC.joined = false;
51499
- const { rtcInfo } = this._buildInData;
51500
- if (rtcInfo) {
51501
- const { voiceId, type } = rtcInfo;
51502
- const result = yield ((_h = this.$RTC) === null || _h === void 0 ? void 0 : _h.join({
51503
- voiceId,
51504
- userId: ((_j = this.selfInfo) === null || _j === void 0 ? void 0 : _j.id) || '',
51505
- roomId: (_k = this.roomInfo) === null || _k === void 0 ? void 0 : _k.info.room_code,
51506
- type,
51507
- }));
51508
- if (result) {
51509
- const status = (_o = (_m = (_l = this.selfInfo) === null || _l === void 0 ? void 0 : _l.micro_status) !== null && _m !== void 0 ? _m : this._options.initialMicroStatus) !== null && _o !== void 0 ? _o : exports.MicroStatus.OPEN;
51510
- yield ((_p = this.$RTC) === null || _p === void 0 ? void 0 : _p.toggleMicro(status === exports.MicroStatus.OPEN));
51511
- }
51512
- else {
51513
- logger$1.error('加入语音房间失败');
51514
- }
51515
- }
51516
- });
51517
51558
  /**
51518
51559
  * 清理带看缓存的数据
51519
51560
  */
@@ -51526,12 +51567,12 @@
51526
51567
  * @returns
51527
51568
  */
51528
51569
  this.connect = (options = {}) => __awaiter$$(this, void 0, void 0, function* () {
51529
- var _q, _r, _s, _t;
51570
+ var _h, _j, _k, _l;
51530
51571
  // 检查 url 和 票据获取接口实现
51531
- this._options.url = (_r = (_q = options.url) !== null && _q !== void 0 ? _q : this._options.url) !== null && _r !== void 0 ? _r : '';
51532
- this._options.getTicket = (_s = options.getTicket) !== null && _s !== void 0 ? _s : this._options.getTicket;
51572
+ this._options.url = (_j = (_h = options.url) !== null && _h !== void 0 ? _h : this._options.url) !== null && _j !== void 0 ? _j : '';
51573
+ this._options.getTicket = (_k = options.getTicket) !== null && _k !== void 0 ? _k : this._options.getTicket;
51533
51574
  this._options.initialMicroStatus =
51534
- (_t = options.rtcMicStatus) !== null && _t !== void 0 ? _t : this._options.initialMicroStatus;
51575
+ (_l = options.rtcMicStatus) !== null && _l !== void 0 ? _l : this._options.initialMicroStatus;
51535
51576
  if (!/^ws(s):\/\//.test(this._options.url) ||
51536
51577
  typeof this._options.getTicket !== 'function') {
51537
51578
  if (!/^ws(s):\/\//.test(this._options.url)) {
@@ -51573,11 +51614,11 @@
51573
51614
  * @returns
51574
51615
  */
51575
51616
  this.exit = () => __awaiter$$(this, void 0, void 0, function* () {
51576
- var _u;
51617
+ var _m;
51577
51618
  this._clearLiveData();
51578
51619
  try {
51579
51620
  /** 退出强制关闭语音 */
51580
- (_u = this.$RTC) === null || _u === void 0 ? void 0 : _u.quit();
51621
+ (_m = this.$RTC) === null || _m === void 0 ? void 0 : _m.quit();
51581
51622
  yield this.updateStatus(exports.BuiltinEventType.RoomChange, exports.BuiltinActionType.RoomClose, {});
51582
51623
  }
51583
51624
  catch (e) {
@@ -51604,10 +51645,10 @@
51604
51645
  });
51605
51646
  // 仅用于用户自己的麦克风控制
51606
51647
  this.toggleMicro = (microStatus) => __awaiter$$(this, void 0, void 0, function* () {
51607
- var _v, _w, _x;
51608
- if (!((_w = (_v = this.selfInfo) === null || _v === void 0 ? void 0 : _v.permission) === null || _w === void 0 ? void 0 : _w.control_own_micro))
51648
+ var _o, _p, _q;
51649
+ if (!((_p = (_o = this.selfInfo) === null || _o === void 0 ? void 0 : _o.permission) === null || _p === void 0 ? void 0 : _p.control_own_micro))
51609
51650
  return false;
51610
- const result = yield ((_x = this.$RTC) === null || _x === void 0 ? void 0 : _x.toggleMicro(microStatus));
51651
+ const result = yield ((_q = this.$RTC) === null || _q === void 0 ? void 0 : _q.toggleMicro(microStatus));
51611
51652
  if (result) {
51612
51653
  yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
51613
51654
  status: microStatus ? exports.MicroStatus.OPEN : exports.MicroStatus.CLOSE,
@@ -51622,12 +51663,12 @@
51622
51663
  * @returns
51623
51664
  */
51624
51665
  this.forbidMicro = (microStatus, toUserIds) => __awaiter$$(this, void 0, void 0, function* () {
51625
- var _y, _z;
51666
+ var _r, _s;
51626
51667
  if (typeof this._options.canForbidUserMicro === 'function' &&
51627
51668
  !this._options.canForbidUserMicro(toUserIds)) {
51628
51669
  return false;
51629
51670
  }
51630
- if (!((_z = (_y = this.selfInfo) === null || _y === void 0 ? void 0 : _y.permission) === null || _z === void 0 ? void 0 : _z.control_other_micro)) {
51671
+ if (!((_s = (_r = this.selfInfo) === null || _r === void 0 ? void 0 : _r.permission) === null || _s === void 0 ? void 0 : _s.control_other_micro)) {
51631
51672
  return false;
51632
51673
  }
51633
51674
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
@@ -51641,12 +51682,12 @@
51641
51682
  * @returns
51642
51683
  */
51643
51684
  this.forbidSync = (sync, toUserIds) => __awaiter$$(this, void 0, void 0, function* () {
51644
- var _0, _1;
51685
+ var _t, _u;
51645
51686
  if (typeof this._options.canForbidUserSync === 'function' &&
51646
51687
  !this._options.canForbidUserSync(toUserIds)) {
51647
51688
  return false;
51648
51689
  }
51649
- if (!((_1 = (_0 = this.selfInfo) === null || _0 === void 0 ? void 0 : _0.permission) === null || _1 === void 0 ? void 0 : _1.control_other_sync)) {
51690
+ if (!((_u = (_t = this.selfInfo) === null || _t === void 0 ? void 0 : _t.permission) === null || _u === void 0 ? void 0 : _u.control_other_sync)) {
51650
51691
  return false;
51651
51692
  }
51652
51693
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
@@ -51657,12 +51698,12 @@
51657
51698
  * @returns
51658
51699
  */
51659
51700
  this.kick = (toUserIds) => __awaiter$$(this, void 0, void 0, function* () {
51660
- var _2, _3;
51701
+ var _v, _w;
51661
51702
  if (typeof this._options.canForbidUserKick === 'function' &&
51662
51703
  !this._options.canForbidUserKick(toUserIds)) {
51663
51704
  return false;
51664
51705
  }
51665
- if (!((_3 = (_2 = this.selfInfo) === null || _2 === void 0 ? void 0 : _2.permission) === null || _3 === void 0 ? void 0 : _3.change_other_status)) {
51706
+ if (!((_w = (_v = this.selfInfo) === null || _v === void 0 ? void 0 : _v.permission) === null || _w === void 0 ? void 0 : _w.change_other_status)) {
51666
51707
  return false;
51667
51708
  }
51668
51709
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserStatus, {