@realsee/live 0.6.9 → 0.6.11

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.
package/dist/index.es.js CHANGED
@@ -452,12 +452,9 @@ class nt extends Me {
452
452
  o(this, "micro", !1);
453
453
  o(this, "voiceId", "");
454
454
  o(this, "options");
455
- this.options = { jsBridge: e, getVoiceSign: i }, this.jsBridge.webViewType !== "WxMiniProgramWebView" && this.jsBridge.callAndListen(
456
- "live/userVolumes",
457
- (n) => {
458
- this.emit("userVolumes", n);
459
- }
460
- ), this.jsBridge.callAndListen("live/weakNetwork", (n) => {
455
+ this.options = { jsBridge: e, getVoiceSign: i }, this.jsBridge.webViewType !== "WxMiniProgramWebView" && this.jsBridge.callAndListen("live/userVolumes", (n) => {
456
+ this.emit("userVolumes", n);
457
+ }), this.jsBridge.callAndListen("live/weakNetwork", (n) => {
461
458
  n && this.emit("weakNetwork");
462
459
  });
463
460
  }
@@ -467,29 +464,20 @@ class nt extends Me {
467
464
  async join(e) {
468
465
  try {
469
466
  this.emit("joinWillStart");
470
- const { sdkAppId: i, userId: n, userSig: c } = await this.options.getVoiceSign(
471
- e
472
- );
467
+ const { sdkAppId: i, userId: n, userSig: c } = await this.options.getVoiceSign(e);
473
468
  if (!(Boolean(i) && Boolean(n) && Boolean(c)))
474
469
  return this.emit("error", new Error("加入房间失败:rtc 签名请求异常")), this.joined = !1, this.joined;
475
470
  this.type = e.type;
476
471
  const [u, d] = await this.jsBridge.callAndBackfeed(
477
- `live/join?sdkAppID=${i}&userID=${n}&roomID=${Number(
478
- e.voiceId
479
- )}&userSig=${c}`
472
+ `live/join?sdkAppID=${i}&userID=${n}&roomID=${Number(e.voiceId)}&userSig=${c}`
480
473
  );
481
- return u ? u.code === lt.Success ? (this.emit("joined"), this.joined = !0) : (this.emit("error", u), this.joined = !1) : (this.emit(
482
- "error",
483
- d || new Error("加入房间失败:未知异常。")
484
- ), this.joined = !1), this.joined;
474
+ return u === !0 ? (this.emit("joined"), this.joined = !0) : u ? u.code === lt.Success ? (this.emit("joined"), this.joined = !0) : (this.emit("error", u), this.joined = !1) : (this.emit("error", d || new Error("加入房间失败:未知异常。")), this.joined = !1), this.joined;
485
475
  } catch (i) {
486
476
  return this.emit("error", new Error("加入房间失败:" + i.message)), this.joined = !1, this.joined;
487
477
  }
488
478
  }
489
479
  async quit() {
490
- const [e, i] = await this.jsBridge.callAndBackfeed(
491
- "live/quit"
492
- );
480
+ const [e, i] = await this.jsBridge.callAndBackfeed("live/quit");
493
481
  return e === null && this.emit("error", i || new Error("退出房间失败:未知异常。")), this.joined = !1, !!e;
494
482
  }
495
483
  async detectMicro() {
@@ -497,9 +485,7 @@ class nt extends Me {
497
485
  return e === null ? (this.emit("error", i || new Error("麦克风监测异常!")), !1) : e;
498
486
  }
499
487
  async toggleMicro(e) {
500
- const [i, n] = await this.jsBridge.callAndBackfeed(
501
- `live/toggleMicro?flag=${e ? 1 : 0}`
502
- );
488
+ const [i, n] = await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${e ? 1 : 0}`);
503
489
  return i === null ? (this.emit("error", n || new Error("麦克风监测异常!")), !1) : (this.micro = i, i);
504
490
  }
505
491
  shock() {
@@ -633,7 +619,7 @@ class mr extends ue {
633
619
  timeout: 1e4,
634
620
  shouldReconnect: (e, i) => {
635
621
  if (!(e.code === 1008 || e.code === 1011))
636
- return [1e3, 3e3, 6e3][i.attempts % 3];
622
+ return [0, 1e3, 2e3][i.attempts % 3];
637
623
  },
638
624
  should1000Reconnect: !1,
639
625
  ignoreConnectivityEvents: !1,
@@ -963,6 +949,12 @@ class vr extends ue {
963
949
  return this._ws.send(JSON.stringify(e));
964
950
  throw new Error("live has not yet been initialized!");
965
951
  }
952
+ /**
953
+ * 准备关闭带看
954
+ */
955
+ readyClose() {
956
+ this._ws && (this._ws._explicitlyClosed = !0);
957
+ }
966
958
  }
967
959
  const pr = (r) => Promise.reject("unimplemented method GetVoiceSign"), je = (r, s = {}, e = []) => ({
968
960
  command: r,
@@ -1053,19 +1045,12 @@ class yr extends ue {
1053
1045
  switch (g) {
1054
1046
  case K.SelfUserInfo: {
1055
1047
  const _ = v;
1056
- ot(this.selfInfo, _, { deep: !0 }) || (this._buildInData.selfInfo = _, this.emit(
1057
- "selfInfoUpdate",
1058
- this._buildInData.selfInfo,
1059
- E
1060
- ));
1048
+ ot(this.selfInfo, _, { deep: !0 }) || (this._buildInData.selfInfo = _, this.emit("selfInfoUpdate", this._buildInData.selfInfo, E));
1061
1049
  break;
1062
1050
  }
1063
1051
  case K.RoomInfo: {
1064
1052
  const _ = v;
1065
- this._buildInData.roomInfo = Object.assign({}, _), this.emit(
1066
- "readyKeyframeSync",
1067
- _.last_frame || {}
1068
- );
1053
+ this._buildInData.roomInfo = Object.assign({}, _), this.emit("readyKeyframeSync", _.last_frame || {});
1069
1054
  break;
1070
1055
  }
1071
1056
  case K.RTCInfo: {
@@ -1095,23 +1080,13 @@ class yr extends ue {
1095
1080
  break;
1096
1081
  }
1097
1082
  case K.KeyframeSync: {
1098
- const _ = v, V = Object.keys(
1099
- _
1100
- ).reduce(
1083
+ const _ = v, V = Object.keys(_).reduce(
1101
1084
  (C, k) => {
1102
- if (ot(
1103
- _[k],
1104
- this._buildInData.keyframes[k],
1105
- {
1106
- deep: !0
1107
- }
1108
- ))
1085
+ if (ot(_[k], this._buildInData.keyframes[k], {
1086
+ deep: !0
1087
+ }))
1109
1088
  return C;
1110
- const U = [
1111
- _[k],
1112
- this._buildInData.keyframes[k],
1113
- E
1114
- ], P = k;
1089
+ const U = [_[k], this._buildInData.keyframes[k], E], P = k;
1115
1090
  return this.keyframes.emit(
1116
1091
  P,
1117
1092
  ...U
@@ -1124,9 +1099,7 @@ class yr extends ue {
1124
1099
  }
1125
1100
  case K.BuiltinMsg: {
1126
1101
  const _ = v;
1127
- this.emit("builtinEvent", _), _.event_type === q.UserChange && this.emit("userChange", _), _.event_type === q.RoomChange && this.emit("roomChange", _), _.event_type === q.UserChange && _.action === H.UserMicroStatus && await this.toggleMicro(
1128
- _.data.status === Z.OPEN
1129
- ), _.event_type === q.RoomChange && _.action === H.RoomClose && await this.exit();
1102
+ this.emit("builtinEvent", _), _.event_type === q.UserChange && this.emit("userChange", _), _.event_type === q.RoomChange && this.emit("roomChange", _), _.event_type === q.UserChange && _.action === H.UserMicroStatus && await this.toggleMicro(_.data.status === Z.OPEN), _.event_type === q.RoomChange && _.action === H.RoomClose && await this.exit();
1130
1103
  break;
1131
1104
  }
1132
1105
  case K.UserKickOut: {
@@ -1196,11 +1169,9 @@ class yr extends ue {
1196
1169
  * @param reason
1197
1170
  * @returns
1198
1171
  */
1199
- o(this, "close", async () => await this.updateStatus(
1200
- q.RoomChange,
1201
- H.RoomClose,
1202
- {}
1203
- ));
1172
+ o(this, "close", async () => {
1173
+ await this._controller.readyClose(), await this.updateStatus(q.RoomChange, H.RoomClose, {});
1174
+ });
1204
1175
  /**
1205
1176
  * 销毁带看
1206
1177
  * @returns
@@ -1211,11 +1182,7 @@ class yr extends ue {
1211
1182
  * @param userInfo
1212
1183
  * @returns
1213
1184
  */
1214
- o(this, "setSelfInfo", async (e) => await this.updateStatus(
1215
- q.UserChange,
1216
- H.UserInfo,
1217
- e
1218
- ));
1185
+ o(this, "setSelfInfo", async (e) => await this.updateStatus(q.UserChange, H.UserInfo, e));
1219
1186
  // 仅用于用户自己的麦克风控制
1220
1187
  o(this, "toggleMicro", async (e) => {
1221
1188
  var n, c, u;
@@ -1279,10 +1246,7 @@ class yr extends ue {
1279
1246
  e
1280
1247
  );
1281
1248
  });
1282
- this._addLiveControllerEventListeners(), this._options = Object.assign(
1283
- { initialMicroStatus: Z.OPEN },
1284
- e
1285
- ), this._options.jsBridge = (() => {
1249
+ this._addLiveControllerEventListeners(), this._options = Object.assign({ initialMicroStatus: Z.OPEN }, e), this._options.jsBridge = (() => {
1286
1250
  if (e.jsBridge)
1287
1251
  return e.jsBridge;
1288
1252
  if (e.useBuiltInJsBridge)
@@ -1291,18 +1255,14 @@ class yr extends ue {
1291
1255
  if (e.rtc)
1292
1256
  return e.rtc;
1293
1257
  if (e.rtcType)
1294
- switch (e.getVoiceSign || O.error(
1295
- "GetVoiceSign method must be passed when using built-in RTC instances"
1296
- ), e.rtcType) {
1258
+ switch (e.getVoiceSign || O.error("GetVoiceSign method must be passed when using built-in RTC instances"), e.rtcType) {
1297
1259
  case Q.RealseeVRWebViewRTC: {
1298
1260
  if (this._options.jsBridge)
1299
1261
  return new nt({
1300
1262
  jsBridge: this._options.jsBridge,
1301
1263
  getVoiceSign: this._options.getVoiceSign
1302
1264
  });
1303
- O.error(
1304
- "JsBridge instance must be passed when using built-in VRWebViewRTC instances"
1305
- );
1265
+ O.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");
1306
1266
  return;
1307
1267
  }
1308
1268
  case Q.RealseeBrowserChimeRTC:
@@ -1311,9 +1271,7 @@ class yr extends ue {
1311
1271
  logLevel: e.__debug__ ? st.DEBUG : st.INFO
1312
1272
  });
1313
1273
  case Q.RealseeBrowserRTC:
1314
- return this._options.autoPlayConfirm || O.error(
1315
- "autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances"
1316
- ), new rt({
1274
+ return this._options.autoPlayConfirm || O.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances"), new rt({
1317
1275
  getVoiceSign: this._options.getVoiceSign,
1318
1276
  autoPlayConfirm: this._options.autoPlayConfirm
1319
1277
  });
@@ -1323,9 +1281,7 @@ class yr extends ue {
1323
1281
  }
1324
1282
  }
1325
1283
  if (e.useBuiltInRTC) {
1326
- if (e.getVoiceSign || O.error(
1327
- "GetVoiceSign method must be passed when using built-in RTC instances"
1328
- ), this._options.jsBridge)
1284
+ if (e.getVoiceSign || O.error("GetVoiceSign method must be passed when using built-in RTC instances"), this._options.jsBridge)
1329
1285
  return lr && (ar || cr) || ur ? new nt({
1330
1286
  jsBridge: this._options.jsBridge,
1331
1287
  getVoiceSign: this._options.getVoiceSign
@@ -1335,9 +1291,7 @@ class yr extends ue {
1335
1291
  getVoiceSign: this._options.getVoiceSign,
1336
1292
  autoPlayConfirm: this._options.autoPlayConfirm
1337
1293
  });
1338
- O.error(
1339
- "jsBridge instance must be passed when using built-in RTC instances"
1340
- );
1294
+ O.error("jsBridge instance must be passed when using built-in RTC instances");
1341
1295
  return;
1342
1296
  }
1343
1297
  })(), this._options.rtc || O.warn("unused rtc"), this._options.url && this._options.getTicket && this.connect(), this._options.__debug__ && Object.assign(window, { $liveController: this._controller, $live: this });
@@ -1412,10 +1366,7 @@ class yr extends ue {
1412
1366
  async updateStatus(e, i, n, c) {
1413
1367
  if (this.state !== x.OPEN)
1414
1368
  return !1;
1415
- const u = Object.assign(
1416
- { event_type: e, action: i },
1417
- { data: n }
1418
- ), d = je(K.BuiltinMsg, u, c);
1369
+ const u = Object.assign({ event_type: e, action: i }, { data: n }), d = je(K.BuiltinMsg, u, c);
1419
1370
  try {
1420
1371
  return this._controller.sendMessage(d), !0;
1421
1372
  } catch (g) {
@@ -1431,11 +1382,7 @@ class yr extends ue {
1431
1382
  */
1432
1383
  broadcast(e, i, n) {
1433
1384
  return this.state !== x.OPEN ? !1 : new Promise((c, u) => {
1434
- const d = je(
1435
- K.CustomEvent,
1436
- e,
1437
- i
1438
- ), g = d.front_request_id, v = n ? setTimeout(() => {
1385
+ const d = je(K.CustomEvent, e, i), g = d.front_request_id, v = n ? setTimeout(() => {
1439
1386
  u(new Error("RESPONSE TIMEOUT")), this.off("broadcast", E);
1440
1387
  }, n) : void 0, E = (y, I) => {
1441
1388
  I === g && (v && clearTimeout(v), this.off("broadcast", E), c(y));