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