@realsee/live 0.5.2-dev.2 → 0.5.2-dev.4

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.
@@ -2,27 +2,25 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var JSBridge = require('@realsee/jsbridge-x');
6
5
  var TRTC = require('trtc-js-sdk');
7
6
  var amazonChimeSdkJs = require('amazon-chime-sdk-js');
8
7
  var React = require('react');
9
8
 
10
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
10
 
12
- var JSBridge__default = /*#__PURE__*/_interopDefaultLegacy(JSBridge);
13
11
  var TRTC__default = /*#__PURE__*/_interopDefaultLegacy(TRTC);
14
12
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
15
13
 
16
- const EVENT_SYMBOL = Symbol('$$REALSEE_LIVE_EVENT$$');
17
- function __generateEventIfNotExisted(instance) {
18
- if (!instance[EVENT_SYMBOL]) {
19
- instance[EVENT_SYMBOL] = {};
14
+ const EVENT_SYMBOL$1 = Symbol('$$REALSEE_LIVE_EVENT$$');
15
+ function __generateEventIfNotExisted$1(instance) {
16
+ if (!instance[EVENT_SYMBOL$1]) {
17
+ instance[EVENT_SYMBOL$1] = {};
20
18
  }
21
- return instance[EVENT_SYMBOL];
19
+ return instance[EVENT_SYMBOL$1];
22
20
  }
23
- function __removeEventIfNotExisted(instance) {
24
- if (!instance[EVENT_SYMBOL]) {
25
- delete instance[EVENT_SYMBOL];
21
+ function __removeEventIfNotExisted$1(instance) {
22
+ if (!instance[EVENT_SYMBOL$1]) {
23
+ delete instance[EVENT_SYMBOL$1];
26
24
  }
27
25
  }
28
26
  /**
@@ -36,13 +34,13 @@ function __removeEventIfNotExisted(instance) {
36
34
  * }>()
37
35
  * ```
38
36
  */
39
- class Subscribe {
37
+ class Subscribe$1 {
40
38
  /**
41
39
  * 判断是否注册了事件
42
40
  * @param name 事件类型
43
41
  */
44
42
  hasListener(name) {
45
- const events = __generateEventIfNotExisted(this);
43
+ const events = __generateEventIfNotExisted$1(this);
46
44
  return events && events[name] && events[name].length > 0;
47
45
  }
48
46
  /**
@@ -55,7 +53,7 @@ class Subscribe {
55
53
  * @template C 回调函数函数上下文
56
54
  */
57
55
  on(name, callback, once) {
58
- const events = __generateEventIfNotExisted(this);
56
+ const events = __generateEventIfNotExisted$1(this);
59
57
  if (!events[name])
60
58
  events[name] = [];
61
59
  events[name].push([callback, once || false]);
@@ -83,10 +81,10 @@ class Subscribe {
83
81
  */
84
82
  off(name, callback) {
85
83
  if (name === undefined) {
86
- __removeEventIfNotExisted(this);
84
+ __removeEventIfNotExisted$1(this);
87
85
  return;
88
86
  }
89
- const events = __generateEventIfNotExisted(this);
87
+ const events = __generateEventIfNotExisted$1(this);
90
88
  if (!events[name])
91
89
  events[name] = [];
92
90
  if (callback === undefined) {
@@ -111,7 +109,7 @@ class Subscribe {
111
109
  */
112
110
  emit(name, ...data) {
113
111
  let canceled = false;
114
- const events = __generateEventIfNotExisted(this);
112
+ const events = __generateEventIfNotExisted$1(this);
115
113
  const event = events[name] || [];
116
114
  for (let one of event.slice()) {
117
115
  const [callback, once = false] = one;
@@ -128,7 +126,7 @@ class Subscribe {
128
126
  /**
129
127
  * rtc 基础抽象类
130
128
  */
131
- class CoreRTC extends Subscribe {
129
+ class CoreRTC extends Subscribe$1 {
132
130
  }
133
131
 
134
132
  /******************************************************************************
@@ -146,7 +144,7 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
146
144
  PERFORMANCE OF THIS SOFTWARE.
147
145
  ***************************************************************************** */
148
146
 
149
- function __awaiter(thisArg, _arguments, P, generator) {
147
+ function __awaiter$1(thisArg, _arguments, P, generator) {
150
148
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
151
149
  return new (P || (P = Promise))(function (resolve, reject) {
152
150
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -220,26 +218,26 @@ const logger = {
220
218
  var logger$1 = logger;
221
219
 
222
220
  // uuid
223
- function S4() {
221
+ function S4$1() {
224
222
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
225
223
  }
226
224
  /**
227
225
  * 基于伪随机数生成 **uuid**。
228
226
  */
229
- function uuid() {
227
+ function uuid$1() {
230
228
  // then to call it, plus stitch in '4' in the third group
231
- return (S4() +
232
- S4() +
229
+ return (S4$1() +
230
+ S4$1() +
233
231
  '-' +
234
- S4() +
232
+ S4$1() +
235
233
  '-4' +
236
- S4().substr(0, 3) +
234
+ S4$1().substr(0, 3) +
237
235
  '-' +
238
- S4() +
236
+ S4$1() +
239
237
  '-' +
240
- S4() +
241
- S4() +
242
- S4()).toLowerCase();
238
+ S4$1() +
239
+ S4$1() +
240
+ S4$1()).toLowerCase();
243
241
  }
244
242
 
245
243
  class BrowserRTC extends CoreRTC {
@@ -258,7 +256,7 @@ class BrowserRTC extends CoreRTC {
258
256
  client: null,
259
257
  stream: null,
260
258
  };
261
- this.join = (options) => __awaiter(this, void 0, void 0, function* () {
259
+ this.join = (options) => __awaiter$1(this, void 0, void 0, function* () {
262
260
  var _a;
263
261
  this.emit('joinWillStart');
264
262
  const createClientOptions = yield this._getVoiceSign({
@@ -322,12 +320,12 @@ class BrowserRTC extends CoreRTC {
322
320
  this._initParentDom();
323
321
  }
324
322
  _initParentDom() {
325
- this.$dom.id = `rs-rtc-${uuid()}`;
323
+ this.$dom.id = `rs-rtc-${uuid$1()}`;
326
324
  this.$dom.style.display = 'none';
327
325
  document.body.appendChild(this.$dom);
328
326
  }
329
327
  quit() {
330
- return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
328
+ return new Promise((resolve) => __awaiter$1(this, void 0, void 0, function* () {
331
329
  var _a, _b;
332
330
  this.joined = false;
333
331
  if (this._trtc.stream) {
@@ -337,6 +335,7 @@ class BrowserRTC extends CoreRTC {
337
335
  this._trtc.stream = null;
338
336
  }
339
337
  (_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.leave().then(() => (this._trtc.client = null)).then(() => resolve(true)).catch(() => resolve(false));
338
+ resolve(true);
340
339
  }));
341
340
  }
342
341
  detectMicro() {
@@ -400,8 +399,8 @@ class BrowserRTC4Chime extends CoreRTC {
400
399
  * 对audio标签初始化
401
400
  */
402
401
  this._initDom = () => {
403
- this.$audio.id = `rs-rtc-${uuid()}`;
404
- this.$dom.id = `rs-rtc-${uuid()}`;
402
+ this.$audio.id = `rs-rtc-${uuid$1()}`;
403
+ this.$dom.id = `rs-rtc-${uuid$1()}`;
405
404
  this.$dom.appendChild(this.$audio);
406
405
  document.body.appendChild(this.$dom);
407
406
  };
@@ -514,8 +513,8 @@ class BrowserRTC4Chime extends CoreRTC {
514
513
  * @returns
515
514
  */
516
515
  join(options) {
517
- return __awaiter(this, void 0, void 0, function* () {
518
- return new Promise((success, fail) => __awaiter(this, void 0, void 0, function* () {
516
+ return __awaiter$1(this, void 0, void 0, function* () {
517
+ return new Promise((success, fail) => __awaiter$1(this, void 0, void 0, function* () {
519
518
  var _a;
520
519
  this.emit('joinWillStart');
521
520
  try {
@@ -601,7 +600,7 @@ class BrowserRTC4Chime extends CoreRTC {
601
600
  });
602
601
  }
603
602
  detectMicro() {
604
- return __awaiter(this, void 0, void 0, function* () {
603
+ return __awaiter$1(this, void 0, void 0, function* () {
605
604
  return new Promise((resolve) => {
606
605
  const rule = { audio: true, video: false };
607
606
  try {
@@ -619,7 +618,7 @@ class BrowserRTC4Chime extends CoreRTC {
619
618
  }
620
619
  toggleMicro(flag) {
621
620
  var _a, _b, _c;
622
- return __awaiter(this, void 0, void 0, function* () {
621
+ return __awaiter$1(this, void 0, void 0, function* () {
623
622
  if (flag) {
624
623
  (_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeUnmuteLocalAudio();
625
624
  }
@@ -686,7 +685,7 @@ class VRWebViewRTC extends CoreRTC {
686
685
  });
687
686
  }
688
687
  join(options) {
689
- return __awaiter(this, void 0, void 0, function* () {
688
+ return __awaiter$1(this, void 0, void 0, function* () {
690
689
  try {
691
690
  this.emit('joinWillStart');
692
691
  const { sdkAppId, userId, userSig } = yield this.options.getVoiceSign(options);
@@ -721,7 +720,7 @@ class VRWebViewRTC extends CoreRTC {
721
720
  });
722
721
  }
723
722
  quit() {
724
- return __awaiter(this, void 0, void 0, function* () {
723
+ return __awaiter$1(this, void 0, void 0, function* () {
725
724
  const [res, error] = yield this.jsBridge.callAndBackfeed('live/quit');
726
725
  if (res === null) {
727
726
  this.emit('error', error ? error : new Error('退出房间失败:未知异常。'));
@@ -731,7 +730,7 @@ class VRWebViewRTC extends CoreRTC {
731
730
  });
732
731
  }
733
732
  detectMicro() {
734
- return __awaiter(this, void 0, void 0, function* () {
733
+ return __awaiter$1(this, void 0, void 0, function* () {
735
734
  const [res, error] = yield this.jsBridge.detectMicro();
736
735
  if (res === null) {
737
736
  this.emit('error', error ? error : new Error('麦克风监测异常!'));
@@ -741,7 +740,7 @@ class VRWebViewRTC extends CoreRTC {
741
740
  });
742
741
  }
743
742
  toggleMicro(flag) {
744
- return __awaiter(this, void 0, void 0, function* () {
743
+ return __awaiter$1(this, void 0, void 0, function* () {
745
744
  const [res, error] = yield this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${!!flag ? 1 : 0}`);
746
745
  if (res === null) {
747
746
  this.emit('error', error ? error : new Error('麦克风监测异常!'));
@@ -857,156 +856,1813 @@ function parseLiveMsg(jsonTxt) {
857
856
  }
858
857
  return resMsg;
859
858
  }
860
- catch (error) {
861
- // notcare? 过滤掉所有不符合规范的数据
862
- return false;
859
+ catch (error) {
860
+ // notcare? 过滤掉所有不符合规范的数据
861
+ return false;
862
+ }
863
+ }
864
+
865
+ exports.LiveState = void 0;
866
+ (function (LiveState) {
867
+ LiveState[LiveState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
868
+ /**
869
+ * 正在链接中
870
+ */
871
+ LiveState[LiveState["CONNECTING"] = 0] = "CONNECTING";
872
+ /**
873
+ * 已经链接并且可以通讯
874
+ */
875
+ LiveState[LiveState["OPEN"] = 1] = "OPEN";
876
+ /**
877
+ * 连接已关闭或者链接失败
878
+ */
879
+ LiveState[LiveState["CLOSED"] = 3] = "CLOSED";
880
+ })(exports.LiveState || (exports.LiveState = {}));
881
+
882
+ /**
883
+ * 用户当前状态枚举。
884
+ */
885
+ exports.UserStatus = void 0;
886
+ (function (UserStatus) {
887
+ /**
888
+ * 正常
889
+ */
890
+ UserStatus[UserStatus["Normal"] = 0] = "Normal";
891
+ /**
892
+ * 被移除
893
+ */
894
+ UserStatus[UserStatus["Removed"] = 1] = "Removed";
895
+ /**
896
+ * 被替换
897
+ */
898
+ UserStatus[UserStatus["Replaced"] = 2] = "Replaced";
899
+ })(exports.UserStatus || (exports.UserStatus = {}));
900
+ exports.MemUserStatus = void 0;
901
+ (function (MemUserStatus) {
902
+ MemUserStatus["WAIT_ENTER"] = "WAIT_ENTER";
903
+ MemUserStatus["ONLINE"] = "ONLINE";
904
+ MemUserStatus["LEAVE"] = "LEAVE";
905
+ MemUserStatus["KICK_OUT"] = "KICK_OUT";
906
+ MemUserStatus["BE_REPLACE"] = "BE_REPLACE";
907
+ MemUserStatus["EXCEPTION"] = "EXCEPTION";
908
+ })(exports.MemUserStatus || (exports.MemUserStatus = {}));
909
+
910
+ /**
911
+ * WebSocket 连接状态枚举
912
+ */
913
+ exports.WebSocketState = void 0;
914
+ (function (WebSocketState) {
915
+ /**
916
+ * 尚未初始化
917
+ */
918
+ WebSocketState[WebSocketState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
919
+ /**
920
+ * 正在链接中
921
+ */
922
+ WebSocketState[WebSocketState["CONNECTING"] = 0] = "CONNECTING";
923
+ /**
924
+ * 已经链接并且可以通讯
925
+ */
926
+ WebSocketState[WebSocketState["OPEN"] = 1] = "OPEN";
927
+ /**
928
+ * 连接正在关闭
929
+ */
930
+ WebSocketState[WebSocketState["CLOSING"] = 2] = "CLOSING";
931
+ /**
932
+ * 连接已关闭或者没有链接成功
933
+ */
934
+ WebSocketState[WebSocketState["CLOSED"] = 3] = "CLOSED";
935
+ })(exports.WebSocketState || (exports.WebSocketState = {}));
936
+ exports.WebSocketErrorType = void 0;
937
+ (function (WebSocketErrorType) {
938
+ WebSocketErrorType["Error"] = "Error";
939
+ WebSocketErrorType["Close"] = "Close";
940
+ WebSocketErrorType["MicroAuth"] = "MicroAuth";
941
+ WebSocketErrorType["DuplicateConnect"] = "DuplicateConnect";
942
+ WebSocketErrorType["IllegalURL"] = "IllegalURL";
943
+ WebSocketErrorType["Unknown"] = "Unknown";
944
+ WebSocketErrorType["IllegalArgs"] = "IllegalArgs";
945
+ })(exports.WebSocketErrorType || (exports.WebSocketErrorType = {}));
946
+ /**
947
+ * WebSocket 异常关闭枚举:https://developer.mozilla.org/zh-CN/docs/Web/API/CloseEvent。
948
+ */
949
+ exports.WebSocketCloseError = void 0;
950
+ (function (WebSocketCloseError) {
951
+ /**
952
+ * 终端离开, 可能因为服务端错误, 也可能因为浏览器正从打开连接的页面跳转离开。
953
+ */
954
+ WebSocketCloseError["Err_1001"] = "CLOSE_GOING_AWAY";
955
+ /**
956
+ * 由于协议错误而中断连接。
957
+ */
958
+ WebSocketCloseError["Err_1002"] = "CLOSE_PROTOCOL_ERROR";
959
+ /**
960
+ * 由于接收到不允许的数据类型而断开连接 (如仅接收文本数据的终端接收到了二进制数据)。
961
+ */
962
+ WebSocketCloseError["Err_1003"] = "CLOSE_UNSUPPORTED";
963
+ /**
964
+ * 安全因素或WebSocket连接次数达到上限。
965
+ */
966
+ WebSocketCloseError["Err_1006"] = "CLOSE_ABNORMAL";
967
+ /**
968
+ * 由于收到了格式不符的数据而断开连接 (如文本消息中包含了非 UTF-8 数据)。
969
+ */
970
+ WebSocketCloseError["Err_1007"] = "Unsupported Data";
971
+ /**
972
+ * 由于收到不符合约定的数据而断开连接。
973
+ */
974
+ WebSocketCloseError["Err_1008"] = "Policy Violation";
975
+ /**
976
+ * 由于收到过大的数据帧而断开连接。
977
+ */
978
+ WebSocketCloseError["Err_1009"] = "CLOSE_TOO_LARGE";
979
+ /**
980
+ * 未知错误。
981
+ */
982
+ WebSocketCloseError["Err_unknown"] = "unknown";
983
+ })(exports.WebSocketCloseError || (exports.WebSocketCloseError = {}));
984
+ function parseWSClsErr(code) {
985
+ switch (code) {
986
+ case 1001: {
987
+ return exports.WebSocketCloseError.Err_1001;
988
+ }
989
+ case 1002: {
990
+ return exports.WebSocketCloseError.Err_1002;
991
+ }
992
+ case 1003: {
993
+ return exports.WebSocketCloseError.Err_1003;
994
+ }
995
+ case 1006: {
996
+ return exports.WebSocketCloseError.Err_1006;
997
+ }
998
+ case 1007: {
999
+ return exports.WebSocketCloseError.Err_1007;
1000
+ }
1001
+ case 1008: {
1002
+ return exports.WebSocketCloseError.Err_1008;
1003
+ }
1004
+ case 1009: {
1005
+ return exports.WebSocketCloseError.Err_1009;
1006
+ }
1007
+ }
1008
+ return exports.WebSocketCloseError.Err_unknown;
1009
+ }
1010
+
1011
+ /******************************************************************************
1012
+ Copyright (c) Microsoft Corporation.
1013
+
1014
+ Permission to use, copy, modify, and/or distribute this software for any
1015
+ purpose with or without fee is hereby granted.
1016
+
1017
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1018
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1019
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1020
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1021
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1022
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1023
+ PERFORMANCE OF THIS SOFTWARE.
1024
+ ***************************************************************************** */
1025
+
1026
+ function __awaiter(thisArg, _arguments, P, generator) {
1027
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1028
+ return new (P || (P = Promise))(function (resolve, reject) {
1029
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1030
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1031
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1032
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1033
+ });
1034
+ }
1035
+
1036
+ const cache = {};
1037
+ function registerGlobalValue(scheme, callback, once = true) {
1038
+ if (!cache[scheme]) {
1039
+ const uuid = '$jsBridgeFn_' + Date.now().toString(16).toUpperCase() + '_' + Math.ceil(Math.random() * 10000).toString(16).toUpperCase();
1040
+ cache[scheme] = {
1041
+ uuid,
1042
+ queue: [{ once, callback }],
1043
+ };
1044
+ }
1045
+ else {
1046
+ cache[scheme].queue.push({ once, callback });
1047
+ }
1048
+ Object.assign(window, {
1049
+ [cache[scheme].uuid]: (data) => {
1050
+ cache[scheme].queue = cache[scheme].queue.reduce((accu, curr) => {
1051
+ const { once, callback } = curr;
1052
+ if (!once) {
1053
+ accu.push(curr);
1054
+ }
1055
+ callback(data);
1056
+ return accu;
1057
+ }, []);
1058
+ }
1059
+ });
1060
+ return cache[scheme].uuid;
1061
+ }
1062
+
1063
+ class BaseController {
1064
+ checkReady(timeout) {
1065
+ return Promise.resolve([false, null]);
1066
+ }
1067
+ callAndBackfeed(scheme) {
1068
+ return Promise.resolve([false, null]);
1069
+ }
1070
+ callAndListen(scheme, callback) {
1071
+ return Promise.resolve([false, null]);
1072
+ }
1073
+ }
1074
+
1075
+ const HYBRID_BRIDGE_NAME = 'HybridBridgeLJ';
1076
+ const $window$1 = window;
1077
+ class WebViewController extends BaseController {
1078
+ constructor() {
1079
+ super();
1080
+ Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
1081
+ try {
1082
+ yield this.checkBridgeReady();
1083
+ }
1084
+ catch (error) {
1085
+ console.warn(error);
1086
+ }
1087
+ }));
1088
+ }
1089
+ checkBridgeReady(timeout = 6000) {
1090
+ if (this.hybridBridge)
1091
+ return true;
1092
+ const start = performance.now();
1093
+ return new Promise((resolve, reject) => {
1094
+ const check = () => {
1095
+ if (this.hybridBridge)
1096
+ return resolve(true);
1097
+ if ($window$1.HybridBridgeLJ) {
1098
+ const hybridBridge = $window$1[HYBRID_BRIDGE_NAME];
1099
+ hybridBridge === null || hybridBridge === void 0 ? void 0 : hybridBridge.getStaticData(registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
1100
+ this.deviceInfo = JSON.parse(data);
1101
+ this.hybridBridge = hybridBridge;
1102
+ return resolve(true);
1103
+ }));
1104
+ }
1105
+ if (performance.now() - start > (timeout || 6000)) {
1106
+ return reject(new Error('HybridBridge 初始化超时~'));
1107
+ }
1108
+ requestAnimationFrame(check);
1109
+ };
1110
+ check();
1111
+ });
1112
+ }
1113
+ checkReady(timeout = 6000) {
1114
+ return __awaiter(this, void 0, void 0, function* () {
1115
+ const res = [null, null];
1116
+ if (this.hybridBridge) {
1117
+ res[0] = true;
1118
+ return res;
1119
+ }
1120
+ try {
1121
+ res[0] = yield this.checkBridgeReady(timeout);
1122
+ }
1123
+ catch (error) {
1124
+ res[0] = false;
1125
+ res[1] = error;
1126
+ }
1127
+ return res;
1128
+ });
1129
+ }
1130
+ get ready() {
1131
+ return !!this.hybridBridge;
1132
+ }
1133
+ get scheme() {
1134
+ var _a;
1135
+ return ((_a = this.deviceInfo) === null || _a === void 0 ? void 0 : _a.scheme) || '';
1136
+ }
1137
+ createSchemeLink(schemeUrl) {
1138
+ if (schemeUrl.startsWith(this.scheme)) {
1139
+ return schemeUrl;
1140
+ }
1141
+ return this.scheme + '://' + schemeUrl;
1142
+ }
1143
+ callAndBackfeed(scheme) {
1144
+ return __awaiter(this, void 0, void 0, function* () {
1145
+ const res = [false, null];
1146
+ const [ready, readyError] = yield this.checkReady();
1147
+ if (!ready) {
1148
+ res[0] = false;
1149
+ res[1] = readyError;
1150
+ return res;
1151
+ }
1152
+ return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
1153
+ const actionUrl = this.createSchemeLink(scheme);
1154
+ const msg = JSON.stringify({
1155
+ actionUrl,
1156
+ functionName: registerGlobalValue(this.createSchemeLink(scheme), (data) => {
1157
+ const d = (() => {
1158
+ try {
1159
+ return JSON.parse(data);
1160
+ }
1161
+ catch (e) {
1162
+ return data;
1163
+ }
1164
+ })();
1165
+ res[0] = (() => {
1166
+ if (d === 1)
1167
+ return true;
1168
+ if (d === 0)
1169
+ return false;
1170
+ return d;
1171
+ })();
1172
+ resolve(res);
1173
+ }),
1174
+ });
1175
+ this.hybridBridge.callAndBackfeed(msg);
1176
+ }));
1177
+ });
1178
+ }
1179
+ callAndListen(scheme, callback) {
1180
+ return __awaiter(this, void 0, void 0, function* () {
1181
+ const res = [false, null];
1182
+ const [ready, readyError] = yield this.checkReady();
1183
+ if (!ready) {
1184
+ res[0] = false;
1185
+ res[1] = readyError;
1186
+ return res;
1187
+ }
1188
+ return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
1189
+ const actionUrl = this.createSchemeLink(scheme);
1190
+ const _callback = (data) => {
1191
+ const d = (() => {
1192
+ try {
1193
+ return JSON.parse(data);
1194
+ }
1195
+ catch (e) {
1196
+ return data;
1197
+ }
1198
+ })();
1199
+ const callbackParam = (() => {
1200
+ if (d === 1)
1201
+ return true;
1202
+ if (d === 0)
1203
+ return false;
1204
+ return d;
1205
+ })();
1206
+ callback(callbackParam);
1207
+ res[0] = () => {
1208
+ const callbacks = cache[actionUrl];
1209
+ if (!callbacks)
1210
+ return;
1211
+ const idx = callbacks.queue.findIndex((func) => func.callback === _callback);
1212
+ if (idx !== -1) {
1213
+ callbacks.queue.splice(idx, 1);
1214
+ }
1215
+ };
1216
+ resolve(res);
1217
+ };
1218
+ const msg = JSON.stringify({
1219
+ actionUrl,
1220
+ functionName: registerGlobalValue(actionUrl, _callback, false),
1221
+ });
1222
+ this.hybridBridge.callAndListen(msg);
1223
+ }));
1224
+ });
1225
+ }
1226
+ }
1227
+
1228
+ var CallTypeEnum;
1229
+ (function (CallTypeEnum) {
1230
+ CallTypeEnum["callAndBackfeed"] = "callAndBack";
1231
+ CallTypeEnum["callAndListen"] = "callAndListen";
1232
+ })(CallTypeEnum || (CallTypeEnum = {}));
1233
+ const $window = window;
1234
+ class WKWebViewController {
1235
+ constructor() {
1236
+ this.checkBridgeReady();
1237
+ }
1238
+ checkBridgeReady(timeout = 6000) {
1239
+ if (this.worker)
1240
+ return true;
1241
+ const start = performance.now();
1242
+ return new Promise((resolve, reject) => {
1243
+ const check = () => {
1244
+ if (this.worker)
1245
+ return resolve(true);
1246
+ if ($window.webkit &&
1247
+ $window.webkit.messageHandlers &&
1248
+ $window.webkit.messageHandlers.realsee) {
1249
+ const worker = $window.webkit.messageHandlers.realsee;
1250
+ worker.postMessage(JSON.stringify({
1251
+ type: 'getStaticData',
1252
+ param: JSON.stringify({
1253
+ functionName: registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
1254
+ this.deviceInfo = JSON.parse(data);
1255
+ this.worker = worker;
1256
+ return resolve(true);
1257
+ }),
1258
+ }),
1259
+ }));
1260
+ return;
1261
+ }
1262
+ if (performance.now() - start > (timeout || 6000)) {
1263
+ return reject(new Error('HybridBridge 初始化超时~'));
1264
+ }
1265
+ requestAnimationFrame(check);
1266
+ };
1267
+ check();
1268
+ });
1269
+ }
1270
+ checkReady(timeout = 6000) {
1271
+ return __awaiter(this, void 0, void 0, function* () {
1272
+ const res = [null, null];
1273
+ if (this.worker) {
1274
+ res[0] = true;
1275
+ return res;
1276
+ }
1277
+ try {
1278
+ res[0] = yield this.checkBridgeReady(timeout);
1279
+ }
1280
+ catch (error) {
1281
+ res[0] = false;
1282
+ res[1] = error;
1283
+ }
1284
+ return res;
1285
+ });
1286
+ }
1287
+ get ready() {
1288
+ return !!this.worker;
1289
+ }
1290
+ get scheme() {
1291
+ var _a;
1292
+ return ((_a = this.deviceInfo) === null || _a === void 0 ? void 0 : _a.scheme) || '';
1293
+ }
1294
+ createSchemeLink(schemeUrl) {
1295
+ if (schemeUrl.startsWith(this.scheme)) {
1296
+ return schemeUrl;
1297
+ }
1298
+ return this.scheme + '://' + schemeUrl;
1299
+ }
1300
+ callAndBackfeed(scheme) {
1301
+ return __awaiter(this, void 0, void 0, function* () {
1302
+ const res = [false, null];
1303
+ const [ready, readyError] = yield this.checkReady();
1304
+ if (!ready) {
1305
+ res[0] = false;
1306
+ res[1] = readyError;
1307
+ return res;
1308
+ }
1309
+ return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
1310
+ const actionUrl = this.createSchemeLink(scheme);
1311
+ const msg = JSON.stringify({
1312
+ actionUrl,
1313
+ functionName: registerGlobalValue(this.createSchemeLink(scheme), (data) => {
1314
+ const d = (() => {
1315
+ try {
1316
+ return JSON.parse(data);
1317
+ }
1318
+ catch (e) {
1319
+ return data;
1320
+ }
1321
+ })();
1322
+ res[0] = (() => {
1323
+ if (d === 1)
1324
+ return true;
1325
+ if (d === 0)
1326
+ return false;
1327
+ return d;
1328
+ })();
1329
+ resolve(res);
1330
+ }),
1331
+ });
1332
+ this.worker.postMessage(JSON.stringify({
1333
+ type: 'callAndBackfeed',
1334
+ param: msg,
1335
+ }));
1336
+ }));
1337
+ });
1338
+ }
1339
+ callAndListen(scheme, callback) {
1340
+ return __awaiter(this, void 0, void 0, function* () {
1341
+ const res = [false, null];
1342
+ const [ready, readyError] = yield this.checkReady();
1343
+ if (!ready) {
1344
+ res[0] = false;
1345
+ res[1] = readyError;
1346
+ return res;
1347
+ }
1348
+ return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
1349
+ const actionUrl = this.createSchemeLink(scheme);
1350
+ const _callback = (data) => {
1351
+ const d = (() => {
1352
+ try {
1353
+ return JSON.parse(data);
1354
+ }
1355
+ catch (e) {
1356
+ return data;
1357
+ }
1358
+ })();
1359
+ const callbackParam = (() => {
1360
+ if (d === 1)
1361
+ return true;
1362
+ if (d === 0)
1363
+ return false;
1364
+ return d;
1365
+ })();
1366
+ callback(callbackParam);
1367
+ res[0] = () => {
1368
+ const callbacks = cache[actionUrl];
1369
+ if (!callbacks)
1370
+ return;
1371
+ const idx = callbacks.queue.findIndex((func) => func.callback === _callback);
1372
+ if (idx !== -1) {
1373
+ callbacks.queue.splice(idx, 1);
1374
+ }
1375
+ };
1376
+ resolve(res);
1377
+ };
1378
+ const msg = JSON.stringify({
1379
+ actionUrl,
1380
+ functionName: registerGlobalValue(actionUrl, _callback, false),
1381
+ });
1382
+ this.worker.postMessage(JSON.stringify({
1383
+ type: 'callAndListen',
1384
+ param: msg,
1385
+ }));
1386
+ }));
1387
+ });
1388
+ }
1389
+ }
1390
+
1391
+ function S4() {
1392
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
1393
+ }
1394
+ function uuid() {
1395
+ return (S4() + S4() + '-' + S4() + '-4' + S4().substr(0, 3) +
1396
+ '-' + S4() + '-' + S4() + S4() + S4()).toLowerCase();
1397
+ }
1398
+
1399
+ var WeappBridgeMessage;
1400
+ (function (WeappBridgeMessage) {
1401
+ WeappBridgeMessage["isReady"] = "Are You OK?";
1402
+ WeappBridgeMessage["ready"] = "I`m OK!";
1403
+ WeappBridgeMessage["ping"] = "ping";
1404
+ WeappBridgeMessage["pong"] = "pong";
1405
+ WeappBridgeMessage["alive"] = "I`m alive!";
1406
+ })(WeappBridgeMessage || (WeappBridgeMessage = {}));
1407
+
1408
+ const endpoint = 'wss://ws.realsee.com';
1409
+ var defaultWsEndpoint = endpoint;
1410
+
1411
+ const generateWssUrl = (tpl, params) => {
1412
+ const url = Object.keys(params).reduce((res, curr) => res.replace(`{{${curr}}}`, `${params[curr]}`), tpl);
1413
+ return encodeURI(url);
1414
+ };
1415
+ var generateWssUrl$1 = generateWssUrl;
1416
+
1417
+ const isValidKey = (key, object) => key in object;
1418
+ var isValidKey$1 = isValidKey;
1419
+
1420
+ const parseQuery = (query = '') => query
1421
+ .replace('?', '')
1422
+ .split('&')
1423
+ .map((qs) => {
1424
+ const [k, v] = qs.split('=');
1425
+ return { [k]: decodeURIComponent(v) };
1426
+ })
1427
+ .reduce((result, curr) => (Object.assign(Object.assign({}, result), curr)), {});
1428
+ var parseQuery$1 = parseQuery;
1429
+
1430
+ const EVENT_SYMBOL = '$$REALSEE_JSBRIDGE_EVENT$$';
1431
+ function __generateEventIfNotExisted(instance) {
1432
+ if (!instance[EVENT_SYMBOL]) {
1433
+ instance[EVENT_SYMBOL] = {};
1434
+ }
1435
+ return instance[EVENT_SYMBOL];
1436
+ }
1437
+ function __removeEventIfNotExisted(instance) {
1438
+ if (!instance[EVENT_SYMBOL]) {
1439
+ delete instance[EVENT_SYMBOL];
1440
+ }
1441
+ }
1442
+ class Subscribe {
1443
+ hasListener(name) {
1444
+ const events = __generateEventIfNotExisted(this);
1445
+ return events && events[name] && events[name].length > 0;
1446
+ }
1447
+ on(name, callback, once) {
1448
+ const events = __generateEventIfNotExisted(this);
1449
+ if (!events[name])
1450
+ events[name] = [];
1451
+ events[name].push([callback, once || false]);
1452
+ return () => this.off(name, callback);
1453
+ }
1454
+ once(name, callback) {
1455
+ return this.on(name, callback, true);
1456
+ }
1457
+ off(name, callback) {
1458
+ if (name === undefined) {
1459
+ __removeEventIfNotExisted(this);
1460
+ return;
1461
+ }
1462
+ const events = __generateEventIfNotExisted(this);
1463
+ if (!events[name])
1464
+ events[name] = [];
1465
+ if (callback === undefined) {
1466
+ events[name].length = 0;
1467
+ return;
1468
+ }
1469
+ let index = 0;
1470
+ for (; index < events[name].length; index++) {
1471
+ if (events[name][index][0] === callback)
1472
+ break;
1473
+ }
1474
+ if (index < events[name].length) {
1475
+ events[name].splice(index, 1);
1476
+ }
1477
+ }
1478
+ emit(name, ...data) {
1479
+ let canceled = false;
1480
+ const events = __generateEventIfNotExisted(this);
1481
+ const event = events[name] || [];
1482
+ for (const one of event.slice()) {
1483
+ const [callback, once = false] = one;
1484
+ const result = callback(...data);
1485
+ if (once)
1486
+ this.off(name, callback);
1487
+ if (result === false)
1488
+ canceled = true;
1489
+ }
1490
+ return canceled;
1491
+ }
1492
+ }
1493
+
1494
+ class RobustWebSocket$1 extends Subscribe {
1495
+ get attempts() {
1496
+ return this._attempts;
1497
+ }
1498
+ constructor(options) {
1499
+ super();
1500
+ this._options = {
1501
+ timeout: 10000,
1502
+ shouldReconnect: (event, ws) => {
1503
+ if (event.code === 1008 || event.code === 1011)
1504
+ return;
1505
+ return [0, 3000, 10000][ws.attempts];
1506
+ },
1507
+ should1000Reconnect: false,
1508
+ ignoreConnectivityEvents: false,
1509
+ automaticOpen: false,
1510
+ };
1511
+ this._attempts = 0;
1512
+ this._reconnects = -1;
1513
+ this._reconnectWhenOnlineAgain = false;
1514
+ this._explicitlyClosed = false;
1515
+ this._connectivityEventsAttached = false;
1516
+ this._clearPendingReconnectIfNeeded = () => {
1517
+ if (this._pendingReconnect) {
1518
+ clearTimeout(this._pendingReconnect);
1519
+ this._pendingReconnect = undefined;
1520
+ }
1521
+ };
1522
+ this._online = (event) => {
1523
+ if (this._reconnectWhenOnlineAgain) {
1524
+ this._clearPendingReconnectIfNeeded();
1525
+ this._reconnect(event);
1526
+ }
1527
+ };
1528
+ this._offline = () => {
1529
+ var _a;
1530
+ this._reconnectWhenOnlineAgain = true;
1531
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000);
1532
+ };
1533
+ this._detachConnectivityEvents = () => {
1534
+ if (this._connectivityEventsAttached) {
1535
+ globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('online', this._online);
1536
+ globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('offline', this._offline);
1537
+ this._connectivityEventsAttached = false;
1538
+ }
1539
+ };
1540
+ this._attachConnectivityEvents = () => {
1541
+ if (!this._connectivityEventsAttached) {
1542
+ globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('online', this._online);
1543
+ globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('offline', this._offline);
1544
+ this._connectivityEventsAttached = true;
1545
+ }
1546
+ };
1547
+ this.send = (data) => {
1548
+ var _a, _b, _c;
1549
+ if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
1550
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
1551
+ }
1552
+ };
1553
+ this.close = (code, reason) => {
1554
+ var _a;
1555
+ if (typeof code !== 'number') {
1556
+ reason = code;
1557
+ code = 1000;
1558
+ }
1559
+ this._clearPendingReconnectIfNeeded();
1560
+ this._reconnectWhenOnlineAgain = false;
1561
+ this._explicitlyClosed = true;
1562
+ this._detachConnectivityEvents();
1563
+ return (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(code, reason);
1564
+ };
1565
+ this.open = (url) => {
1566
+ var _a, _b;
1567
+ if (url) {
1568
+ this._url = url;
1569
+ }
1570
+ if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) !== WebSocket.OPEN &&
1571
+ ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.readyState) !== WebSocket.CONNECTING) {
1572
+ this._clearPendingReconnectIfNeeded();
1573
+ this._reconnectWhenOnlineAgain = false;
1574
+ this._explicitlyClosed = false;
1575
+ this._createWebSocket();
1576
+ }
1577
+ };
1578
+ this._createWebSocket = () => {
1579
+ var _a, _b, _c;
1580
+ const newUrl = typeof this._url === 'string' ? this._url : (_a = this._url) === null || _a === void 0 ? void 0 : _a.call(this, this);
1581
+ if (!newUrl)
1582
+ return;
1583
+ this._pendingReconnect = undefined;
1584
+ this._removeWebSocketEvent();
1585
+ this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
1586
+ this._attempts = this._attempts + 1;
1587
+ this.emit('connecting', new CustomEvent('connecting', {
1588
+ detail: { attempts: this._attempts, reconnects: this._reconnects },
1589
+ }));
1590
+ const timeoutCallback = () => {
1591
+ this._connectTimeout = undefined;
1592
+ this._detachConnectivityEvents();
1593
+ this.emit('timeout', new CustomEvent('connecting', {
1594
+ detail: {
1595
+ attempts: this._attempts,
1596
+ reconnects: this._reconnects,
1597
+ },
1598
+ }));
1599
+ };
1600
+ this._connectTimeout = setTimeout(timeoutCallback, (_b = this._options) === null || _b === void 0 ? void 0 : _b.timeout);
1601
+ this._dispatchWebSocketEvent();
1602
+ if (!((_c = this._options) === null || _c === void 0 ? void 0 : _c.ignoreConnectivityEvents)) {
1603
+ this._attachConnectivityEvents();
1604
+ }
1605
+ };
1606
+ this._removeWebSocketEvent = () => {
1607
+ var _a, _b, _c, _d;
1608
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
1609
+ (_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
1610
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
1611
+ (_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
1612
+ };
1613
+ this._dispatchWebSocketEvent = () => {
1614
+ var _a, _b, _c, _d;
1615
+ (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.addEventListener('open', this._webSocketOpenHandler);
1616
+ (_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.addEventListener('close', this._webSocketCloseHandler);
1617
+ (_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.addEventListener('error', this._webSocketErrorHandler);
1618
+ (_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.addEventListener('message', this._webSocketMessageHandler);
1619
+ };
1620
+ this._webSocketOpenHandler = (event) => {
1621
+ if (this._connectTimeout) {
1622
+ clearTimeout(this._connectTimeout);
1623
+ this._connectTimeout = undefined;
1624
+ }
1625
+ const reconnects = ++this._reconnects;
1626
+ const attempts = this._attempts;
1627
+ this._attempts = 0;
1628
+ this._reconnectWhenOnlineAgain = false;
1629
+ return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
1630
+ };
1631
+ this._webSocketCloseHandler = (event) => {
1632
+ this._reconnect(event);
1633
+ return this.emit('close', event);
1634
+ };
1635
+ this._webSocketErrorHandler = (event) => {
1636
+ return this.emit('error', new CustomEvent('error', { detail: { error: event } }));
1637
+ };
1638
+ this._webSocketMessageHandler = (event) => {
1639
+ return this.emit('message', event);
1640
+ };
1641
+ if (options) {
1642
+ this.setOptions(options);
1643
+ }
1644
+ }
1645
+ setOptions(options) {
1646
+ if (!options)
1647
+ return;
1648
+ this._url = options.url;
1649
+ this._protocols = options.protocols;
1650
+ const opts = Object.assign(this._options, options.robustOptions || {});
1651
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.timeout) !== 'number') {
1652
+ throw new Error('timeout must be the number of milliseconds to timeout a connection attempt');
1653
+ }
1654
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.shouldReconnect) !== 'function') {
1655
+ throw new Error('shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.');
1656
+ }
1657
+ this._options = opts;
1658
+ if (this._options.automaticOpen) {
1659
+ this._createWebSocket();
1660
+ }
1661
+ }
1662
+ _reconnect(event) {
1663
+ var _a, _b, _c, _d;
1664
+ if ((!((_a = this._options) === null || _a === void 0 ? void 0 : _a.should1000Reconnect) && event.code === 1000) ||
1665
+ this._explicitlyClosed) {
1666
+ this._attempts = 0;
1667
+ return;
1668
+ }
1669
+ if (((_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _b === void 0 ? void 0 : _b.onLine) === false) {
1670
+ this._reconnectWhenOnlineAgain = true;
1671
+ return;
1672
+ }
1673
+ const delay = (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.shouldReconnect) === null || _d === void 0 ? void 0 : _d.call(_c, event, this);
1674
+ if (typeof delay === 'number') {
1675
+ this._pendingReconnect = setTimeout(this._createWebSocket, delay);
1676
+ }
1677
+ }
1678
+ }
1679
+
1680
+ class HybridBridge {
1681
+ get isReady() {
1682
+ return this._readyState === 'open';
1683
+ }
1684
+ constructor() {
1685
+ var _a, _b;
1686
+ this._rsWeappBridgeMethodAdapter = {};
1687
+ this._ws = new RobustWebSocket$1();
1688
+ this._readyState = 'close';
1689
+ this.initialize = (timeout = 6000) => __awaiter(this, void 0, void 0, function* () {
1690
+ const res = [false, null];
1691
+ const { wssid, wstsp, wssig, wsmnt = defaultWsEndpoint, } = parseQuery$1(globalThis.location.search);
1692
+ if (!(wssid && wstsp && wssig && wsmnt)) {
1693
+ res[1] = new Error('HybridBridge 参数缺失,初始化失败~');
1694
+ return res;
1695
+ }
1696
+ const url = generateWssUrl$1('{{origin}}/{{endpoint}}/{{uuid}}/{{member}}/{{ak}}/{{ts}}/{{sign}}', {
1697
+ origin: wsmnt,
1698
+ endpoint: 'proxy',
1699
+ uuid: wssid,
1700
+ member: 'webview',
1701
+ ak: 'vr_live_miniapp',
1702
+ ts: wstsp,
1703
+ sign: wssig,
1704
+ });
1705
+ try {
1706
+ const result = yield this._open(url);
1707
+ if (result) {
1708
+ this.initBuiltInHandlers();
1709
+ res[0] = yield this.waitReady(timeout);
1710
+ }
1711
+ else {
1712
+ res[1] = new Error('HybridBridge ws未连接,初始化失败~');
1713
+ }
1714
+ }
1715
+ catch (e) {
1716
+ res[1] = e;
1717
+ }
1718
+ return res;
1719
+ });
1720
+ this.initBuiltInHandlers = () => {
1721
+ this._registerLifecycleHandler();
1722
+ this._registerHeartbeatHandler();
1723
+ this._registerMessageHandler();
1724
+ this._registerBridgeRequestHandler();
1725
+ this._registerReadyHandler();
1726
+ };
1727
+ this._open = (url) => new Promise((resolve) => {
1728
+ const handleOpen = () => {
1729
+ this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true), true);
1730
+ this._ws.once('timeout', () => resolve(false));
1731
+ this.send(WeappBridgeMessage.isReady);
1732
+ };
1733
+ this._ws.once('open', handleOpen);
1734
+ this._ws.open(url);
1735
+ });
1736
+ this._registerLifecycleHandler = () => {
1737
+ this._ws.on('connecting', () => {
1738
+ console.log('RsWeappBridge connecting');
1739
+ this._readyState = 'connecting';
1740
+ });
1741
+ this._ws.on('open', () => {
1742
+ console.log('RsWeappBridge open');
1743
+ this._readyState = 'open';
1744
+ });
1745
+ this._ws.on('close', () => {
1746
+ this._readyState = 'close';
1747
+ });
1748
+ this._ws.on('error', () => {
1749
+ console.log('RsWeappBridge error');
1750
+ this._readyState = 'close';
1751
+ });
1752
+ this._ws.on('timeout', () => {
1753
+ console.log('RsWeappBridge timeout');
1754
+ this._readyState = 'close';
1755
+ });
1756
+ };
1757
+ this._registerHeartbeatHandler = () => {
1758
+ this._receivedMessage(WeappBridgeMessage.ping, () => setTimeout(() => this._ws.send(WeappBridgeMessage.pong), 500));
1759
+ this._receivedMessage(WeappBridgeMessage.pong, () => setTimeout(() => this._ws.send(WeappBridgeMessage.ping), 1000));
1760
+ };
1761
+ this._receivedMessage = (targetMessage, handler, once) => {
1762
+ const msgHandler = (evnet) => {
1763
+ if (evnet.data === targetMessage) {
1764
+ handler();
1765
+ if (once) {
1766
+ this._ws.off('message', msgHandler);
1767
+ }
1768
+ }
1769
+ };
1770
+ this._ws.on('message', msgHandler);
1771
+ };
1772
+ this._registerReadyHandler = () => {
1773
+ this._receivedMessage(WeappBridgeMessage.isReady, () => this._ws.send(WeappBridgeMessage.ready));
1774
+ };
1775
+ this.send = (data) => {
1776
+ this._ws.send(data);
1777
+ };
1778
+ this.waitReady = (timeout = 6000) => {
1779
+ return new Promise((resolve, reject) => {
1780
+ this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true));
1781
+ this.send(WeappBridgeMessage.isReady);
1782
+ setTimeout(() => reject('HybridBridge 初始化超时~'), timeout);
1783
+ });
1784
+ };
1785
+ this._parseMessage = (event) => {
1786
+ try {
1787
+ return JSON.parse(event.data);
1788
+ }
1789
+ catch (e) {
1790
+ return event.data;
1791
+ }
1792
+ };
1793
+ this._registerMessageHandler = () => {
1794
+ this._ws.on('message', (event) => {
1795
+ const message = this._parseMessage(event);
1796
+ if (typeof message === 'object') {
1797
+ const { id, command, data } = message;
1798
+ if (command === 'message' &&
1799
+ typeof this._rsWeappBridgeMethodAdapter.bindMessage === 'function') {
1800
+ this._rsWeappBridgeMethodAdapter.bindMessage({ id, data });
1801
+ }
1802
+ }
1803
+ });
1804
+ };
1805
+ this.getStaticData = (callbackFunctionName) => {
1806
+ this.callAndBackfeed(JSON.stringify({
1807
+ actionUrl: 'common/staticData',
1808
+ functionName: callbackFunctionName,
1809
+ }));
1810
+ };
1811
+ this.callAndBackfeed = (msg) => {
1812
+ const { actionUrl = '', functionName = '' } = JSON.parse(msg);
1813
+ if (!actionUrl)
1814
+ throw new Error('callAndBackfeed actionUrl is empty!');
1815
+ if (!functionName)
1816
+ throw new Error('callAndBackfeed functionName is empty!');
1817
+ const callback = (result) => {
1818
+ if (typeof globalThis[functionName] === 'function') {
1819
+ globalThis[functionName](result);
1820
+ }
1821
+ };
1822
+ this._callAndBackfeed(actionUrl, callback);
1823
+ };
1824
+ this.callAndListen = (msg) => {
1825
+ const { actionUrl, functionName } = JSON.parse(msg);
1826
+ if (!actionUrl)
1827
+ throw new Error('callAndListen actionUrl is empty!');
1828
+ if (!functionName)
1829
+ throw new Error('callAndListen functionName is empty!');
1830
+ const callback = (result) => {
1831
+ if (typeof globalThis[functionName] === 'function') {
1832
+ globalThis[functionName](result);
1833
+ }
1834
+ };
1835
+ try {
1836
+ this._callAndListen(actionUrl, callback);
1837
+ }
1838
+ catch (e) {
1839
+ console.warn(e);
1840
+ callback(false);
1841
+ }
1842
+ };
1843
+ this.execute = (method, args) => __awaiter(this, void 0, void 0, function* () { return yield this._invokeBridgeMethod(method, args); });
1844
+ this._invokeBridgeMethod = (method, args) => new Promise((success, fail) => {
1845
+ const id = uuid();
1846
+ const wsBridgeResponsehandler = (event) => {
1847
+ const result = this._parseMessage(event);
1848
+ if (typeof result === 'object') {
1849
+ if (result.method === method && result.id === id) {
1850
+ this._ws.off('message', wsBridgeResponsehandler);
1851
+ result.error ? fail(result.error) : success(result.data);
1852
+ }
1853
+ }
1854
+ };
1855
+ this._ws.on('message', wsBridgeResponsehandler);
1856
+ this.send(JSON.stringify({ method, args, id }));
1857
+ });
1858
+ if (((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) === null || _a === void 0 ? void 0 : _a.__Realsee_WxMini_HybridBridge__) instanceof HybridBridge) {
1859
+ return (_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) === null || _b === void 0 ? void 0 : _b.__Realsee_WxMini_HybridBridge__;
1860
+ }
1861
+ if (globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) {
1862
+ globalThis.window.__Realsee_WxMini_HybridBridge__ = this;
1863
+ this.initBuiltInHandlers();
1864
+ }
1865
+ }
1866
+ _registerBridgeRequestHandler() {
1867
+ this._ws.on('message', (event) => __awaiter(this, void 0, void 0, function* () {
1868
+ const request = this._parseMessage(event);
1869
+ if (typeof request === 'object') {
1870
+ const { id, method, args, command } = request;
1871
+ if (command === 'request') {
1872
+ if (method) {
1873
+ let result = null;
1874
+ let error = null;
1875
+ let _method = null;
1876
+ if (typeof this._rsWeappBridgeMethodAdapter[method] === 'function') {
1877
+ _method = this._rsWeappBridgeMethodAdapter[method];
1878
+ }
1879
+ else if (globalThis && isValidKey$1(method, globalThis)) {
1880
+ _method = globalThis[method];
1881
+ }
1882
+ if (typeof _method === 'function') {
1883
+ try {
1884
+ result = yield _method(args);
1885
+ }
1886
+ catch (e) {
1887
+ error = e.message || e;
1888
+ }
1889
+ }
1890
+ else {
1891
+ error = 'Method not implemented.';
1892
+ }
1893
+ this.send(JSON.stringify({
1894
+ id,
1895
+ method,
1896
+ result,
1897
+ error,
1898
+ command: 'response',
1899
+ }));
1900
+ }
1901
+ }
1902
+ }
1903
+ }));
1904
+ }
1905
+ _callAndBackfeed(actionUrl, backfeed) {
1906
+ const reqId = uuid();
1907
+ const data = JSON.stringify({
1908
+ id: reqId,
1909
+ actionUrl,
1910
+ command: 'rsSchemeRequest',
1911
+ type: 'callAndBackfeed',
1912
+ });
1913
+ let timer = null;
1914
+ const callback = (event) => {
1915
+ const message = this._parseMessage(event);
1916
+ if (typeof message === 'object') {
1917
+ const { id, result, errmsg, command } = message;
1918
+ if (command === 'rsSchemeResponse' && id === reqId) {
1919
+ this._ws.off('message', callback);
1920
+ if (timer)
1921
+ clearTimeout(timer);
1922
+ if (errmsg) {
1923
+ console.warn(errmsg);
1924
+ backfeed(0);
1925
+ }
1926
+ else {
1927
+ backfeed(result);
1928
+ }
1929
+ }
1930
+ }
1931
+ };
1932
+ this._ws.on('message', callback);
1933
+ this.send(data);
1934
+ timer = globalThis.setTimeout(() => {
1935
+ console.warn('callAndBackfeed timeout');
1936
+ backfeed(0);
1937
+ }, 30000);
1938
+ }
1939
+ _callAndListen(actionUrl, fn) {
1940
+ const reqId = uuid();
1941
+ const data = JSON.stringify({
1942
+ id: reqId,
1943
+ actionUrl,
1944
+ command: 'rsSchemeRequest',
1945
+ type: 'callAndListen',
1946
+ });
1947
+ const callback = (event) => {
1948
+ const message = this._parseMessage(event);
1949
+ if (typeof message === 'object') {
1950
+ const { id, result, errmsg, command } = message;
1951
+ if (command === 'rsSchemeResponse' && id === reqId) {
1952
+ if (errmsg) {
1953
+ console.warn(errmsg);
1954
+ fn(false);
1955
+ }
1956
+ else {
1957
+ fn(result);
1958
+ }
1959
+ }
1960
+ }
1961
+ };
1962
+ this._ws.on('message', callback);
1963
+ this.send(data);
1964
+ }
1965
+ invoke(method, args) {
1966
+ return __awaiter(this, void 0, void 0, function* () {
1967
+ return new Promise((success, fail) => {
1968
+ const reqId = uuid();
1969
+ const data = JSON.stringify({
1970
+ id: reqId,
1971
+ method,
1972
+ args,
1973
+ command: 'request',
1974
+ });
1975
+ let timer = null;
1976
+ const callback = (event) => {
1977
+ const message = this._parseMessage(event);
1978
+ if (typeof message === 'object') {
1979
+ const { id, result, error, command } = message;
1980
+ if (command === 'response' &&
1981
+ id === reqId &&
1982
+ message.method === method) {
1983
+ this._ws.off('message', callback);
1984
+ if (timer)
1985
+ clearTimeout(timer);
1986
+ if (error) {
1987
+ fail(error);
1988
+ }
1989
+ else {
1990
+ success(result);
1991
+ }
1992
+ }
1993
+ }
1994
+ };
1995
+ this._ws.on('message', callback);
1996
+ this.send(data);
1997
+ timer = setTimeout(() => fail('method invoke timeout'), 30000);
1998
+ });
1999
+ });
2000
+ }
2001
+ }
2002
+
2003
+ class WxMiniprogramController extends BaseController {
2004
+ constructor() {
2005
+ super(...arguments);
2006
+ this._hybridBridge = new HybridBridge();
2007
+ this.initializing = false;
2008
+ }
2009
+ get hybridBridge() {
2010
+ return this._hybridBridge;
2011
+ }
2012
+ checkBridgeReady(timeout = 60000) {
2013
+ if (this.ready)
2014
+ return true;
2015
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
2016
+ if (this.ready)
2017
+ return resolve(true);
2018
+ if (this.initializing) {
2019
+ const check = () => {
2020
+ if (this.ready)
2021
+ return resolve(true);
2022
+ requestAnimationFrame(check);
2023
+ };
2024
+ check();
2025
+ }
2026
+ else {
2027
+ this.initializing = true;
2028
+ const [res, error] = yield this._hybridBridge.initialize(timeout);
2029
+ if (!res || error) {
2030
+ throw error || new Error('HybridBridge 初始化失败~');
2031
+ }
2032
+ this._hybridBridge.getStaticData(registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
2033
+ this.deviceInfo = (() => {
2034
+ try {
2035
+ return JSON.parse(data);
2036
+ }
2037
+ catch (e) {
2038
+ return data;
2039
+ }
2040
+ })();
2041
+ }));
2042
+ this.initializing = false;
2043
+ return resolve(true);
2044
+ }
2045
+ }));
2046
+ }
2047
+ checkReady(timeout = 60000) {
2048
+ return __awaiter(this, void 0, void 0, function* () {
2049
+ const res = [null, null];
2050
+ if (this.ready) {
2051
+ res[0] = true;
2052
+ return res;
2053
+ }
2054
+ try {
2055
+ res[0] = yield this.checkBridgeReady(timeout);
2056
+ }
2057
+ catch (error) {
2058
+ res[0] = false;
2059
+ res[1] = error;
2060
+ }
2061
+ return res;
2062
+ });
2063
+ }
2064
+ get ready() {
2065
+ return !!this._hybridBridge.isReady;
2066
+ }
2067
+ get scheme() {
2068
+ var _a;
2069
+ return ((_a = this.deviceInfo) === null || _a === void 0 ? void 0 : _a.scheme) || '';
2070
+ }
2071
+ createSchemeLink(schemeUrl) {
2072
+ if (schemeUrl.startsWith(this.scheme)) {
2073
+ return schemeUrl;
2074
+ }
2075
+ return this.scheme + '://' + schemeUrl;
2076
+ }
2077
+ callAndBackfeed(scheme) {
2078
+ return __awaiter(this, void 0, void 0, function* () {
2079
+ const res = [false, null];
2080
+ const [ready, readyError] = yield this.checkReady();
2081
+ if (!ready) {
2082
+ res[0] = false;
2083
+ res[1] = readyError;
2084
+ return res;
2085
+ }
2086
+ return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
2087
+ const actionUrl = this.createSchemeLink(scheme);
2088
+ const msg = JSON.stringify({
2089
+ actionUrl,
2090
+ functionName: registerGlobalValue(this.createSchemeLink(scheme), (data) => {
2091
+ let d = data;
2092
+ try {
2093
+ d = JSON.parse(data);
2094
+ }
2095
+ catch (e) {
2096
+ }
2097
+ res[0] = (() => {
2098
+ if (d === 1)
2099
+ return true;
2100
+ if (d === 0)
2101
+ return false;
2102
+ return d;
2103
+ })();
2104
+ resolve(res);
2105
+ }),
2106
+ });
2107
+ this._hybridBridge.callAndBackfeed(msg);
2108
+ }));
2109
+ });
2110
+ }
2111
+ callAndListen(scheme, callback) {
2112
+ return __awaiter(this, void 0, void 0, function* () {
2113
+ const res = [false, null];
2114
+ const [ready, readyError] = yield this.checkReady();
2115
+ if (!ready) {
2116
+ res[0] = false;
2117
+ res[1] = readyError;
2118
+ return res;
2119
+ }
2120
+ return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
2121
+ const actionUrl = this.createSchemeLink(scheme);
2122
+ const _callback = (data) => {
2123
+ let d = data;
2124
+ try {
2125
+ d = JSON.parse(data);
2126
+ }
2127
+ catch (e) {
2128
+ }
2129
+ const callbackParam = (() => {
2130
+ if (d === 1)
2131
+ return true;
2132
+ if (d === 0)
2133
+ return false;
2134
+ return d;
2135
+ })();
2136
+ callback(callbackParam);
2137
+ res[0] = () => {
2138
+ const callbacks = cache[actionUrl];
2139
+ if (!callbacks)
2140
+ return;
2141
+ const idx = callbacks.queue.findIndex((func) => func.callback === _callback);
2142
+ if (idx !== -1) {
2143
+ callbacks.queue.splice(idx, 1);
2144
+ }
2145
+ };
2146
+ resolve(res);
2147
+ };
2148
+ const msg = JSON.stringify({
2149
+ actionUrl,
2150
+ functionName: registerGlobalValue(actionUrl, _callback, false),
2151
+ });
2152
+ this._hybridBridge.callAndListen(msg);
2153
+ }));
2154
+ });
2155
+ }
2156
+ invoke(method, data) {
2157
+ var _a, _b;
2158
+ return __awaiter(this, void 0, void 0, function* () {
2159
+ const [ready, readyError] = yield this.checkReady();
2160
+ if (!ready) {
2161
+ throw readyError;
2162
+ }
2163
+ else {
2164
+ return (yield ((_b = (_a = this._hybridBridge).invoke) === null || _b === void 0 ? void 0 : _b.call(_a, method, data)));
2165
+ }
2166
+ });
2167
+ }
2168
+ }
2169
+
2170
+ var WebViewTypeEnum;
2171
+ (function (WebViewTypeEnum) {
2172
+ WebViewTypeEnum["WebView"] = "WebKit";
2173
+ WebViewTypeEnum["WKWebview"] = "WKWebview";
2174
+ WebViewTypeEnum["UIWebview"] = "UIWebview";
2175
+ WebViewTypeEnum["Browser"] = "Browser";
2176
+ WebViewTypeEnum["WeChatMPWebView"] = "WxMiniProgramWebView";
2177
+ WebViewTypeEnum["Unsupported"] = "Unsupported";
2178
+ })(WebViewTypeEnum || (WebViewTypeEnum = {}));
2179
+
2180
+ class JSBridgeCore extends Subscribe {
2181
+ constructor() {
2182
+ super(...arguments);
2183
+ this.webViewType = WebViewTypeEnum.Unsupported;
2184
+ }
2185
+ }
2186
+
2187
+ const userAgent$1 = globalThis.navigator.userAgent;
2188
+ const isAndroid$1 = /android/gi.test(userAgent$1);
2189
+ const isIOS$1 = /iPhone|iPad\s+OS/gi.test(userAgent$1);
2190
+ const isWxMiniProgram$1 = /MicroMessenger/gi.test(userAgent$1) && /miniProgram/gi.test(userAgent$1);
2191
+ const isRealseeVRWebview$1 = /realsee/gi.test(userAgent$1);
2192
+
2193
+ const defaultOptions$1 = {
2194
+ timeout: 6000,
2195
+ };
2196
+ class JSBridgeApp extends JSBridgeCore {
2197
+ constructor(options = {}) {
2198
+ super();
2199
+ this.options = Object.assign(defaultOptions$1, options);
2200
+ if (!isRealseeVRWebview$1) {
2201
+ console.warn('未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... ');
2202
+ }
2203
+ this.webViewType = (() => {
2204
+ if (isAndroid$1)
2205
+ return WebViewTypeEnum.WebView;
2206
+ if (isIOS$1)
2207
+ return WebViewTypeEnum.WKWebview;
2208
+ return WebViewTypeEnum.Browser;
2209
+ })();
2210
+ this._controller = (() => {
2211
+ if (isAndroid$1)
2212
+ return new WebViewController();
2213
+ if (isIOS$1)
2214
+ return new WKWebViewController();
2215
+ return new BaseController();
2216
+ })();
2217
+ this.callAndListen('common/webViewState', (webviewState) => {
2218
+ this.emit('webViewStateChange', webviewState);
2219
+ });
2220
+ this.callAndListen('common/webViewError', (errorInfo) => {
2221
+ this.emit('error', errorInfo);
2222
+ });
2223
+ }
2224
+ ready() {
2225
+ return __awaiter(this, void 0, void 0, function* () {
2226
+ return yield this._controller.checkReady(this.options.timeout);
2227
+ });
2228
+ }
2229
+ callAndBackfeed(schemeUrl) {
2230
+ return __awaiter(this, void 0, void 0, function* () {
2231
+ return yield this._controller.callAndBackfeed(schemeUrl);
2232
+ });
2233
+ }
2234
+ callAndListen(schemeUrl, callback) {
2235
+ var _a;
2236
+ return __awaiter(this, void 0, void 0, function* () {
2237
+ return yield ((_a = this._controller) === null || _a === void 0 ? void 0 : _a.callAndListen(schemeUrl, callback));
2238
+ });
2239
+ }
2240
+ setLeftTopBackButton(enable) {
2241
+ return __awaiter(this, void 0, void 0, function* () {
2242
+ if (this.webViewType === WebViewTypeEnum.WebView) {
2243
+ return [true, null];
2244
+ }
2245
+ return yield this.callAndBackfeed(`common/setLeftTopBackButton?enable=${enable ? 1 : 0}`);
2246
+ });
2247
+ }
2248
+ getBangsHeight() {
2249
+ return __awaiter(this, void 0, void 0, function* () {
2250
+ return yield this.callAndBackfeed('common/getBangsHeight');
2251
+ });
2252
+ }
2253
+ shock(duration = 4) {
2254
+ return __awaiter(this, void 0, void 0, function* () {
2255
+ return yield this.callAndBackfeed(`common/shock?duration=${duration}`);
2256
+ });
2257
+ }
2258
+ minimize() {
2259
+ return __awaiter(this, void 0, void 0, function* () {
2260
+ return yield this.callAndBackfeed(`common/minimize`);
2261
+ });
2262
+ }
2263
+ loadProgress(progress) {
2264
+ return __awaiter(this, void 0, void 0, function* () {
2265
+ progress = progress < 0 ? 0 : progress > 100 ? 100 : progress;
2266
+ return yield this.callAndBackfeed(`common/loadProgress?progress=${progress}`);
2267
+ });
2268
+ }
2269
+ closeLoading() {
2270
+ return __awaiter(this, void 0, void 0, function* () {
2271
+ return yield this.callAndBackfeed(`common/closeLoading`);
2272
+ });
2273
+ }
2274
+ setOrientation(orientation) {
2275
+ return __awaiter(this, void 0, void 0, function* () {
2276
+ return yield this.callAndBackfeed(`common/setOrientation?orientation=${orientation}`);
2277
+ });
2278
+ }
2279
+ keepScreenLight(enable) {
2280
+ return __awaiter(this, void 0, void 0, function* () {
2281
+ return yield this.callAndBackfeed(`common/keepScreenLight?enable=${enable ? 1 : 0}`);
2282
+ });
2283
+ }
2284
+ closeWebView() {
2285
+ return __awaiter(this, void 0, void 0, function* () {
2286
+ return yield this.callAndBackfeed(`common/closeWebView`);
2287
+ });
2288
+ }
2289
+ openWebView(url, way) {
2290
+ return __awaiter(this, void 0, void 0, function* () {
2291
+ return yield this.callAndBackfeed(`common/openWebView?way=${way}&url=${encodeURIComponent(url)}`);
2292
+ });
2293
+ }
2294
+ saveImage2Album(base64) {
2295
+ return __awaiter(this, void 0, void 0, function* () {
2296
+ return yield this.callAndBackfeed(`common/saveImage2Album?base64=${base64}`);
2297
+ });
2298
+ }
2299
+ actionShare(shareConfig) {
2300
+ return __awaiter(this, void 0, void 0, function* () {
2301
+ return yield this.callAndBackfeed(`common/actionShare?json=${JSON.stringify(shareConfig)}`);
2302
+ });
2303
+ }
2304
+ getDeviceInfo() {
2305
+ return __awaiter(this, void 0, void 0, function* () {
2306
+ return yield this.callAndBackfeed(`common/getDeviceInfo`);
2307
+ });
2308
+ }
2309
+ getUserInfo() {
2310
+ return __awaiter(this, void 0, void 0, function* () {
2311
+ return yield this.callAndBackfeed(`common/getUserInfo`);
2312
+ });
2313
+ }
2314
+ getWebViewState() {
2315
+ return __awaiter(this, void 0, void 0, function* () {
2316
+ return yield this.callAndBackfeed(`common/getWebViewState`);
2317
+ });
2318
+ }
2319
+ login() {
2320
+ return __awaiter(this, void 0, void 0, function* () {
2321
+ const res = yield this.callAndBackfeed(`common/login`);
2322
+ if (res[0]) {
2323
+ return yield this.getUserInfo();
2324
+ }
2325
+ return res;
2326
+ });
2327
+ }
2328
+ logout() {
2329
+ return __awaiter(this, void 0, void 0, function* () {
2330
+ return yield this.callAndBackfeed(`common/logout`);
2331
+ });
2332
+ }
2333
+ detectMicro() {
2334
+ return __awaiter(this, void 0, void 0, function* () {
2335
+ return yield this.callAndBackfeed(`common/detectMicro`);
2336
+ });
2337
+ }
2338
+ preload(urls) {
2339
+ return __awaiter(this, void 0, void 0, function* () {
2340
+ urls = urls.map((url) => {
2341
+ if (url.startsWith('//')) {
2342
+ return 'https:' + url;
2343
+ }
2344
+ return url;
2345
+ });
2346
+ return yield this.callAndBackfeed(`common/preload?urls=${JSON.stringify(urls)}`);
2347
+ });
2348
+ }
2349
+ createCacheProxyUrl(urls) {
2350
+ urls = Array.isArray(urls) ? urls : [urls];
2351
+ const userAgent = window.navigator.userAgent;
2352
+ if (!/supportCache/i.test(userAgent)) {
2353
+ return urls;
2354
+ }
2355
+ const proxyCache = (url) => {
2356
+ if (this.webViewType === WebViewTypeEnum.WKWebview) {
2357
+ return url.replace(/https*:/, '').replace(/\/\//, 'realseeproxycache://');
2358
+ }
2359
+ else if (this.webViewType === WebViewTypeEnum.WebView) {
2360
+ return url + (url.indexOf('?') !== -1 ? '&' : '?') + 'realseeproxycache=1';
2361
+ }
2362
+ return url;
2363
+ };
2364
+ return urls.map(proxyCache);
2365
+ }
2366
+ }
2367
+
2368
+ var OpenWebViewEnum;
2369
+ (function (OpenWebViewEnum) {
2370
+ OpenWebViewEnum["Append"] = "Append";
2371
+ OpenWebViewEnum["Replace"] = "Replace";
2372
+ OpenWebViewEnum["Single"] = "Single";
2373
+ })(OpenWebViewEnum || (OpenWebViewEnum = {}));
2374
+
2375
+ class JSBridgeBrowser extends JSBridgeCore {
2376
+ constructor() {
2377
+ super(...arguments);
2378
+ this.webViewType = WebViewTypeEnum.Browser;
2379
+ }
2380
+ ready() {
2381
+ return Promise.resolve([true, null]);
2382
+ }
2383
+ callAndBackfeed(schemeUrl) {
2384
+ return Promise.resolve([false, null]);
2385
+ }
2386
+ callAndListen(schemeUrl, callback) {
2387
+ return Promise.resolve([() => void 0, null]);
2388
+ }
2389
+ loadProgress(progress) {
2390
+ return Promise.resolve([true, null]);
2391
+ }
2392
+ closeLoading() {
2393
+ return Promise.resolve([true, null]);
2394
+ }
2395
+ getDeviceInfo() {
2396
+ return Promise.resolve([false, null]);
2397
+ }
2398
+ getWebViewState() {
2399
+ return Promise.resolve([false, null]);
2400
+ }
2401
+ setLeftTopBackButton(enable) {
2402
+ return Promise.resolve([false, null]);
2403
+ }
2404
+ login() {
2405
+ return Promise.resolve([false, null]);
2406
+ }
2407
+ logout() {
2408
+ return Promise.resolve([false, null]);
2409
+ }
2410
+ getUserInfo() {
2411
+ return Promise.resolve([false, null]);
2412
+ }
2413
+ openWebView(url, way) {
2414
+ switch (way) {
2415
+ case OpenWebViewEnum.Replace:
2416
+ case OpenWebViewEnum.Single: {
2417
+ setTimeout(() => globalThis.location.replace(url), 200);
2418
+ break;
2419
+ }
2420
+ case OpenWebViewEnum.Append:
2421
+ default: {
2422
+ setTimeout(() => (globalThis.location.href = url), 200);
2423
+ break;
2424
+ }
2425
+ }
2426
+ return Promise.resolve([true, null]);
2427
+ }
2428
+ closeWebView() {
2429
+ globalThis.close();
2430
+ return Promise.resolve([true, null]);
2431
+ }
2432
+ getBangsHeight() {
2433
+ return Promise.resolve([0, null]);
2434
+ }
2435
+ setOrientation(orientation) {
2436
+ return Promise.resolve([false, null]);
2437
+ }
2438
+ keepScreenLight(enable) {
2439
+ return Promise.resolve([false, null]);
2440
+ }
2441
+ shock(duration) {
2442
+ return Promise.resolve([false, null]);
2443
+ }
2444
+ minimize() {
2445
+ return Promise.resolve([false, null]);
2446
+ }
2447
+ saveImage2Album(base64) {
2448
+ return Promise.resolve([false, null]);
2449
+ }
2450
+ detectMicro() {
2451
+ return new Promise((resolve) => {
2452
+ const rule = { audio: true, video: false };
2453
+ try {
2454
+ globalThis.navigator.mediaDevices
2455
+ .getUserMedia(rule)
2456
+ .then(() => resolve([true, null]))
2457
+ .catch((e) => resolve([false, e]));
2458
+ }
2459
+ catch (e) {
2460
+ console.error(e);
2461
+ resolve([false, e]);
2462
+ }
2463
+ });
2464
+ }
2465
+ actionShare(shareConfig) {
2466
+ return Promise.resolve([false, null]);
2467
+ }
2468
+ preload(urls) {
2469
+ return Promise.resolve([false, null]);
2470
+ }
2471
+ createCacheProxyUrl(urls) {
2472
+ return [];
863
2473
  }
864
2474
  }
865
2475
 
866
- exports.LiveState = void 0;
867
- (function (LiveState) {
868
- LiveState[LiveState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
869
- /**
870
- * 正在链接中
871
- */
872
- LiveState[LiveState["CONNECTING"] = 0] = "CONNECTING";
873
- /**
874
- * 已经链接并且可以通讯
875
- */
876
- LiveState[LiveState["OPEN"] = 1] = "OPEN";
877
- /**
878
- * 连接已关闭或者链接失败
879
- */
880
- LiveState[LiveState["CLOSED"] = 3] = "CLOSED";
881
- })(exports.LiveState || (exports.LiveState = {}));
882
-
883
- /**
884
- * 用户当前状态枚举。
885
- */
886
- exports.UserStatus = void 0;
887
- (function (UserStatus) {
888
- /**
889
- * 正常
890
- */
891
- UserStatus[UserStatus["Normal"] = 0] = "Normal";
892
- /**
893
- * 被移除
894
- */
895
- UserStatus[UserStatus["Removed"] = 1] = "Removed";
896
- /**
897
- * 被替换
898
- */
899
- UserStatus[UserStatus["Replaced"] = 2] = "Replaced";
900
- })(exports.UserStatus || (exports.UserStatus = {}));
901
- exports.MemUserStatus = void 0;
902
- (function (MemUserStatus) {
903
- MemUserStatus["WAIT_ENTER"] = "WAIT_ENTER";
904
- MemUserStatus["ONLINE"] = "ONLINE";
905
- MemUserStatus["LEAVE"] = "LEAVE";
906
- MemUserStatus["KICK_OUT"] = "KICK_OUT";
907
- MemUserStatus["BE_REPLACE"] = "BE_REPLACE";
908
- MemUserStatus["EXCEPTION"] = "EXCEPTION";
909
- })(exports.MemUserStatus || (exports.MemUserStatus = {}));
910
-
911
- /**
912
- * WebSocket 连接状态枚举
913
- */
914
- exports.WebSocketState = void 0;
915
- (function (WebSocketState) {
916
- /**
917
- * 尚未初始化
918
- */
919
- WebSocketState[WebSocketState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
920
- /**
921
- * 正在链接中
922
- */
923
- WebSocketState[WebSocketState["CONNECTING"] = 0] = "CONNECTING";
924
- /**
925
- * 已经链接并且可以通讯
926
- */
927
- WebSocketState[WebSocketState["OPEN"] = 1] = "OPEN";
928
- /**
929
- * 连接正在关闭
930
- */
931
- WebSocketState[WebSocketState["CLOSING"] = 2] = "CLOSING";
932
- /**
933
- * 连接已关闭或者没有链接成功
934
- */
935
- WebSocketState[WebSocketState["CLOSED"] = 3] = "CLOSED";
936
- })(exports.WebSocketState || (exports.WebSocketState = {}));
937
- exports.WebSocketErrorType = void 0;
938
- (function (WebSocketErrorType) {
939
- WebSocketErrorType["Error"] = "Error";
940
- WebSocketErrorType["Close"] = "Close";
941
- WebSocketErrorType["MicroAuth"] = "MicroAuth";
942
- WebSocketErrorType["DuplicateConnect"] = "DuplicateConnect";
943
- WebSocketErrorType["IllegalURL"] = "IllegalURL";
944
- WebSocketErrorType["Unknown"] = "Unknown";
945
- WebSocketErrorType["IllegalArgs"] = "IllegalArgs";
946
- })(exports.WebSocketErrorType || (exports.WebSocketErrorType = {}));
947
- /**
948
- * WebSocket 异常关闭枚举:https://developer.mozilla.org/zh-CN/docs/Web/API/CloseEvent。
949
- */
950
- exports.WebSocketCloseError = void 0;
951
- (function (WebSocketCloseError) {
952
- /**
953
- * 终端离开, 可能因为服务端错误, 也可能因为浏览器正从打开连接的页面跳转离开。
954
- */
955
- WebSocketCloseError["Err_1001"] = "CLOSE_GOING_AWAY";
956
- /**
957
- * 由于协议错误而中断连接。
958
- */
959
- WebSocketCloseError["Err_1002"] = "CLOSE_PROTOCOL_ERROR";
960
- /**
961
- * 由于接收到不允许的数据类型而断开连接 (如仅接收文本数据的终端接收到了二进制数据)。
962
- */
963
- WebSocketCloseError["Err_1003"] = "CLOSE_UNSUPPORTED";
964
- /**
965
- * 安全因素或WebSocket连接次数达到上限。
966
- */
967
- WebSocketCloseError["Err_1006"] = "CLOSE_ABNORMAL";
968
- /**
969
- * 由于收到了格式不符的数据而断开连接 (如文本消息中包含了非 UTF-8 数据)。
970
- */
971
- WebSocketCloseError["Err_1007"] = "Unsupported Data";
972
- /**
973
- * 由于收到不符合约定的数据而断开连接。
974
- */
975
- WebSocketCloseError["Err_1008"] = "Policy Violation";
976
- /**
977
- * 由于收到过大的数据帧而断开连接。
978
- */
979
- WebSocketCloseError["Err_1009"] = "CLOSE_TOO_LARGE";
980
- /**
981
- * 未知错误。
982
- */
983
- WebSocketCloseError["Err_unknown"] = "unknown";
984
- })(exports.WebSocketCloseError || (exports.WebSocketCloseError = {}));
985
- function parseWSClsErr(code) {
986
- switch (code) {
987
- case 1001: {
988
- return exports.WebSocketCloseError.Err_1001;
989
- }
990
- case 1002: {
991
- return exports.WebSocketCloseError.Err_1002;
992
- }
993
- case 1003: {
994
- return exports.WebSocketCloseError.Err_1003;
995
- }
996
- case 1006: {
997
- return exports.WebSocketCloseError.Err_1006;
998
- }
999
- case 1007: {
1000
- return exports.WebSocketCloseError.Err_1007;
1001
- }
1002
- case 1008: {
1003
- return exports.WebSocketCloseError.Err_1008;
2476
+ const defaultOptions = {
2477
+ timeout: 60000,
2478
+ };
2479
+ class JSBridgeMiniprogram extends JSBridgeCore {
2480
+ constructor(options = {}) {
2481
+ super();
2482
+ this._controller = new WxMiniprogramController();
2483
+ this.options = Object.assign(defaultOptions, options);
2484
+ if (!isWxMiniProgram$1) {
2485
+ console.warn('未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... ');
1004
2486
  }
1005
- case 1009: {
1006
- return exports.WebSocketCloseError.Err_1009;
2487
+ this.webViewType = WebViewTypeEnum.WeChatMPWebView;
2488
+ this.callAndListen('common/webViewState', (webviewState) => {
2489
+ this.emit('webViewStateChange', webviewState);
2490
+ });
2491
+ this.callAndListen('common/webViewError', (errorInfo) => {
2492
+ this.emit('error', errorInfo);
2493
+ });
2494
+ }
2495
+ ready() {
2496
+ return __awaiter(this, void 0, void 0, function* () {
2497
+ return yield this._controller.checkReady(this.options.timeout);
2498
+ });
2499
+ }
2500
+ callAndBackfeed(schemeUrl) {
2501
+ return __awaiter(this, void 0, void 0, function* () {
2502
+ return yield this._controller.callAndBackfeed(schemeUrl);
2503
+ });
2504
+ }
2505
+ callAndListen(schemeUrl, callback) {
2506
+ return __awaiter(this, void 0, void 0, function* () {
2507
+ return yield this._controller.callAndListen(schemeUrl, callback);
2508
+ });
2509
+ }
2510
+ setLeftTopBackButton(enable) {
2511
+ return __awaiter(this, void 0, void 0, function* () {
2512
+ if (this.webViewType === WebViewTypeEnum.WebView) {
2513
+ return [true, null];
2514
+ }
2515
+ return yield this.callAndBackfeed(`common/setLeftTopBackButton?enable=${enable ? 1 : 0}`);
2516
+ });
2517
+ }
2518
+ getBangsHeight() {
2519
+ return __awaiter(this, void 0, void 0, function* () {
2520
+ return yield this.callAndBackfeed('common/getBangsHeight');
2521
+ });
2522
+ }
2523
+ shock(duration = 4) {
2524
+ return __awaiter(this, void 0, void 0, function* () {
2525
+ return yield this.callAndBackfeed(`common/shock?duration=${duration}`);
2526
+ });
2527
+ }
2528
+ minimize() {
2529
+ return __awaiter(this, void 0, void 0, function* () {
2530
+ return yield this.callAndBackfeed(`common/minimize`);
2531
+ });
2532
+ }
2533
+ loadProgress(progress) {
2534
+ return __awaiter(this, void 0, void 0, function* () {
2535
+ progress = progress < 0 ? 0 : progress > 100 ? 100 : progress;
2536
+ return yield this.callAndBackfeed(`common/loadProgress?progress=${progress}`);
2537
+ });
2538
+ }
2539
+ closeLoading() {
2540
+ return __awaiter(this, void 0, void 0, function* () {
2541
+ return yield this.callAndBackfeed(`common/closeLoading`);
2542
+ });
2543
+ }
2544
+ setOrientation(orientation) {
2545
+ return __awaiter(this, void 0, void 0, function* () {
2546
+ return yield this.callAndBackfeed(`common/setOrientation?orientation=${orientation}`);
2547
+ });
2548
+ }
2549
+ keepScreenLight(enable) {
2550
+ return __awaiter(this, void 0, void 0, function* () {
2551
+ return yield this.callAndBackfeed(`common/keepScreenLight?enable=${enable ? 1 : 0}`);
2552
+ });
2553
+ }
2554
+ closeWebView() {
2555
+ return __awaiter(this, void 0, void 0, function* () {
2556
+ return yield this.callAndBackfeed(`common/closeWebView`);
2557
+ });
2558
+ }
2559
+ openWebView(url, way) {
2560
+ return __awaiter(this, void 0, void 0, function* () {
2561
+ return yield this.callAndBackfeed(`common/openWebView?way=${way}&url=${encodeURIComponent(url)}`);
2562
+ });
2563
+ }
2564
+ saveImage2Album(base64) {
2565
+ return __awaiter(this, void 0, void 0, function* () {
2566
+ return yield this.callAndBackfeed(`common/saveImage2Album?base64=${base64}`);
2567
+ });
2568
+ }
2569
+ actionShare(shareConfig) {
2570
+ var _a, _b, _c;
2571
+ return __awaiter(this, void 0, void 0, function* () {
2572
+ const config = {
2573
+ path: (_a = shareConfig.miniprogram) === null || _a === void 0 ? void 0 : _a[0].path,
2574
+ title: (_b = shareConfig.miniprogram) === null || _b === void 0 ? void 0 : _b[0].title,
2575
+ imageUrl: (_c = shareConfig.miniprogram) === null || _c === void 0 ? void 0 : _c[0].hdImageData,
2576
+ };
2577
+ return yield this.callAndBackfeed(`common/actionShare?json=${JSON.stringify(config)}`);
2578
+ });
2579
+ }
2580
+ getDeviceInfo() {
2581
+ return __awaiter(this, void 0, void 0, function* () {
2582
+ return yield this.callAndBackfeed(`common/getDeviceInfo`);
2583
+ });
2584
+ }
2585
+ getUserInfo() {
2586
+ return __awaiter(this, void 0, void 0, function* () {
2587
+ return yield this.callAndBackfeed(`common/getUserInfo`);
2588
+ });
2589
+ }
2590
+ getWebViewState() {
2591
+ return __awaiter(this, void 0, void 0, function* () {
2592
+ return yield this.callAndBackfeed(`common/getWebViewState`);
2593
+ });
2594
+ }
2595
+ login() {
2596
+ return __awaiter(this, void 0, void 0, function* () {
2597
+ const res = yield this.callAndBackfeed(`common/login`);
2598
+ if (res[0]) {
2599
+ return yield this.getUserInfo();
2600
+ }
2601
+ return res;
2602
+ });
2603
+ }
2604
+ logout() {
2605
+ return __awaiter(this, void 0, void 0, function* () {
2606
+ return yield this.callAndBackfeed(`common/logout`);
2607
+ });
2608
+ }
2609
+ detectMicro() {
2610
+ return __awaiter(this, void 0, void 0, function* () {
2611
+ return yield this.callAndBackfeed(`common/detectMicro`);
2612
+ });
2613
+ }
2614
+ preload(urls) {
2615
+ return __awaiter(this, void 0, void 0, function* () {
2616
+ urls = urls.map((url) => {
2617
+ if (url.startsWith('//')) {
2618
+ return 'https:' + url;
2619
+ }
2620
+ return url;
2621
+ });
2622
+ return yield this.callAndBackfeed(`common/preload?urls=${JSON.stringify(urls)}`);
2623
+ });
2624
+ }
2625
+ createCacheProxyUrl(urls) {
2626
+ urls = Array.isArray(urls) ? urls : [urls];
2627
+ const userAgent = window.navigator.userAgent;
2628
+ if (!/supportCache/i.test(userAgent)) {
2629
+ return urls;
1007
2630
  }
2631
+ const proxyCache = (url) => {
2632
+ if (this.webViewType === WebViewTypeEnum.WKWebview) {
2633
+ return url
2634
+ .replace(/https*:/, '')
2635
+ .replace(/\/\//, 'realseeproxycache://');
2636
+ }
2637
+ else if (this.webViewType === WebViewTypeEnum.WebView) {
2638
+ return (url + (url.indexOf('?') !== -1 ? '&' : '?') + 'realseeproxycache=1');
2639
+ }
2640
+ return url;
2641
+ };
2642
+ return urls.map(proxyCache);
2643
+ }
2644
+ invokeNativeApi(method, data) {
2645
+ return __awaiter(this, void 0, void 0, function* () {
2646
+ return yield this._controller.invoke(method, data);
2647
+ });
2648
+ }
2649
+ execute(method, args) {
2650
+ var _a, _b, _c;
2651
+ return __awaiter(this, void 0, void 0, function* () {
2652
+ return yield ((_c = (_b = (_a = this._controller) === null || _a === void 0 ? void 0 : _a.hybridBridge) === null || _b === void 0 ? void 0 : _b.execute) === null || _c === void 0 ? void 0 : _c.call(_b, method, args));
2653
+ });
2654
+ }
2655
+ }
2656
+
2657
+ class JSBridge extends JSBridgeCore {
2658
+ constructor(options = {}) {
2659
+ super();
2660
+ if (isRealseeVRWebview$1 && (isAndroid$1 || isIOS$1))
2661
+ return new JSBridgeApp(options);
2662
+ if (isWxMiniProgram$1)
2663
+ return new JSBridgeMiniprogram(options);
2664
+ return new JSBridgeBrowser();
1008
2665
  }
1009
- return exports.WebSocketCloseError.Err_unknown;
1010
2666
  }
1011
2667
 
1012
2668
  function getDefaultExportFromCjs (x) {
@@ -1186,7 +2842,7 @@ function equal(value, other, opt = { deep: false }) {
1186
2842
  * 1、自动重连
1187
2843
  * 2、可根据网络情况进行重连
1188
2844
  */
1189
- class RobustWebSocket extends Subscribe {
2845
+ class RobustWebSocket extends Subscribe$1 {
1190
2846
  get attempts() {
1191
2847
  return this._attempts;
1192
2848
  }
@@ -1213,7 +2869,7 @@ class RobustWebSocket extends Subscribe {
1213
2869
  /**
1214
2870
  * 做一个健康检查
1215
2871
  */
1216
- this._healthCheck = () => __awaiter(this, void 0, void 0, function* () {
2872
+ this._healthCheck = () => __awaiter$1(this, void 0, void 0, function* () {
1217
2873
  if (this._realWebSocket &&
1218
2874
  this._realWebSocket.readyState !== this._readyState) {
1219
2875
  this._readyState = this._realWebSocket.readyState;
@@ -1477,7 +3133,7 @@ class RobustWebSocket extends Subscribe {
1477
3133
  }
1478
3134
  }
1479
3135
 
1480
- class LiveController extends Subscribe {
3136
+ class LiveController extends Subscribe$1 {
1481
3137
  set state(state) {
1482
3138
  const prevState = JSON.parse(JSON.stringify(this._state));
1483
3139
  this._state = state;
@@ -1594,7 +3250,7 @@ class LiveController extends Subscribe {
1594
3250
  * 释放资源,释放之后需要重新实例化
1595
3251
  * @returns
1596
3252
  */
1597
- this.dispose = () => __awaiter(this, void 0, void 0, function* () {
3253
+ this.dispose = () => __awaiter$1(this, void 0, void 0, function* () {
1598
3254
  this._removeWebSocketEventListeners();
1599
3255
  return yield this.close('live room close by controller disposed!');
1600
3256
  });
@@ -1635,7 +3291,7 @@ class LiveController extends Subscribe {
1635
3291
  const unimplementedGetVoiceSign = (params) => Promise.reject('unimplemented method GetVoiceSign');
1636
3292
  const createLiveMsg = (command, data = {}, toUserIds = []) => ({
1637
3293
  command,
1638
- front_request_id: uuid(),
3294
+ front_request_id: uuid$1(),
1639
3295
  data: Object.assign(Object.assign({}, data), { to_user_ids: Array.isArray(toUserIds) ? toUserIds : [toUserIds] }),
1640
3296
  });
1641
3297
  const _clearLiveInstanceIfNeed = () => {
@@ -1645,7 +3301,7 @@ const _clearLiveInstanceIfNeed = () => {
1645
3301
  window.__Realsee_Live__ = null;
1646
3302
  }
1647
3303
  };
1648
- class Live extends Subscribe {
3304
+ class Live extends Subscribe$1 {
1649
3305
  get options() {
1650
3306
  return Object.freeze(this._options || {});
1651
3307
  }
@@ -1715,7 +3371,7 @@ class Live extends Subscribe {
1715
3371
  /**
1716
3372
  * 帧数据监听
1717
3373
  */
1718
- this.keyframes = new Subscribe();
3374
+ this.keyframes = new Subscribe$1();
1719
3375
  /**
1720
3376
  * 内置的一些数据
1721
3377
  */
@@ -1776,8 +3432,8 @@ class Live extends Subscribe {
1776
3432
  * 消息接收
1777
3433
  * @param liveMsg
1778
3434
  */
1779
- this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
1780
- var _b, _c, _d, _e, _f, _g;
3435
+ this._handleMessage = (liveMsg) => __awaiter$1(this, void 0, void 0, function* () {
3436
+ var _b, _c, _d, _e, _f;
1781
3437
  if (typeof liveMsg === 'object') {
1782
3438
  const { command, data = {}, frontRequestId, code, message } = liveMsg;
1783
3439
  if (code === 'SUCCESS') {
@@ -1817,7 +3473,7 @@ class Live extends Subscribe {
1817
3473
  }));
1818
3474
  if (result) {
1819
3475
  const status = (_f = this._options.initialMicroStatus) !== null && _f !== void 0 ? _f : exports.MicroStatus.OPEN;
1820
- yield ((_g = this.$RTC) === null || _g === void 0 ? void 0 : _g.toggleMicro(status === exports.MicroStatus.OPEN));
3476
+ yield this.toggleMicro(status === exports.MicroStatus.OPEN);
1821
3477
  }
1822
3478
  else {
1823
3479
  logger$1.error('加入语音房间失败');
@@ -1930,13 +3586,13 @@ class Live extends Subscribe {
1930
3586
  * @param options
1931
3587
  * @returns
1932
3588
  */
1933
- this.connect = (options = {}) => __awaiter(this, void 0, void 0, function* () {
1934
- var _h, _j, _k, _l;
3589
+ this.connect = (options = {}) => __awaiter$1(this, void 0, void 0, function* () {
3590
+ var _g, _h, _j, _k;
1935
3591
  // 检查 url 和 票据获取接口实现
1936
- this._options.url = (_j = (_h = options.url) !== null && _h !== void 0 ? _h : this._options.url) !== null && _j !== void 0 ? _j : '';
1937
- this._options.getTicket = (_k = options.getTicket) !== null && _k !== void 0 ? _k : this._options.getTicket;
3592
+ this._options.url = (_h = (_g = options.url) !== null && _g !== void 0 ? _g : this._options.url) !== null && _h !== void 0 ? _h : '';
3593
+ this._options.getTicket = (_j = options.getTicket) !== null && _j !== void 0 ? _j : this._options.getTicket;
1938
3594
  this._options.initialMicroStatus =
1939
- (_l = options.rtcMicStatus) !== null && _l !== void 0 ? _l : this._options.initialMicroStatus;
3595
+ (_k = options.rtcMicStatus) !== null && _k !== void 0 ? _k : this._options.initialMicroStatus;
1940
3596
  if (!/^ws(s):\/\//.test(this._options.url) ||
1941
3597
  typeof this._options.getTicket !== 'function') {
1942
3598
  if (!/^ws(s):\/\//.test(this._options.url)) {
@@ -1984,12 +3640,12 @@ class Live extends Subscribe {
1984
3640
  * 退出带看
1985
3641
  * @returns
1986
3642
  */
1987
- this.exit = () => __awaiter(this, void 0, void 0, function* () {
1988
- var _m;
3643
+ this.exit = () => __awaiter$1(this, void 0, void 0, function* () {
3644
+ var _l;
1989
3645
  this._clearLiveData();
1990
3646
  try {
1991
3647
  /** 退出强制关闭语音 */
1992
- (_m = this.$RTC) === null || _m === void 0 ? void 0 : _m.quit();
3648
+ (_l = this.$RTC) === null || _l === void 0 ? void 0 : _l.quit();
1993
3649
  yield this.updateStatus(exports.BuiltinEventType.RoomChange, exports.BuiltinActionType.RoomClose, {});
1994
3650
  }
1995
3651
  catch (e) {
@@ -2001,7 +3657,7 @@ class Live extends Subscribe {
2001
3657
  * 销毁带看
2002
3658
  * @returns
2003
3659
  */
2004
- this.dispose = () => __awaiter(this, void 0, void 0, function* () {
3660
+ this.dispose = () => __awaiter$1(this, void 0, void 0, function* () {
2005
3661
  this._removeLiveControllerEventListeners();
2006
3662
  this._clearLiveData();
2007
3663
  return yield this._controller.dispose();
@@ -2011,15 +3667,15 @@ class Live extends Subscribe {
2011
3667
  * @param userInfo
2012
3668
  * @returns
2013
3669
  */
2014
- this.setSelfInfo = (userInfo) => __awaiter(this, void 0, void 0, function* () {
3670
+ this.setSelfInfo = (userInfo) => __awaiter$1(this, void 0, void 0, function* () {
2015
3671
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserInfo, userInfo);
2016
3672
  });
2017
3673
  // 仅用于用户自己的麦克风控制
2018
- this.toggleMicro = (microStatus) => __awaiter(this, void 0, void 0, function* () {
2019
- var _o, _p, _q;
2020
- if (!((_p = (_o = this.selfInfo) === null || _o === void 0 ? void 0 : _o.permission) === null || _p === void 0 ? void 0 : _p.control_own_micro))
3674
+ this.toggleMicro = (microStatus) => __awaiter$1(this, void 0, void 0, function* () {
3675
+ var _m, _o, _p;
3676
+ if (!((_o = (_m = this.selfInfo) === null || _m === void 0 ? void 0 : _m.permission) === null || _o === void 0 ? void 0 : _o.control_own_micro))
2021
3677
  return false;
2022
- const result = yield ((_q = this.$RTC) === null || _q === void 0 ? void 0 : _q.toggleMicro(microStatus));
3678
+ const result = yield ((_p = this.$RTC) === null || _p === void 0 ? void 0 : _p.toggleMicro(microStatus));
2023
3679
  if (result) {
2024
3680
  yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
2025
3681
  status: microStatus ? exports.MicroStatus.OPEN : exports.MicroStatus.CLOSE,
@@ -2033,13 +3689,13 @@ class Live extends Subscribe {
2033
3689
  * @param toUserIds
2034
3690
  * @returns
2035
3691
  */
2036
- this.forbidMicro = (microStatus, toUserIds) => __awaiter(this, void 0, void 0, function* () {
2037
- var _r, _s;
3692
+ this.forbidMicro = (microStatus, toUserIds) => __awaiter$1(this, void 0, void 0, function* () {
3693
+ var _q, _r;
2038
3694
  if (typeof this._options.canForbidUserMicro === 'function' &&
2039
3695
  !this._options.canForbidUserMicro(toUserIds)) {
2040
3696
  return false;
2041
3697
  }
2042
- if (!((_s = (_r = this.selfInfo) === null || _r === void 0 ? void 0 : _r.permission) === null || _s === void 0 ? void 0 : _s.control_other_micro)) {
3698
+ if (!((_r = (_q = this.selfInfo) === null || _q === void 0 ? void 0 : _q.permission) === null || _r === void 0 ? void 0 : _r.control_other_micro)) {
2043
3699
  return false;
2044
3700
  }
2045
3701
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
@@ -2052,13 +3708,13 @@ class Live extends Subscribe {
2052
3708
  * @param toUserIds
2053
3709
  * @returns
2054
3710
  */
2055
- this.forbidSync = (sync, toUserIds) => __awaiter(this, void 0, void 0, function* () {
2056
- var _t, _u;
3711
+ this.forbidSync = (sync, toUserIds) => __awaiter$1(this, void 0, void 0, function* () {
3712
+ var _s, _t;
2057
3713
  if (typeof this._options.canForbidUserSync === 'function' &&
2058
3714
  !this._options.canForbidUserSync(toUserIds)) {
2059
3715
  return false;
2060
3716
  }
2061
- if (!((_u = (_t = this.selfInfo) === null || _t === void 0 ? void 0 : _t.permission) === null || _u === void 0 ? void 0 : _u.control_other_sync)) {
3717
+ if (!((_t = (_s = this.selfInfo) === null || _s === void 0 ? void 0 : _s.permission) === null || _t === void 0 ? void 0 : _t.control_other_sync)) {
2062
3718
  return false;
2063
3719
  }
2064
3720
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
@@ -2068,13 +3724,13 @@ class Live extends Subscribe {
2068
3724
  * @param toUserIds
2069
3725
  * @returns
2070
3726
  */
2071
- this.kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () {
2072
- var _v, _w;
3727
+ this.kick = (toUserIds) => __awaiter$1(this, void 0, void 0, function* () {
3728
+ var _u, _v;
2073
3729
  if (typeof this._options.canForbidUserKick === 'function' &&
2074
3730
  !this._options.canForbidUserKick(toUserIds)) {
2075
3731
  return false;
2076
3732
  }
2077
- if (!((_w = (_v = this.selfInfo) === null || _v === void 0 ? void 0 : _v.permission) === null || _w === void 0 ? void 0 : _w.change_other_status)) {
3733
+ if (!((_v = (_u = this.selfInfo) === null || _u === void 0 ? void 0 : _u.permission) === null || _v === void 0 ? void 0 : _v.change_other_status)) {
2078
3734
  return false;
2079
3735
  }
2080
3736
  return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserStatus, {
@@ -2088,7 +3744,7 @@ class Live extends Subscribe {
2088
3744
  if (opts.jsBridge)
2089
3745
  return opts.jsBridge;
2090
3746
  if (opts.useBuiltInJsBridge)
2091
- return new JSBridge__default["default"]();
3747
+ return new JSBridge();
2092
3748
  return undefined;
2093
3749
  })();
2094
3750
  // 第二步检查getVoiceSign
@@ -2184,7 +3840,7 @@ class Live extends Subscribe {
2184
3840
  * @returns
2185
3841
  */
2186
3842
  updateStatus(evtType, atnType, status, toUserIds) {
2187
- return __awaiter(this, void 0, void 0, function* () {
3843
+ return __awaiter$1(this, void 0, void 0, function* () {
2188
3844
  if (this.state !== exports.LiveState.OPEN)
2189
3845
  return false;
2190
3846
  const data = Object.assign({ event_type: evtType, action: atnType }, { data: status });
@@ -2284,7 +3940,7 @@ function createLiveReact(options) {
2284
3940
  /**
2285
3941
  * 带看连接操作
2286
3942
  */
2287
- const useConnect = () => (options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); });
3943
+ const useConnect = () => (options) => __awaiter$1(this, void 0, void 0, function* () { return yield live.connect(options); });
2288
3944
  /**
2289
3945
  *
2290
3946
  * @param name
@@ -2308,12 +3964,12 @@ function createLiveReact(options) {
2308
3964
  */
2309
3965
  function useLiveAction() {
2310
3966
  const live = useLiveInstance();
2311
- const connect = (options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); });
3967
+ const connect = (options) => __awaiter$1(this, void 0, void 0, function* () { return yield live.connect(options); });
2312
3968
  const toggleMicro = (microStatus) => live.toggleMicro(microStatus);
2313
- const broadcast = (data, toUserIds, timeout = 0) => __awaiter(this, void 0, void 0, function* () { return yield live.broadcast(data, toUserIds, timeout); });
2314
- const exit = () => __awaiter(this, void 0, void 0, function* () { return yield live.exit(); });
2315
- const kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () { return yield live.kick(toUserIds); });
2316
- const forbidMicro = (micro, toUserIds = []) => __awaiter(this, void 0, void 0, function* () { return yield live.forbidMicro(micro, toUserIds); });
3969
+ const broadcast = (data, toUserIds, timeout = 0) => __awaiter$1(this, void 0, void 0, function* () { return yield live.broadcast(data, toUserIds, timeout); });
3970
+ const exit = () => __awaiter$1(this, void 0, void 0, function* () { return yield live.exit(); });
3971
+ const kick = (toUserIds) => __awaiter$1(this, void 0, void 0, function* () { return yield live.kick(toUserIds); });
3972
+ const forbidMicro = (micro, toUserIds = []) => __awaiter$1(this, void 0, void 0, function* () { return yield live.forbidMicro(micro, toUserIds); });
2317
3973
  const forbidSync = (sync, toUserIds = []) => live.forbidSync(sync, toUserIds);
2318
3974
  const getFramesByKey = (key) => live.getFramesByKey(key);
2319
3975
  const sendKeyframe = (key, frame) => live.sendKeyframe(key, frame);
@@ -2403,7 +4059,7 @@ function createLiveReact(options) {
2403
4059
  live.on('selfInfoUpdate', selfInfoUpdate);
2404
4060
  return () => live.off('selfInfoUpdate', selfInfoUpdate);
2405
4061
  }, [live]);
2406
- const setState = React__default["default"].useCallback((userInfo) => __awaiter(this, void 0, void 0, function* () {
4062
+ const setState = React__default["default"].useCallback((userInfo) => __awaiter$1(this, void 0, void 0, function* () {
2407
4063
  return yield live.setSelfInfo(userInfo);
2408
4064
  }), [live]);
2409
4065
  return [state, setState];