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

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.
@@ -49452,7 +49452,12 @@
49452
49452
  * @param data
49453
49453
  * @returns
49454
49454
  */
49455
- this.send = (data) => { var _a; return (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.send(data); };
49455
+ this.send = (data) => {
49456
+ var _a, _b, _c;
49457
+ if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
49458
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
49459
+ }
49460
+ };
49456
49461
  /**
49457
49462
  * 关闭连接
49458
49463
  * @param code 代码
@@ -49496,6 +49501,7 @@
49496
49501
  if (!newUrl)
49497
49502
  return;
49498
49503
  this._pendingReconnect = undefined;
49504
+ this._removeWebSocketEvent();
49499
49505
  this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
49500
49506
  this._attempts = this._attempts + 1;
49501
49507
  this.emit('connecting', new CustomEvent('connecting', {
@@ -49517,6 +49523,16 @@
49517
49523
  this._attachConnectivityEvents();
49518
49524
  }
49519
49525
  };
49526
+ /**
49527
+ * 断开ws事件
49528
+ */
49529
+ this._removeWebSocketEvent = () => {
49530
+ var _a, _b, _c, _d;
49531
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
49532
+ (_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
49533
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
49534
+ (_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
49535
+ };
49520
49536
  /**
49521
49537
  * 分发ws事件
49522
49538
  */
@@ -50922,7 +50938,12 @@
50922
50938
  * @param data
50923
50939
  * @returns
50924
50940
  */
50925
- this.send = (data) => { var _a; return (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.send(data); };
50941
+ this.send = (data) => {
50942
+ var _a, _b, _c;
50943
+ if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
50944
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
50945
+ }
50946
+ };
50926
50947
  /**
50927
50948
  * 关闭连接
50928
50949
  * @param code 代码
@@ -50966,6 +50987,7 @@
50966
50987
  if (!newUrl)
50967
50988
  return;
50968
50989
  this._pendingReconnect = undefined;
50990
+ this._removeWebSocketEvent();
50969
50991
  this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
50970
50992
  this._attempts = this._attempts + 1;
50971
50993
  this.emit('connecting', new CustomEvent('connecting', {
@@ -50987,6 +51009,16 @@
50987
51009
  this._attachConnectivityEvents();
50988
51010
  }
50989
51011
  };
51012
+ /**
51013
+ * 断开ws事件
51014
+ */
51015
+ this._removeWebSocketEvent = () => {
51016
+ var _a, _b, _c, _d;
51017
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
51018
+ (_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
51019
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
51020
+ (_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
51021
+ };
50990
51022
  /**
50991
51023
  * 分发ws事件
50992
51024
  */
@@ -51164,6 +51196,9 @@
51164
51196
  this._handleOpenEvent = (event) => {
51165
51197
  logger$1.info('live room open', event.detail);
51166
51198
  this.state = exports.LiveState.OPEN;
51199
+ if (event.detail.reconnects > 0) {
51200
+ this.emit('reconnected', event.detail);
51201
+ }
51167
51202
  };
51168
51203
  /**
51169
51204
  * 处理超时
@@ -51290,6 +51325,7 @@
51290
51325
  this._addLiveControllerEventListeners = () => {
51291
51326
  this._controller.on('stateChange', this._handleStateChange);
51292
51327
  this._controller.on('message', this._handleMessage);
51328
+ this._controller.on('reconnected', this._handleReconnected);
51293
51329
  };
51294
51330
  /**
51295
51331
  * 移除带看控制的事件监听
@@ -51297,6 +51333,7 @@
51297
51333
  this._removeLiveControllerEventListeners = () => {
51298
51334
  this._controller.off('stateChange', this._handleStateChange);
51299
51335
  this._controller.off('message', this._handleMessage);
51336
+ this._controller.off('reconnected', this._handleReconnected);
51300
51337
  };
51301
51338
  /**
51302
51339
  * 带看状态变化
@@ -51304,6 +51341,10 @@
51304
51341
  * @returns
51305
51342
  */
51306
51343
  this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
51344
+ /**
51345
+ * 消息接收
51346
+ * @param liveMsg
51347
+ */
51307
51348
  this._handleMessage = (liveMsg) => __awaiter$$(this, void 0, void 0, function* () {
51308
51349
  var _b, _c, _d, _e, _f, _g;
51309
51350
  if (typeof liveMsg === 'object') {
@@ -51335,6 +51376,7 @@
51335
51376
  */
51336
51377
  case exports.Command.RTCInfo: {
51337
51378
  const { voice_id: voiceId, type } = data;
51379
+ this._buildInData.rtcInfo = { voiceId, type };
51338
51380
  if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
51339
51381
  const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
51340
51382
  voiceId,
@@ -51446,6 +51488,32 @@
51446
51488
  }
51447
51489
  }
51448
51490
  });
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
+ });
51449
51517
  /**
51450
51518
  * 清理带看缓存的数据
51451
51519
  */
@@ -51458,12 +51526,12 @@
51458
51526
  * @returns
51459
51527
  */
51460
51528
  this.connect = (options = {}) => __awaiter$$(this, void 0, void 0, function* () {
51461
- var _h, _j, _k, _l;
51529
+ var _q, _r, _s, _t;
51462
51530
  // 检查 url 和 票据获取接口实现
51463
- this._options.url = (_j = (_h = options.url) !== null && _h !== void 0 ? _h : this._options.url) !== null && _j !== void 0 ? _j : '';
51464
- this._options.getTicket = (_k = options.getTicket) !== null && _k !== void 0 ? _k : this._options.getTicket;
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;
51465
51533
  this._options.initialMicroStatus =
51466
- (_l = options.rtcMicStatus) !== null && _l !== void 0 ? _l : this._options.initialMicroStatus;
51534
+ (_t = options.rtcMicStatus) !== null && _t !== void 0 ? _t : this._options.initialMicroStatus;
51467
51535
  if (!/^ws(s):\/\//.test(this._options.url) ||
51468
51536
  typeof this._options.getTicket !== 'function') {
51469
51537
  if (!/^ws(s):\/\//.test(this._options.url)) {
@@ -51505,11 +51573,11 @@
51505
51573
  * @returns
51506
51574
  */
51507
51575
  this.exit = () => __awaiter$$(this, void 0, void 0, function* () {
51508
- var _m;
51576
+ var _u;
51509
51577
  this._clearLiveData();
51510
51578
  try {
51511
51579
  /** 退出强制关闭语音 */
51512
- (_m = this.$RTC) === null || _m === void 0 ? void 0 : _m.quit();
51580
+ (_u = this.$RTC) === null || _u === void 0 ? void 0 : _u.quit();
51513
51581
  yield this.updateStatus(exports.BuiltinEventType.RoomChange, exports.BuiltinActionType.RoomClose, {});
51514
51582
  }
51515
51583
  catch (e) {
@@ -51536,10 +51604,10 @@
51536
51604
  });
51537
51605
  // 仅用于用户自己的麦克风控制
51538
51606
  this.toggleMicro = (microStatus) => __awaiter$$(this, void 0, void 0, function* () {
51539
- var _o, _p, _q;
51540
- if (!((_p = (_o = this.selfInfo) === null || _o === void 0 ? void 0 : _o.permission) === null || _p === void 0 ? void 0 : _p.control_own_micro))
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))
51541
51609
  return false;
51542
- const result = yield ((_q = this.$RTC) === null || _q === void 0 ? void 0 : _q.toggleMicro(microStatus));
51610
+ const result = yield ((_x = this.$RTC) === null || _x === void 0 ? void 0 : _x.toggleMicro(microStatus));
51543
51611
  if (result) {
51544
51612
  yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
51545
51613
  status: microStatus ? exports.MicroStatus.OPEN : exports.MicroStatus.CLOSE,
@@ -51554,12 +51622,12 @@
51554
51622
  * @returns
51555
51623
  */
51556
51624
  this.forbidMicro = (microStatus, toUserIds) => __awaiter$$(this, void 0, void 0, function* () {
51557
- var _r, _s;
51625
+ var _y, _z;
51558
51626
  if (typeof this._options.canForbidUserMicro === 'function' &&
51559
51627
  !this._options.canForbidUserMicro(toUserIds)) {
51560
51628
  return false;
51561
51629
  }
51562
- if (!((_s = (_r = this.selfInfo) === null || _r === void 0 ? void 0 : _r.permission) === null || _s === void 0 ? void 0 : _s.control_other_micro)) {
51630
+ if (!((_z = (_y = this.selfInfo) === null || _y === void 0 ? void 0 : _y.permission) === null || _z === void 0 ? void 0 : _z.control_other_micro)) {
51563
51631
  return false;
51564
51632
  }
51565
51633
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
@@ -51573,12 +51641,12 @@
51573
51641
  * @returns
51574
51642
  */
51575
51643
  this.forbidSync = (sync, toUserIds) => __awaiter$$(this, void 0, void 0, function* () {
51576
- var _t, _u;
51644
+ var _0, _1;
51577
51645
  if (typeof this._options.canForbidUserSync === 'function' &&
51578
51646
  !this._options.canForbidUserSync(toUserIds)) {
51579
51647
  return false;
51580
51648
  }
51581
- if (!((_u = (_t = this.selfInfo) === null || _t === void 0 ? void 0 : _t.permission) === null || _u === void 0 ? void 0 : _u.control_other_sync)) {
51649
+ if (!((_1 = (_0 = this.selfInfo) === null || _0 === void 0 ? void 0 : _0.permission) === null || _1 === void 0 ? void 0 : _1.control_other_sync)) {
51582
51650
  return false;
51583
51651
  }
51584
51652
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
@@ -51589,12 +51657,12 @@
51589
51657
  * @returns
51590
51658
  */
51591
51659
  this.kick = (toUserIds) => __awaiter$$(this, void 0, void 0, function* () {
51592
- var _v, _w;
51660
+ var _2, _3;
51593
51661
  if (typeof this._options.canForbidUserKick === 'function' &&
51594
51662
  !this._options.canForbidUserKick(toUserIds)) {
51595
51663
  return false;
51596
51664
  }
51597
- if (!((_w = (_v = this.selfInfo) === null || _v === void 0 ? void 0 : _v.permission) === null || _w === void 0 ? void 0 : _w.change_other_status)) {
51665
+ if (!((_3 = (_2 = this.selfInfo) === null || _2 === void 0 ? void 0 : _2.permission) === null || _3 === void 0 ? void 0 : _3.change_other_status)) {
51598
51666
  return false;
51599
51667
  }
51600
51668
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserStatus, {