@realsee/live 0.4.0-alpha.3 → 0.4.0-alpha.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/README.md +52 -54
- package/dist/realsee-live.cjs.development.js +46 -2
- 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 +46 -3
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +1798 -33
- 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/dist/typings/live/Live.d.ts +6 -1
- package/dist/typings/live/LiveOptions.d.ts +14 -1
- package/dist/typings/rtc/type.d.ts +4 -0
- package/package.json +2 -2
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.RealseeLive = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
const EVENT_SYMBOL = Symbol('$$REALSEE_LIVE_EVENT$$');
|
|
8
|
-
function __generateEventIfNotExisted(instance) {
|
|
9
|
-
if (!instance[EVENT_SYMBOL]) {
|
|
10
|
-
instance[EVENT_SYMBOL] = {};
|
|
7
|
+
const EVENT_SYMBOL$1 = Symbol('$$REALSEE_LIVE_EVENT$$');
|
|
8
|
+
function __generateEventIfNotExisted$1(instance) {
|
|
9
|
+
if (!instance[EVENT_SYMBOL$1]) {
|
|
10
|
+
instance[EVENT_SYMBOL$1] = {};
|
|
11
11
|
}
|
|
12
|
-
return instance[EVENT_SYMBOL];
|
|
12
|
+
return instance[EVENT_SYMBOL$1];
|
|
13
13
|
}
|
|
14
|
-
function __removeEventIfNotExisted(instance) {
|
|
15
|
-
if (!instance[EVENT_SYMBOL]) {
|
|
16
|
-
delete instance[EVENT_SYMBOL];
|
|
14
|
+
function __removeEventIfNotExisted$1(instance) {
|
|
15
|
+
if (!instance[EVENT_SYMBOL$1]) {
|
|
16
|
+
delete instance[EVENT_SYMBOL$1];
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
* }>()
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
class Subscribe {
|
|
30
|
+
class Subscribe$1 {
|
|
31
31
|
/**
|
|
32
32
|
* 判断是否注册了事件
|
|
33
33
|
* @param name 事件类型
|
|
34
34
|
*/
|
|
35
35
|
hasListener(name) {
|
|
36
|
-
const events = __generateEventIfNotExisted(this);
|
|
36
|
+
const events = __generateEventIfNotExisted$1(this);
|
|
37
37
|
return events && events[name] && events[name].length > 0;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* @template C 回调函数函数上下文
|
|
47
47
|
*/
|
|
48
48
|
on(name, callback, once) {
|
|
49
|
-
const events = __generateEventIfNotExisted(this);
|
|
49
|
+
const events = __generateEventIfNotExisted$1(this);
|
|
50
50
|
if (!events[name])
|
|
51
51
|
events[name] = [];
|
|
52
52
|
events[name].push([callback, once || false]);
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
*/
|
|
75
75
|
off(name, callback) {
|
|
76
76
|
if (name === undefined) {
|
|
77
|
-
__removeEventIfNotExisted(this);
|
|
77
|
+
__removeEventIfNotExisted$1(this);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
const events = __generateEventIfNotExisted(this);
|
|
80
|
+
const events = __generateEventIfNotExisted$1(this);
|
|
81
81
|
if (!events[name])
|
|
82
82
|
events[name] = [];
|
|
83
83
|
if (callback === undefined) {
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
*/
|
|
103
103
|
emit(name, ...data) {
|
|
104
104
|
let canceled = false;
|
|
105
|
-
const events = __generateEventIfNotExisted(this);
|
|
105
|
+
const events = __generateEventIfNotExisted$1(this);
|
|
106
106
|
const event = events[name] || [];
|
|
107
107
|
for (let one of event.slice()) {
|
|
108
108
|
const [callback, once = false] = one;
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
/**
|
|
120
120
|
* rtc 基础抽象类
|
|
121
121
|
*/
|
|
122
|
-
class CoreRTC extends Subscribe {
|
|
122
|
+
class CoreRTC extends Subscribe$1 {
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -158,29 +158,34 @@
|
|
|
158
158
|
RTCType["RealseeBrowserRTC"] = "RealseeBrowserRTC";
|
|
159
159
|
RTCType["RealseeVRWebViewRTC"] = "RealseeVRWebViewRTC";
|
|
160
160
|
RTCType["RealseeBrowserChimeRTC"] = "RealseeBrowserChimeRTC";
|
|
161
|
-
})(exports.RTCType || (exports.RTCType = {}));
|
|
161
|
+
})(exports.RTCType || (exports.RTCType = {}));
|
|
162
|
+
exports.BuiltInRTCType = void 0;
|
|
163
|
+
(function (BuiltInRTCType) {
|
|
164
|
+
BuiltInRTCType["RealseeXTRTC"] = "trtc";
|
|
165
|
+
BuiltInRTCType["RealseeXChimeRTC"] = "chime";
|
|
166
|
+
})(exports.BuiltInRTCType || (exports.BuiltInRTCType = {}));
|
|
162
167
|
|
|
163
168
|
// uuid
|
|
164
|
-
function S4() {
|
|
169
|
+
function S4$1() {
|
|
165
170
|
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
166
171
|
}
|
|
167
172
|
/**
|
|
168
173
|
* 基于伪随机数生成 **uuid**。
|
|
169
174
|
*/
|
|
170
|
-
function uuid() {
|
|
175
|
+
function uuid$1() {
|
|
171
176
|
// then to call it, plus stitch in '4' in the third group
|
|
172
|
-
return (S4() +
|
|
173
|
-
S4() +
|
|
177
|
+
return (S4$1() +
|
|
178
|
+
S4$1() +
|
|
174
179
|
'-' +
|
|
175
|
-
S4() +
|
|
180
|
+
S4$1() +
|
|
176
181
|
'-4' +
|
|
177
|
-
S4().substr(0, 3) +
|
|
182
|
+
S4$1().substr(0, 3) +
|
|
178
183
|
'-' +
|
|
179
|
-
S4() +
|
|
184
|
+
S4$1() +
|
|
180
185
|
'-' +
|
|
181
|
-
S4() +
|
|
182
|
-
S4() +
|
|
183
|
-
S4()).toLowerCase();
|
|
186
|
+
S4$1() +
|
|
187
|
+
S4$1() +
|
|
188
|
+
S4$1()).toLowerCase();
|
|
184
189
|
}
|
|
185
190
|
|
|
186
191
|
class BrowserRTC extends CoreRTC {
|
|
@@ -265,7 +270,7 @@
|
|
|
265
270
|
this._initParentDom();
|
|
266
271
|
}
|
|
267
272
|
_initParentDom() {
|
|
268
|
-
this.$dom.id = `rs-rtc-${uuid()}`;
|
|
273
|
+
this.$dom.id = `rs-rtc-${uuid$1()}`;
|
|
269
274
|
this.$dom.style.display = 'none';
|
|
270
275
|
document.body.appendChild(this.$dom);
|
|
271
276
|
}
|
|
@@ -48210,8 +48215,8 @@
|
|
|
48210
48215
|
* 对audio标签初始化
|
|
48211
48216
|
*/
|
|
48212
48217
|
this._initDom = () => {
|
|
48213
|
-
this.$audio.id = `rs-rtc-${uuid()}`;
|
|
48214
|
-
this.$dom.id = `rs-rtc-${uuid()}`;
|
|
48218
|
+
this.$audio.id = `rs-rtc-${uuid$1()}`;
|
|
48219
|
+
this.$dom.id = `rs-rtc-${uuid$1()}`;
|
|
48215
48220
|
this.$dom.appendChild(this.$audio);
|
|
48216
48221
|
document.body.appendChild(this.$dom);
|
|
48217
48222
|
};
|
|
@@ -48774,12 +48779,1741 @@
|
|
|
48774
48779
|
return exports.WebSocketCloseError.Err_unknown;
|
|
48775
48780
|
}
|
|
48776
48781
|
|
|
48782
|
+
const cache = {};
|
|
48783
|
+
/**
|
|
48784
|
+
* 创建一个唯一的函数名(在当前页面会话中保障其唯一性即可)。
|
|
48785
|
+
* @param extra 可以额外自定义部分字符串。
|
|
48786
|
+
* @returns
|
|
48787
|
+
*/
|
|
48788
|
+
function registerGlobalValue(scheme, callback, once = true) {
|
|
48789
|
+
if (!cache[scheme]) {
|
|
48790
|
+
const uuid = '$jsBridgeFn_' + Date.now().toString(16).toUpperCase() + '_' + Math.ceil(Math.random() * 10000).toString(16).toUpperCase();
|
|
48791
|
+
cache[scheme] = {
|
|
48792
|
+
uuid,
|
|
48793
|
+
queue: [{ once, callback }],
|
|
48794
|
+
};
|
|
48795
|
+
}
|
|
48796
|
+
else {
|
|
48797
|
+
cache[scheme].queue.push({ once, callback });
|
|
48798
|
+
}
|
|
48799
|
+
Object.assign(window, {
|
|
48800
|
+
[cache[scheme].uuid]: (data) => {
|
|
48801
|
+
cache[scheme].queue = cache[scheme].queue.reduce((accu, curr) => {
|
|
48802
|
+
const { once, callback } = curr;
|
|
48803
|
+
if (!once) {
|
|
48804
|
+
accu.push(curr);
|
|
48805
|
+
}
|
|
48806
|
+
callback(data);
|
|
48807
|
+
return accu;
|
|
48808
|
+
}, []);
|
|
48809
|
+
}
|
|
48810
|
+
});
|
|
48811
|
+
return cache[scheme].uuid;
|
|
48812
|
+
}
|
|
48813
|
+
|
|
48814
|
+
class BaseController {
|
|
48815
|
+
checkReady(timeout) {
|
|
48816
|
+
return Promise.resolve([false, null]);
|
|
48817
|
+
}
|
|
48818
|
+
callAndBackfeed(scheme) {
|
|
48819
|
+
return Promise.resolve([false, null]);
|
|
48820
|
+
}
|
|
48821
|
+
callAndListen(scheme, callback) {
|
|
48822
|
+
return Promise.resolve([false, null]);
|
|
48823
|
+
}
|
|
48824
|
+
}
|
|
48825
|
+
|
|
48826
|
+
const HYBRID_BRIDGE_NAME = 'HybridBridgeLJ';
|
|
48827
|
+
const $window$1 = window;
|
|
48828
|
+
/**
|
|
48829
|
+
* Android WebView 控件。
|
|
48830
|
+
*/
|
|
48831
|
+
class WebViewController extends BaseController {
|
|
48832
|
+
constructor() {
|
|
48833
|
+
super();
|
|
48834
|
+
Promise.resolve().then(async () => {
|
|
48835
|
+
try {
|
|
48836
|
+
await this.checkBridgeReady();
|
|
48837
|
+
}
|
|
48838
|
+
catch (error) {
|
|
48839
|
+
console.warn(error);
|
|
48840
|
+
}
|
|
48841
|
+
});
|
|
48842
|
+
}
|
|
48843
|
+
/**
|
|
48844
|
+
* 检查 HybridBridgeLJ 是否ready
|
|
48845
|
+
* @param timeout 超时时间
|
|
48846
|
+
* @returns
|
|
48847
|
+
*/
|
|
48848
|
+
checkBridgeReady(timeout = 6000) {
|
|
48849
|
+
if (this.hybridBridge)
|
|
48850
|
+
return true;
|
|
48851
|
+
const start = performance.now();
|
|
48852
|
+
return new Promise((resolve, reject) => {
|
|
48853
|
+
const check = () => {
|
|
48854
|
+
if (this.hybridBridge)
|
|
48855
|
+
return resolve(true);
|
|
48856
|
+
if ($window$1.HybridBridgeLJ) {
|
|
48857
|
+
const hybridBridge = $window$1[HYBRID_BRIDGE_NAME];
|
|
48858
|
+
hybridBridge === null || hybridBridge === void 0 ? void 0 : hybridBridge.getStaticData(registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
|
|
48859
|
+
this.deviceInfo = JSON.parse(data);
|
|
48860
|
+
this.hybridBridge = hybridBridge;
|
|
48861
|
+
return resolve(true);
|
|
48862
|
+
}));
|
|
48863
|
+
}
|
|
48864
|
+
if (performance.now() - start > (timeout || 6000)) {
|
|
48865
|
+
// console.warn('HybridBridge 初始化超时~')
|
|
48866
|
+
return reject(new Error('HybridBridge 初始化超时~'));
|
|
48867
|
+
}
|
|
48868
|
+
// 逐帧监测
|
|
48869
|
+
requestAnimationFrame(check);
|
|
48870
|
+
};
|
|
48871
|
+
// 开启监测
|
|
48872
|
+
check();
|
|
48873
|
+
});
|
|
48874
|
+
}
|
|
48875
|
+
async checkReady(timeout = 6000) {
|
|
48876
|
+
const res = [null, null];
|
|
48877
|
+
if (this.hybridBridge) {
|
|
48878
|
+
res[0] = true;
|
|
48879
|
+
return res;
|
|
48880
|
+
}
|
|
48881
|
+
try {
|
|
48882
|
+
res[0] = await this.checkBridgeReady(timeout);
|
|
48883
|
+
}
|
|
48884
|
+
catch (error) {
|
|
48885
|
+
res[0] = false;
|
|
48886
|
+
res[1] = error;
|
|
48887
|
+
}
|
|
48888
|
+
return res;
|
|
48889
|
+
}
|
|
48890
|
+
get ready() {
|
|
48891
|
+
return !!this.hybridBridge;
|
|
48892
|
+
}
|
|
48893
|
+
get scheme() {
|
|
48894
|
+
var _a;
|
|
48895
|
+
return ((_a = this.deviceInfo) === null || _a === void 0 ? void 0 : _a.scheme) || '';
|
|
48896
|
+
}
|
|
48897
|
+
createSchemeLink(schemeUrl) {
|
|
48898
|
+
if (schemeUrl.startsWith(this.scheme)) {
|
|
48899
|
+
return schemeUrl;
|
|
48900
|
+
}
|
|
48901
|
+
return this.scheme + '://' + schemeUrl;
|
|
48902
|
+
}
|
|
48903
|
+
async callAndBackfeed(scheme) {
|
|
48904
|
+
const res = [false, null];
|
|
48905
|
+
const [ready, readyError] = await this.checkReady();
|
|
48906
|
+
if (!ready) {
|
|
48907
|
+
res[0] = false;
|
|
48908
|
+
res[1] = readyError;
|
|
48909
|
+
return res;
|
|
48910
|
+
}
|
|
48911
|
+
return await new Promise(async (resolve) => {
|
|
48912
|
+
const actionUrl = this.createSchemeLink(scheme);
|
|
48913
|
+
const msg = JSON.stringify({
|
|
48914
|
+
actionUrl,
|
|
48915
|
+
functionName: registerGlobalValue(this.createSchemeLink(scheme), (data) => {
|
|
48916
|
+
const d = JSON.parse(data);
|
|
48917
|
+
res[0] = (() => {
|
|
48918
|
+
if (d === 1)
|
|
48919
|
+
return true;
|
|
48920
|
+
if (d === 0)
|
|
48921
|
+
return false;
|
|
48922
|
+
return d;
|
|
48923
|
+
})();
|
|
48924
|
+
resolve(res);
|
|
48925
|
+
}),
|
|
48926
|
+
});
|
|
48927
|
+
this.hybridBridge.callAndBackfeed(msg);
|
|
48928
|
+
});
|
|
48929
|
+
}
|
|
48930
|
+
async callAndListen(scheme, callback) {
|
|
48931
|
+
const res = [false, null];
|
|
48932
|
+
const [ready, readyError] = await this.checkReady();
|
|
48933
|
+
if (!ready) {
|
|
48934
|
+
res[0] = false;
|
|
48935
|
+
res[1] = readyError;
|
|
48936
|
+
return res;
|
|
48937
|
+
}
|
|
48938
|
+
return await new Promise(async (resolve) => {
|
|
48939
|
+
const actionUrl = this.createSchemeLink(scheme);
|
|
48940
|
+
const _callback = (data) => {
|
|
48941
|
+
const d = JSON.parse(data);
|
|
48942
|
+
const callbackParam = (() => {
|
|
48943
|
+
if (d === 1)
|
|
48944
|
+
return true;
|
|
48945
|
+
if (d === 0)
|
|
48946
|
+
return false;
|
|
48947
|
+
return d;
|
|
48948
|
+
})();
|
|
48949
|
+
callback(callbackParam);
|
|
48950
|
+
res[0] = () => {
|
|
48951
|
+
// 清理掉当前的回调引用
|
|
48952
|
+
const callbacks = cache[actionUrl];
|
|
48953
|
+
if (!callbacks)
|
|
48954
|
+
return;
|
|
48955
|
+
const idx = callbacks.queue.findIndex((func) => func.callback === _callback);
|
|
48956
|
+
if (idx !== -1) {
|
|
48957
|
+
callbacks.queue.splice(idx, 1);
|
|
48958
|
+
}
|
|
48959
|
+
};
|
|
48960
|
+
resolve(res);
|
|
48961
|
+
};
|
|
48962
|
+
const msg = JSON.stringify({
|
|
48963
|
+
actionUrl,
|
|
48964
|
+
functionName: registerGlobalValue(actionUrl, _callback, false),
|
|
48965
|
+
});
|
|
48966
|
+
this.hybridBridge.callAndListen(msg);
|
|
48967
|
+
});
|
|
48968
|
+
}
|
|
48969
|
+
}
|
|
48970
|
+
|
|
48971
|
+
var CallTypeEnum;
|
|
48972
|
+
(function (CallTypeEnum) {
|
|
48973
|
+
CallTypeEnum["callAndBackfeed"] = "callAndBack";
|
|
48974
|
+
CallTypeEnum["callAndListen"] = "callAndListen";
|
|
48975
|
+
})(CallTypeEnum || (CallTypeEnum = {}));
|
|
48976
|
+
const $window = window;
|
|
48977
|
+
/**
|
|
48978
|
+
*
|
|
48979
|
+
* 将原本 JSBridgeApp 中的逻辑均聚合至此 Controller 实现,
|
|
48980
|
+
* 目的是规避太多的引用对象被暴露(防止因引用对象被'篡改'造成未知异常)。
|
|
48981
|
+
*
|
|
48982
|
+
*/
|
|
48983
|
+
class WKWebViewController {
|
|
48984
|
+
constructor() {
|
|
48985
|
+
this.checkBridgeReady();
|
|
48986
|
+
}
|
|
48987
|
+
checkBridgeReady(timeout = 6000) {
|
|
48988
|
+
if (this.worker)
|
|
48989
|
+
return true;
|
|
48990
|
+
const start = performance.now();
|
|
48991
|
+
return new Promise((resolve, reject) => {
|
|
48992
|
+
const check = () => {
|
|
48993
|
+
if (this.worker)
|
|
48994
|
+
return resolve(true);
|
|
48995
|
+
if ($window.webkit && $window.webkit.messageHandlers && $window.webkit.messageHandlers.realsee) {
|
|
48996
|
+
const worker = $window.webkit.messageHandlers.realsee;
|
|
48997
|
+
worker.postMessage(JSON.stringify({
|
|
48998
|
+
type: 'getStaticData',
|
|
48999
|
+
param: JSON.stringify({
|
|
49000
|
+
functionName: registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
|
|
49001
|
+
this.deviceInfo = JSON.parse(data);
|
|
49002
|
+
this.worker = worker;
|
|
49003
|
+
return resolve(true);
|
|
49004
|
+
})
|
|
49005
|
+
})
|
|
49006
|
+
}));
|
|
49007
|
+
return;
|
|
49008
|
+
}
|
|
49009
|
+
if (performance.now() - start > (timeout || 6000)) {
|
|
49010
|
+
// console.warn('HybridBridge 初始化超时~')
|
|
49011
|
+
return reject(new Error('HybridBridge 初始化超时~'));
|
|
49012
|
+
}
|
|
49013
|
+
// 逐帧监测
|
|
49014
|
+
requestAnimationFrame(check);
|
|
49015
|
+
};
|
|
49016
|
+
// 开启监测
|
|
49017
|
+
check();
|
|
49018
|
+
});
|
|
49019
|
+
}
|
|
49020
|
+
async checkReady(timeout = 6000) {
|
|
49021
|
+
const res = [null, null];
|
|
49022
|
+
if (this.worker) {
|
|
49023
|
+
res[0] = true;
|
|
49024
|
+
return res;
|
|
49025
|
+
}
|
|
49026
|
+
try {
|
|
49027
|
+
res[0] = await this.checkBridgeReady(timeout);
|
|
49028
|
+
}
|
|
49029
|
+
catch (error) {
|
|
49030
|
+
res[0] = false;
|
|
49031
|
+
res[1] = error;
|
|
49032
|
+
}
|
|
49033
|
+
return res;
|
|
49034
|
+
}
|
|
49035
|
+
get ready() {
|
|
49036
|
+
return !!this.worker;
|
|
49037
|
+
}
|
|
49038
|
+
get scheme() {
|
|
49039
|
+
var _a;
|
|
49040
|
+
return ((_a = this.deviceInfo) === null || _a === void 0 ? void 0 : _a.scheme) || '';
|
|
49041
|
+
}
|
|
49042
|
+
createSchemeLink(schemeUrl) {
|
|
49043
|
+
if (schemeUrl.startsWith(this.scheme)) {
|
|
49044
|
+
return schemeUrl;
|
|
49045
|
+
}
|
|
49046
|
+
return this.scheme + '://' + schemeUrl;
|
|
49047
|
+
}
|
|
49048
|
+
async callAndBackfeed(scheme) {
|
|
49049
|
+
const res = [false, null];
|
|
49050
|
+
const [ready, readyError] = await this.checkReady();
|
|
49051
|
+
if (!ready) {
|
|
49052
|
+
res[0] = false;
|
|
49053
|
+
res[1] = readyError;
|
|
49054
|
+
return res;
|
|
49055
|
+
}
|
|
49056
|
+
return await new Promise(async (resolve) => {
|
|
49057
|
+
const actionUrl = this.createSchemeLink(scheme);
|
|
49058
|
+
const msg = JSON.stringify({
|
|
49059
|
+
actionUrl,
|
|
49060
|
+
functionName: registerGlobalValue(this.createSchemeLink(scheme), (data) => {
|
|
49061
|
+
const d = JSON.parse(data);
|
|
49062
|
+
res[0] = (() => {
|
|
49063
|
+
if (d === 1)
|
|
49064
|
+
return true;
|
|
49065
|
+
if (d === 0)
|
|
49066
|
+
return false;
|
|
49067
|
+
return d;
|
|
49068
|
+
})();
|
|
49069
|
+
resolve(res);
|
|
49070
|
+
})
|
|
49071
|
+
});
|
|
49072
|
+
this.worker.postMessage(JSON.stringify({
|
|
49073
|
+
type: 'callAndBackfeed',
|
|
49074
|
+
param: msg
|
|
49075
|
+
}));
|
|
49076
|
+
});
|
|
49077
|
+
}
|
|
49078
|
+
async callAndListen(scheme, callback) {
|
|
49079
|
+
const res = [false, null];
|
|
49080
|
+
const [ready, readyError] = await this.checkReady();
|
|
49081
|
+
if (!ready) {
|
|
49082
|
+
res[0] = false;
|
|
49083
|
+
res[1] = readyError;
|
|
49084
|
+
return res;
|
|
49085
|
+
}
|
|
49086
|
+
return await new Promise(async (resolve) => {
|
|
49087
|
+
const actionUrl = this.createSchemeLink(scheme);
|
|
49088
|
+
const _callback = (data) => {
|
|
49089
|
+
const d = JSON.parse(data);
|
|
49090
|
+
const callbackParam = (() => {
|
|
49091
|
+
if (d === 1)
|
|
49092
|
+
return true;
|
|
49093
|
+
if (d === 0)
|
|
49094
|
+
return false;
|
|
49095
|
+
return d;
|
|
49096
|
+
})();
|
|
49097
|
+
callback(callbackParam);
|
|
49098
|
+
res[0] = () => {
|
|
49099
|
+
// 清理掉当前的回调引用
|
|
49100
|
+
const callbacks = cache[actionUrl];
|
|
49101
|
+
if (!callbacks)
|
|
49102
|
+
return;
|
|
49103
|
+
const idx = callbacks.queue.findIndex((func) => func.callback === _callback);
|
|
49104
|
+
if (idx !== -1) {
|
|
49105
|
+
callbacks.queue.splice(idx, 1);
|
|
49106
|
+
}
|
|
49107
|
+
};
|
|
49108
|
+
resolve(res);
|
|
49109
|
+
};
|
|
49110
|
+
const msg = JSON.stringify({
|
|
49111
|
+
actionUrl,
|
|
49112
|
+
functionName: registerGlobalValue(actionUrl, _callback, false)
|
|
49113
|
+
});
|
|
49114
|
+
this.worker.postMessage(JSON.stringify({
|
|
49115
|
+
type: 'callAndListen',
|
|
49116
|
+
param: msg,
|
|
49117
|
+
}));
|
|
49118
|
+
});
|
|
49119
|
+
}
|
|
49120
|
+
}
|
|
49121
|
+
|
|
49122
|
+
// uuid
|
|
49123
|
+
function S4() {
|
|
49124
|
+
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
|
49125
|
+
}
|
|
49126
|
+
/**
|
|
49127
|
+
* 随机生成一个uuid值
|
|
49128
|
+
*/
|
|
49129
|
+
function uuid() {
|
|
49130
|
+
// then to call it, plus stitch in '4' in the third group
|
|
49131
|
+
return (S4() + S4() + '-' + S4() + '-4' + S4().substr(0, 3) +
|
|
49132
|
+
'-' + S4() + '-' + S4() + S4() + S4()).toLowerCase();
|
|
49133
|
+
}
|
|
49134
|
+
|
|
49135
|
+
/**
|
|
49136
|
+
* 事件消息
|
|
49137
|
+
*/
|
|
49138
|
+
var WeappBridgeMessage;
|
|
49139
|
+
(function (WeappBridgeMessage) {
|
|
49140
|
+
WeappBridgeMessage["isReady"] = "Are You OK?";
|
|
49141
|
+
WeappBridgeMessage["ready"] = "I`m OK!";
|
|
49142
|
+
WeappBridgeMessage["ping"] = "ping";
|
|
49143
|
+
WeappBridgeMessage["pong"] = "pong";
|
|
49144
|
+
WeappBridgeMessage["alive"] = "I`m alive!";
|
|
49145
|
+
})(WeappBridgeMessage || (WeappBridgeMessage = {}));
|
|
49146
|
+
|
|
49147
|
+
/**
|
|
49148
|
+
* ws的状态
|
|
49149
|
+
* 参考https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
|
49150
|
+
*/
|
|
49151
|
+
var WebSocketState;
|
|
49152
|
+
(function (WebSocketState) {
|
|
49153
|
+
WebSocketState[WebSocketState["CONNECTING"] = 0] = "CONNECTING";
|
|
49154
|
+
WebSocketState[WebSocketState["OPEN"] = 1] = "OPEN";
|
|
49155
|
+
WebSocketState[WebSocketState["CLOSING"] = 2] = "CLOSING";
|
|
49156
|
+
WebSocketState[WebSocketState["CLOSED"] = 3] = "CLOSED";
|
|
49157
|
+
})(WebSocketState || (WebSocketState = {}));
|
|
49158
|
+
|
|
49159
|
+
/**
|
|
49160
|
+
* ws 关闭的原因
|
|
49161
|
+
*/
|
|
49162
|
+
const WebSocketCloseOptions = {
|
|
49163
|
+
/**
|
|
49164
|
+
* 重连关闭
|
|
49165
|
+
*/
|
|
49166
|
+
reconnect: { code: 1000, reason: 'close websocket when reconnecting' },
|
|
49167
|
+
/**
|
|
49168
|
+
* 主动关闭
|
|
49169
|
+
*/
|
|
49170
|
+
normalClosure: { code: 1000, reason: 'normal closure' },
|
|
49171
|
+
/**
|
|
49172
|
+
* 强制关闭
|
|
49173
|
+
*/
|
|
49174
|
+
forceClosure: { code: 1000, reason: 'force closure' },
|
|
49175
|
+
/**
|
|
49176
|
+
* 切换到后台,被微信杀掉,需要重连连接
|
|
49177
|
+
*/
|
|
49178
|
+
interrupted: { code: 1000, reason: 'interrupted' },
|
|
49179
|
+
/**
|
|
49180
|
+
* 服务端拒绝连接
|
|
49181
|
+
*/
|
|
49182
|
+
streamEndEncountered: { code: 1000, reason: 'stream end encountered' },
|
|
49183
|
+
/**
|
|
49184
|
+
* 丢失心跳
|
|
49185
|
+
* @deprecated
|
|
49186
|
+
*/
|
|
49187
|
+
lostHeartbeat: { code: 1000, reason: 'lost heartbeat' },
|
|
49188
|
+
};
|
|
49189
|
+
|
|
49190
|
+
const EVENT_SYMBOL = '$$REALSEE_JSBRIDGE_EVENT$$';
|
|
49191
|
+
function __generateEventIfNotExisted(instance) {
|
|
49192
|
+
if (!instance[EVENT_SYMBOL]) {
|
|
49193
|
+
instance[EVENT_SYMBOL] = {};
|
|
49194
|
+
}
|
|
49195
|
+
return instance[EVENT_SYMBOL];
|
|
49196
|
+
}
|
|
49197
|
+
function __removeEventIfNotExisted(instance) {
|
|
49198
|
+
if (!instance[EVENT_SYMBOL]) {
|
|
49199
|
+
delete instance[EVENT_SYMBOL];
|
|
49200
|
+
}
|
|
49201
|
+
}
|
|
49202
|
+
/**
|
|
49203
|
+
* 监听者模式
|
|
49204
|
+
* @template T 预设的监听回调类型
|
|
49205
|
+
* @example
|
|
49206
|
+
* ```
|
|
49207
|
+
* new Subscribe<{
|
|
49208
|
+
* "foo": [arg1: number, arg2: string],
|
|
49209
|
+
* "bar": [arg: boolean],
|
|
49210
|
+
* }>()
|
|
49211
|
+
* ```
|
|
49212
|
+
*/
|
|
49213
|
+
class Subscribe {
|
|
49214
|
+
/**
|
|
49215
|
+
* 判断是否注册了事件
|
|
49216
|
+
* @param name 事件类型
|
|
49217
|
+
*/
|
|
49218
|
+
hasListener(name) {
|
|
49219
|
+
const events = __generateEventIfNotExisted(this);
|
|
49220
|
+
return events && events[name] && events[name].length > 0;
|
|
49221
|
+
}
|
|
49222
|
+
/**
|
|
49223
|
+
* 注册事件
|
|
49224
|
+
* @param name 事件类型
|
|
49225
|
+
* @param callback 事件回调函数
|
|
49226
|
+
* @param once 是否只执行一次
|
|
49227
|
+
* @returns 解除事件
|
|
49228
|
+
* @template K 预设的监听事件名称
|
|
49229
|
+
* @template C 回调函数函数上下文
|
|
49230
|
+
*/
|
|
49231
|
+
on(name, callback, once) {
|
|
49232
|
+
const events = __generateEventIfNotExisted(this);
|
|
49233
|
+
if (!events[name])
|
|
49234
|
+
events[name] = [];
|
|
49235
|
+
events[name].push([callback, once || false]);
|
|
49236
|
+
return () => this.off(name, callback);
|
|
49237
|
+
}
|
|
49238
|
+
/**
|
|
49239
|
+
* 注册事件(是否只执行一次)
|
|
49240
|
+
* @param name 事件类型
|
|
49241
|
+
* @param callback 事件回调函数
|
|
49242
|
+
* @returns 解除事件
|
|
49243
|
+
* @template K 预设的监听事件名称
|
|
49244
|
+
* @template C 回调函数函数上下文
|
|
49245
|
+
*/
|
|
49246
|
+
once(name, callback) {
|
|
49247
|
+
return this.on(name, callback, true);
|
|
49248
|
+
}
|
|
49249
|
+
/**
|
|
49250
|
+
* 解除事件
|
|
49251
|
+
*
|
|
49252
|
+
* 如果 name 不传的话解除对应所有事件
|
|
49253
|
+
* 如果 name, callback 不传的话解除所有name的所有事件
|
|
49254
|
+
* @param name 事件类型
|
|
49255
|
+
* @param callback 事件回调函数
|
|
49256
|
+
* @template K 预设的监听事件名称
|
|
49257
|
+
*/
|
|
49258
|
+
off(name, callback) {
|
|
49259
|
+
if (name === undefined) {
|
|
49260
|
+
__removeEventIfNotExisted(this);
|
|
49261
|
+
return;
|
|
49262
|
+
}
|
|
49263
|
+
const events = __generateEventIfNotExisted(this);
|
|
49264
|
+
if (!events[name])
|
|
49265
|
+
events[name] = [];
|
|
49266
|
+
if (callback === undefined) {
|
|
49267
|
+
events[name].length = 0;
|
|
49268
|
+
return;
|
|
49269
|
+
}
|
|
49270
|
+
let index = 0;
|
|
49271
|
+
for (; index < events[name].length; index++) {
|
|
49272
|
+
if (events[name][index][0] === callback)
|
|
49273
|
+
break;
|
|
49274
|
+
}
|
|
49275
|
+
if (index < events[name].length) {
|
|
49276
|
+
events[name].splice(index, 1);
|
|
49277
|
+
}
|
|
49278
|
+
}
|
|
49279
|
+
/**
|
|
49280
|
+
* 触发事件
|
|
49281
|
+
* @param name 事件类型
|
|
49282
|
+
* @param data 触发事件的数据
|
|
49283
|
+
* @returns canceled 是否被触发取消
|
|
49284
|
+
* @template K 预设的监听事件名称
|
|
49285
|
+
*/
|
|
49286
|
+
emit(name, ...data) {
|
|
49287
|
+
let canceled = false;
|
|
49288
|
+
const events = __generateEventIfNotExisted(this);
|
|
49289
|
+
const event = events[name] || [];
|
|
49290
|
+
for (const one of event.slice()) {
|
|
49291
|
+
const [callback, once = false] = one;
|
|
49292
|
+
const result = callback(...data);
|
|
49293
|
+
if (once)
|
|
49294
|
+
this.off(name, callback);
|
|
49295
|
+
if (result === false)
|
|
49296
|
+
canceled = true;
|
|
49297
|
+
}
|
|
49298
|
+
return canceled;
|
|
49299
|
+
}
|
|
49300
|
+
}
|
|
49301
|
+
|
|
49302
|
+
/**
|
|
49303
|
+
* ws的事件
|
|
49304
|
+
*/
|
|
49305
|
+
var WebSocketEvent;
|
|
49306
|
+
(function (WebSocketEvent) {
|
|
49307
|
+
WebSocketEvent["open"] = "open";
|
|
49308
|
+
WebSocketEvent["close"] = "close";
|
|
49309
|
+
WebSocketEvent["error"] = "error";
|
|
49310
|
+
WebSocketEvent["message"] = "message";
|
|
49311
|
+
})(WebSocketEvent || (WebSocketEvent = {}));
|
|
49312
|
+
|
|
49313
|
+
class Ws4Webview extends Subscribe {
|
|
49314
|
+
constructor() {
|
|
49315
|
+
super(...arguments);
|
|
49316
|
+
this._state = null;
|
|
49317
|
+
/**
|
|
49318
|
+
* @description 注册ws接通事件回调
|
|
49319
|
+
* @param listener 事件回调函数
|
|
49320
|
+
* @param once 是否只执行一次
|
|
49321
|
+
* @returns
|
|
49322
|
+
*/
|
|
49323
|
+
this.onOpen = (listener, once) => once ? this.once(WebSocketEvent.open, listener) : this.on(WebSocketEvent.open, listener);
|
|
49324
|
+
/**
|
|
49325
|
+
* @description 注册一次ws接通事件回调
|
|
49326
|
+
* @param listener 事件回调函数
|
|
49327
|
+
*/
|
|
49328
|
+
this.onceOpen = (listener) => this.onOpen(listener, true);
|
|
49329
|
+
/**
|
|
49330
|
+
* @description 移除ws接通事件回调
|
|
49331
|
+
* @param listener 事件回调函数
|
|
49332
|
+
* @returns
|
|
49333
|
+
*/
|
|
49334
|
+
this.offOpen = (listener) => this.hasListener(WebSocketEvent.open) && this.off(WebSocketEvent.open, listener);
|
|
49335
|
+
/**
|
|
49336
|
+
* @description 注册ws消息事件回调
|
|
49337
|
+
* @param listener 事件回调函数
|
|
49338
|
+
* @param once 是否只执行一次
|
|
49339
|
+
* @returns
|
|
49340
|
+
*/
|
|
49341
|
+
this.onMessage = (listener, once) => once ? this.once(WebSocketEvent.message, listener) : this.on(WebSocketEvent.message, listener);
|
|
49342
|
+
/**
|
|
49343
|
+
* @description 注册一次ws消息事件回调
|
|
49344
|
+
* @param listener 事件回调函数
|
|
49345
|
+
*/
|
|
49346
|
+
this.onceMessage = (listener) => this.onMessage(listener, true);
|
|
49347
|
+
/**
|
|
49348
|
+
* @description 移除ws接通事件回调
|
|
49349
|
+
* @param listener 事件回调函数
|
|
49350
|
+
* @returns
|
|
49351
|
+
*/
|
|
49352
|
+
this.offMessage = (listener) => this.hasListener(WebSocketEvent.message) && this.off(WebSocketEvent.message, listener);
|
|
49353
|
+
/**
|
|
49354
|
+
* @description 注册ws错误事件回调
|
|
49355
|
+
* @param listener 事件回调函数
|
|
49356
|
+
* @param once 是否只执行一次
|
|
49357
|
+
* @returns
|
|
49358
|
+
*/
|
|
49359
|
+
this.onError = (listener, once) => once ? this.once(WebSocketEvent.error, listener) : this.on(WebSocketEvent.error, listener);
|
|
49360
|
+
/**
|
|
49361
|
+
* @description 注册一次ws消息事件回调
|
|
49362
|
+
* @param listener 事件回调函数
|
|
49363
|
+
*/
|
|
49364
|
+
this.onceError = (listener) => this.onError(listener, true);
|
|
49365
|
+
/**
|
|
49366
|
+
* @description 移除ws接通事件回调
|
|
49367
|
+
* @param listener 事件回调函数
|
|
49368
|
+
* @returns
|
|
49369
|
+
*/
|
|
49370
|
+
this.offError = (listener) => this.hasListener(WebSocketEvent.error) && this.off(WebSocketEvent.error, listener);
|
|
49371
|
+
/**
|
|
49372
|
+
* @description 注册ws错误事件回调
|
|
49373
|
+
* @param listener 事件回调函数
|
|
49374
|
+
* @param once 是否只执行一次
|
|
49375
|
+
* @returns
|
|
49376
|
+
*/
|
|
49377
|
+
this.onClose = (listener, once) => once ? this.once(WebSocketEvent.close, listener) : this.on(WebSocketEvent.close, listener);
|
|
49378
|
+
/**
|
|
49379
|
+
* @description 注册一次ws消息事件回调
|
|
49380
|
+
* @param listener 事件回调函数
|
|
49381
|
+
*/
|
|
49382
|
+
this.onceClose = (listener) => this.onClose(listener, true);
|
|
49383
|
+
/**
|
|
49384
|
+
* @description 移除ws接通事件回调
|
|
49385
|
+
* @param listener 事件回调函数
|
|
49386
|
+
* @returns
|
|
49387
|
+
*/
|
|
49388
|
+
this.offClose = (listener) => this.hasListener(WebSocketEvent.close) && this.off(WebSocketEvent.close, listener);
|
|
49389
|
+
}
|
|
49390
|
+
get readyState() {
|
|
49391
|
+
return this._state;
|
|
49392
|
+
}
|
|
49393
|
+
/**
|
|
49394
|
+
* 连接ws
|
|
49395
|
+
* @param options
|
|
49396
|
+
*/
|
|
49397
|
+
connect(options) {
|
|
49398
|
+
if (this._state === WebSocketState.CONNECTING || this._state === WebSocketState.OPEN)
|
|
49399
|
+
return Promise.reject("\u5DF2\u5B58\u5728\u4E00\u4E2A\u8FDE\u63A5\u4E2D\u6216\u6253\u5F00\u72B6\u6001\u7684websocket\u5B9E\u4F8B" /* ErrorMessage.WsAlreadyExists */);
|
|
49400
|
+
return new Promise((resolve, reject) => {
|
|
49401
|
+
const { url } = options;
|
|
49402
|
+
if (!url)
|
|
49403
|
+
throw new Error("\u975E\u6CD5\u7684websocket\u94FE\u63A5" /* ErrorMessage.WsUrlInvalid */);
|
|
49404
|
+
this._wsOptions = options;
|
|
49405
|
+
this._state = WebSocketState.CONNECTING;
|
|
49406
|
+
this._wsTask = new WebSocket(url);
|
|
49407
|
+
this.registerEventHandler();
|
|
49408
|
+
this.handleConnected();
|
|
49409
|
+
this.onceOpen(() => resolve(true));
|
|
49410
|
+
this.onceError((err) => reject(err));
|
|
49411
|
+
});
|
|
49412
|
+
}
|
|
49413
|
+
/**
|
|
49414
|
+
* 重连websocket
|
|
49415
|
+
* @returns
|
|
49416
|
+
*/
|
|
49417
|
+
async reconnect() {
|
|
49418
|
+
this.close(WebSocketCloseOptions.reconnect);
|
|
49419
|
+
if (this._wsOptions)
|
|
49420
|
+
this.connect(this._wsOptions);
|
|
49421
|
+
}
|
|
49422
|
+
/**
|
|
49423
|
+
* @description 发送消息
|
|
49424
|
+
* @param data 消息体
|
|
49425
|
+
*/
|
|
49426
|
+
send(data) {
|
|
49427
|
+
try {
|
|
49428
|
+
if (this._wsTask && this.readyState === WebSocketState.OPEN) {
|
|
49429
|
+
this._wsTask.send(data);
|
|
49430
|
+
}
|
|
49431
|
+
else if (this._wsTask && this.readyState === WebSocketState.CONNECTING) {
|
|
49432
|
+
this.once(WebSocketEvent.open, () => { var _a; return (_a = this._wsTask) === null || _a === void 0 ? void 0 : _a.send(data); });
|
|
49433
|
+
}
|
|
49434
|
+
else {
|
|
49435
|
+
this.once(WebSocketEvent.open, () => this.send(data));
|
|
49436
|
+
this.reconnect();
|
|
49437
|
+
}
|
|
49438
|
+
}
|
|
49439
|
+
catch (e) {
|
|
49440
|
+
this.once(WebSocketEvent.open, () => this.send(data));
|
|
49441
|
+
this.reconnect();
|
|
49442
|
+
}
|
|
49443
|
+
}
|
|
49444
|
+
/**
|
|
49445
|
+
* @description 手动关闭ws
|
|
49446
|
+
* @param options 关闭ws的配置参数
|
|
49447
|
+
*/
|
|
49448
|
+
close(options) {
|
|
49449
|
+
var _a;
|
|
49450
|
+
this._state = WebSocketState.CLOSING;
|
|
49451
|
+
(_a = this._wsTask) === null || _a === void 0 ? void 0 : _a.close(options.code, options.reason);
|
|
49452
|
+
}
|
|
49453
|
+
/**
|
|
49454
|
+
* 处理连接后的事件绑定
|
|
49455
|
+
*/
|
|
49456
|
+
handleConnected() {
|
|
49457
|
+
this.onceOpen(() => (this._state = WebSocketState.OPEN));
|
|
49458
|
+
this.onClose(() => (this._state = WebSocketState.CLOSED));
|
|
49459
|
+
}
|
|
49460
|
+
/**
|
|
49461
|
+
* 注册websocket事件
|
|
49462
|
+
*/
|
|
49463
|
+
registerEventHandler() {
|
|
49464
|
+
var _a, _b, _c, _d;
|
|
49465
|
+
(_a = this._wsTask) === null || _a === void 0 ? void 0 : _a.addEventListener(WebSocketEvent.open, (ev) => this.emit(WebSocketEvent.open, ev));
|
|
49466
|
+
(_b = this._wsTask) === null || _b === void 0 ? void 0 : _b.addEventListener(WebSocketEvent.message, (result) => {
|
|
49467
|
+
let data = result.data;
|
|
49468
|
+
try {
|
|
49469
|
+
if (typeof result.data === 'string') {
|
|
49470
|
+
data = JSON.parse(result.data);
|
|
49471
|
+
}
|
|
49472
|
+
}
|
|
49473
|
+
catch (e) {
|
|
49474
|
+
/** 不可序列化的数据不用处理 */
|
|
49475
|
+
}
|
|
49476
|
+
this.emit(WebSocketEvent.message, data);
|
|
49477
|
+
});
|
|
49478
|
+
(_c = this._wsTask) === null || _c === void 0 ? void 0 : _c.addEventListener(WebSocketEvent.close, (ev) => this.emit(WebSocketEvent.close, ev));
|
|
49479
|
+
(_d = this._wsTask) === null || _d === void 0 ? void 0 : _d.addEventListener(WebSocketEvent.error, (ev) => this.emit(WebSocketEvent.error, ev));
|
|
49480
|
+
}
|
|
49481
|
+
}
|
|
49482
|
+
var Ws4Webview$1 = Ws4Webview;
|
|
49483
|
+
|
|
49484
|
+
const endpoint = 'wss://ws.realsee.com';
|
|
49485
|
+
var defaultWsEndpoint = endpoint;
|
|
49486
|
+
|
|
49487
|
+
/**
|
|
49488
|
+
* 拼接ws链接
|
|
49489
|
+
* @param tpl
|
|
49490
|
+
* @param params
|
|
49491
|
+
* @returns
|
|
49492
|
+
*/
|
|
49493
|
+
const generateWssUrl = (tpl, params) => {
|
|
49494
|
+
const url = Object.keys(params).reduce((res, curr) => res.replace(`{{${curr}}}`, `${params[curr]}`), tpl);
|
|
49495
|
+
return encodeURI(url);
|
|
49496
|
+
};
|
|
49497
|
+
var generateWssUrl$1 = generateWssUrl;
|
|
49498
|
+
|
|
49499
|
+
const isValidKey = (key, object) => key in object;
|
|
49500
|
+
var isValidKey$1 = isValidKey;
|
|
49501
|
+
|
|
49502
|
+
/**
|
|
49503
|
+
* 解析参数
|
|
49504
|
+
* @param query
|
|
49505
|
+
* @returns
|
|
49506
|
+
*/
|
|
49507
|
+
const parseQuery = (query = '') => query
|
|
49508
|
+
.replace('?', '')
|
|
49509
|
+
.split('&')
|
|
49510
|
+
.map((qs) => {
|
|
49511
|
+
const [k, v] = qs.split('=');
|
|
49512
|
+
return { [k]: decodeURIComponent(v) };
|
|
49513
|
+
})
|
|
49514
|
+
.reduce((result, curr) => ({ ...result, ...curr }), {});
|
|
49515
|
+
var parseQuery$1 = parseQuery;
|
|
49516
|
+
|
|
49517
|
+
const ws = (() => new Ws4Webview$1())();
|
|
49518
|
+
class HybridBridge {
|
|
49519
|
+
constructor() {
|
|
49520
|
+
/**
|
|
49521
|
+
* @deprecated 兼容旧逻辑
|
|
49522
|
+
*/
|
|
49523
|
+
this._rsWeappBridgeMethodAdapter = {};
|
|
49524
|
+
this._forceClose = false;
|
|
49525
|
+
/**
|
|
49526
|
+
* 进行jsbridge的初始化,即打通ws通道
|
|
49527
|
+
* @param timeout 超时计时
|
|
49528
|
+
* @returns
|
|
49529
|
+
*/
|
|
49530
|
+
this.initialize = async (timeout = 6000) => {
|
|
49531
|
+
const res = [false, null];
|
|
49532
|
+
const { wssid, wstsp, wssig, wsmnt = defaultWsEndpoint, } = parseQuery$1(globalThis.location.search);
|
|
49533
|
+
if (!(wssid && wstsp && wssig && wsmnt)) {
|
|
49534
|
+
res[1] = new Error('HybridBridge 参数缺失,初始化失败~');
|
|
49535
|
+
return res;
|
|
49536
|
+
}
|
|
49537
|
+
const url = generateWssUrl$1('{{origin}}/{{endpoint}}/{{uuid}}/{{member}}/{{ak}}/{{ts}}/{{sign}}', {
|
|
49538
|
+
origin: wsmnt,
|
|
49539
|
+
endpoint: 'proxy',
|
|
49540
|
+
uuid: wssid,
|
|
49541
|
+
member: 'webview',
|
|
49542
|
+
ak: 'vr_live_miniapp',
|
|
49543
|
+
ts: wstsp,
|
|
49544
|
+
sign: wssig,
|
|
49545
|
+
});
|
|
49546
|
+
try {
|
|
49547
|
+
const result = await ws.connect({ url });
|
|
49548
|
+
if (result) {
|
|
49549
|
+
this.initBuiltInHandlers();
|
|
49550
|
+
res[0] = await this.waitReady(timeout);
|
|
49551
|
+
}
|
|
49552
|
+
else {
|
|
49553
|
+
res[1] = new Error('HybridBridge ws未连接,初始化失败~');
|
|
49554
|
+
}
|
|
49555
|
+
}
|
|
49556
|
+
catch (e) {
|
|
49557
|
+
res[1] = e;
|
|
49558
|
+
}
|
|
49559
|
+
return res;
|
|
49560
|
+
};
|
|
49561
|
+
this.getStaticData = (callbackFunctionName) => {
|
|
49562
|
+
this.callAndBackfeed(JSON.stringify({
|
|
49563
|
+
actionUrl: 'common/staticData',
|
|
49564
|
+
functionName: callbackFunctionName,
|
|
49565
|
+
}));
|
|
49566
|
+
};
|
|
49567
|
+
/**
|
|
49568
|
+
* 处理一次性执行的方法
|
|
49569
|
+
* @param msg JSON.stringify({ actionUrl: string, functionName: string })
|
|
49570
|
+
*/
|
|
49571
|
+
this.callAndBackfeed = (msg) => {
|
|
49572
|
+
const { actionUrl = '', functionName = '' } = JSON.parse(msg);
|
|
49573
|
+
if (!actionUrl)
|
|
49574
|
+
throw new Error('callAndBackfeed actionUrl is empty!');
|
|
49575
|
+
if (!functionName)
|
|
49576
|
+
throw new Error('callAndBackfeed functionName is empty!');
|
|
49577
|
+
const callback = (result) => {
|
|
49578
|
+
if (typeof globalThis[functionName] === 'function') {
|
|
49579
|
+
globalThis[functionName](result);
|
|
49580
|
+
}
|
|
49581
|
+
};
|
|
49582
|
+
this._callAndBackfeed(actionUrl, callback);
|
|
49583
|
+
};
|
|
49584
|
+
/**
|
|
49585
|
+
* 处理监听
|
|
49586
|
+
* @param msg JSON.stringify({ actionUrl: string, functionName: string })
|
|
49587
|
+
*/
|
|
49588
|
+
this.callAndListen = (msg) => {
|
|
49589
|
+
const { actionUrl, functionName } = JSON.parse(msg);
|
|
49590
|
+
if (!actionUrl)
|
|
49591
|
+
throw new Error('callAndListen actionUrl is empty!');
|
|
49592
|
+
if (!functionName)
|
|
49593
|
+
throw new Error('callAndListen functionName is empty!');
|
|
49594
|
+
const callback = (result) => {
|
|
49595
|
+
if (typeof globalThis[functionName] === 'function') {
|
|
49596
|
+
globalThis[functionName](result);
|
|
49597
|
+
}
|
|
49598
|
+
};
|
|
49599
|
+
try {
|
|
49600
|
+
this._callAndListen(actionUrl, callback);
|
|
49601
|
+
}
|
|
49602
|
+
catch (e) {
|
|
49603
|
+
console.warn(e);
|
|
49604
|
+
callback(false);
|
|
49605
|
+
}
|
|
49606
|
+
};
|
|
49607
|
+
}
|
|
49608
|
+
get isReady() {
|
|
49609
|
+
return ws.readyState === WebSocketState.OPEN;
|
|
49610
|
+
}
|
|
49611
|
+
/**
|
|
49612
|
+
* 内建的处理函数
|
|
49613
|
+
*/
|
|
49614
|
+
initBuiltInHandlers() {
|
|
49615
|
+
this._registerLifecycleHandler();
|
|
49616
|
+
this._registerHeartbeatHandler();
|
|
49617
|
+
this._registerMessageHandler();
|
|
49618
|
+
this._registerBridgeRequestHandler();
|
|
49619
|
+
this._registerReadyHandler();
|
|
49620
|
+
}
|
|
49621
|
+
/**
|
|
49622
|
+
* 注册生命周期回调
|
|
49623
|
+
*/
|
|
49624
|
+
_registerLifecycleHandler() {
|
|
49625
|
+
ws.onOpen(() => console.log('RsWeappBridge open'));
|
|
49626
|
+
ws.onClose((res) => {
|
|
49627
|
+
console.log('RsWeappBridge close');
|
|
49628
|
+
if (res.code === 1000) {
|
|
49629
|
+
switch ((res.reason + '').toLowerCase()) {
|
|
49630
|
+
case WebSocketCloseOptions.lostHeartbeat.reason: {
|
|
49631
|
+
// 心跳丢失
|
|
49632
|
+
ws.reconnect();
|
|
49633
|
+
break;
|
|
49634
|
+
}
|
|
49635
|
+
// case WebSocketCloseOptions.normalClosure.reason: // 主动关闭
|
|
49636
|
+
case WebSocketCloseOptions.interrupted.reason: // 切换到后台,被微信杀掉,需要重连连接
|
|
49637
|
+
case WebSocketCloseOptions.streamEndEncountered.reason: // 服务端拒绝连接
|
|
49638
|
+
default: {
|
|
49639
|
+
if (!this._forceClose) {
|
|
49640
|
+
ws.reconnect();
|
|
49641
|
+
}
|
|
49642
|
+
break;
|
|
49643
|
+
}
|
|
49644
|
+
}
|
|
49645
|
+
}
|
|
49646
|
+
if (res.code !== 1000 && !this._forceClose) {
|
|
49647
|
+
ws.reconnect();
|
|
49648
|
+
}
|
|
49649
|
+
if (this._forceClose)
|
|
49650
|
+
this._forceClose = false;
|
|
49651
|
+
});
|
|
49652
|
+
ws.onError((err) => console.error(err));
|
|
49653
|
+
}
|
|
49654
|
+
/**
|
|
49655
|
+
* 注册心跳的回调
|
|
49656
|
+
* @deprecated 兼容老的容器SDK
|
|
49657
|
+
*/
|
|
49658
|
+
_registerHeartbeatHandler() {
|
|
49659
|
+
// 收到ping时回复pong
|
|
49660
|
+
this._receivedMessage(WeappBridgeMessage.ping, () => ws.send(WeappBridgeMessage.pong));
|
|
49661
|
+
// 收到pong时回复ping
|
|
49662
|
+
this._receivedMessage(WeappBridgeMessage.pong, () => ws.send(WeappBridgeMessage.ping));
|
|
49663
|
+
}
|
|
49664
|
+
/**
|
|
49665
|
+
* 当收到某消息时
|
|
49666
|
+
* @param targetMessage 目标消息
|
|
49667
|
+
* @param handler 回调
|
|
49668
|
+
* @param once 是否一次性处理
|
|
49669
|
+
*/
|
|
49670
|
+
_receivedMessage(targetMessage, handler, once) {
|
|
49671
|
+
const msgHandler = (msg) => {
|
|
49672
|
+
if (msg === targetMessage) {
|
|
49673
|
+
handler();
|
|
49674
|
+
if (once) {
|
|
49675
|
+
ws.offMessage(msgHandler);
|
|
49676
|
+
}
|
|
49677
|
+
}
|
|
49678
|
+
};
|
|
49679
|
+
ws.onMessage(msgHandler);
|
|
49680
|
+
}
|
|
49681
|
+
/**
|
|
49682
|
+
* 强制关闭ws
|
|
49683
|
+
* @param options
|
|
49684
|
+
*/
|
|
49685
|
+
forceClose(options) {
|
|
49686
|
+
this._forceClose = true;
|
|
49687
|
+
ws.close(options);
|
|
49688
|
+
}
|
|
49689
|
+
/**
|
|
49690
|
+
* 注册准备就绪的回调
|
|
49691
|
+
*/
|
|
49692
|
+
_registerReadyHandler() {
|
|
49693
|
+
// 收到就绪询问时回复已就绪
|
|
49694
|
+
this._receivedMessage(WeappBridgeMessage.isReady, () => ws.send(WeappBridgeMessage.ready));
|
|
49695
|
+
}
|
|
49696
|
+
/**
|
|
49697
|
+
* 发送消息
|
|
49698
|
+
*/
|
|
49699
|
+
send(data) {
|
|
49700
|
+
ws.send(data);
|
|
49701
|
+
}
|
|
49702
|
+
/**
|
|
49703
|
+
* 等待响应
|
|
49704
|
+
* @param timeout 超时计时
|
|
49705
|
+
* @returns
|
|
49706
|
+
*/
|
|
49707
|
+
waitReady(timeout = 6000) {
|
|
49708
|
+
return new Promise((resolve, reject) => {
|
|
49709
|
+
this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true));
|
|
49710
|
+
this.send(WeappBridgeMessage.isReady);
|
|
49711
|
+
setTimeout(() => reject('HybridBridge 初始化超时~'), timeout);
|
|
49712
|
+
});
|
|
49713
|
+
}
|
|
49714
|
+
/**
|
|
49715
|
+
* 注册消息投递回调
|
|
49716
|
+
* @deprecated 兼容老方法
|
|
49717
|
+
*/
|
|
49718
|
+
_registerMessageHandler() {
|
|
49719
|
+
ws.onMessage((message) => {
|
|
49720
|
+
if (typeof message === 'object') {
|
|
49721
|
+
const { id, command, data } = message;
|
|
49722
|
+
if (command === 'message' &&
|
|
49723
|
+
typeof this._rsWeappBridgeMethodAdapter.bindMessage === 'function') {
|
|
49724
|
+
this._rsWeappBridgeMethodAdapter.bindMessage({ id, data });
|
|
49725
|
+
}
|
|
49726
|
+
}
|
|
49727
|
+
});
|
|
49728
|
+
}
|
|
49729
|
+
/**
|
|
49730
|
+
* 注册bridge方法回调
|
|
49731
|
+
* @deprecated 兼容老方法
|
|
49732
|
+
*/
|
|
49733
|
+
_registerBridgeRequestHandler() {
|
|
49734
|
+
ws.onMessage(async (request) => {
|
|
49735
|
+
if (typeof request === 'object') {
|
|
49736
|
+
const { id, method, args, command } = request;
|
|
49737
|
+
if (command === 'request') {
|
|
49738
|
+
if (method) {
|
|
49739
|
+
let result = null;
|
|
49740
|
+
let error = null;
|
|
49741
|
+
let _method = null;
|
|
49742
|
+
if (typeof this._rsWeappBridgeMethodAdapter[method] === 'function') {
|
|
49743
|
+
// 优先读 _rsWeappBridgeMethodAdapter 上注册的方法
|
|
49744
|
+
_method = this._rsWeappBridgeMethodAdapter[method];
|
|
49745
|
+
}
|
|
49746
|
+
else if (globalThis && isValidKey$1(method, globalThis)) {
|
|
49747
|
+
// 再读 globalThis 下的方法
|
|
49748
|
+
_method = globalThis[method];
|
|
49749
|
+
}
|
|
49750
|
+
if (typeof _method === 'function') {
|
|
49751
|
+
try {
|
|
49752
|
+
result = await _method(args);
|
|
49753
|
+
}
|
|
49754
|
+
catch (e) {
|
|
49755
|
+
error = e.message || e;
|
|
49756
|
+
}
|
|
49757
|
+
}
|
|
49758
|
+
else {
|
|
49759
|
+
error = 'Method not implemented.';
|
|
49760
|
+
}
|
|
49761
|
+
this.send(JSON.stringify({
|
|
49762
|
+
id,
|
|
49763
|
+
method,
|
|
49764
|
+
result,
|
|
49765
|
+
error,
|
|
49766
|
+
command: 'response',
|
|
49767
|
+
}));
|
|
49768
|
+
}
|
|
49769
|
+
}
|
|
49770
|
+
}
|
|
49771
|
+
});
|
|
49772
|
+
}
|
|
49773
|
+
/**
|
|
49774
|
+
* 处理 callAndBackfeed
|
|
49775
|
+
* @param actionUrl
|
|
49776
|
+
* @param backfeed
|
|
49777
|
+
*/
|
|
49778
|
+
_callAndBackfeed(actionUrl, backfeed) {
|
|
49779
|
+
const reqId = uuid();
|
|
49780
|
+
const data = JSON.stringify({
|
|
49781
|
+
id: reqId,
|
|
49782
|
+
actionUrl,
|
|
49783
|
+
command: 'rsSchemeRequest',
|
|
49784
|
+
type: 'callAndBackfeed',
|
|
49785
|
+
});
|
|
49786
|
+
let timer = null;
|
|
49787
|
+
const callback = (message) => {
|
|
49788
|
+
const { id, result, errmsg, command } = message;
|
|
49789
|
+
if (command === 'rsSchemeResponse' && id === reqId) {
|
|
49790
|
+
ws.offMessage(callback);
|
|
49791
|
+
if (timer)
|
|
49792
|
+
clearTimeout(timer);
|
|
49793
|
+
if (errmsg) {
|
|
49794
|
+
console.warn(errmsg);
|
|
49795
|
+
backfeed(0);
|
|
49796
|
+
}
|
|
49797
|
+
else {
|
|
49798
|
+
backfeed(result);
|
|
49799
|
+
}
|
|
49800
|
+
}
|
|
49801
|
+
};
|
|
49802
|
+
ws.onMessage(callback);
|
|
49803
|
+
this.send(data);
|
|
49804
|
+
// 30s超时处理
|
|
49805
|
+
timer = globalThis.setTimeout(() => {
|
|
49806
|
+
console.warn('callAndBackfeed timeout');
|
|
49807
|
+
backfeed(0);
|
|
49808
|
+
}, 30000);
|
|
49809
|
+
}
|
|
49810
|
+
/**
|
|
49811
|
+
* 处理 _callAndListen
|
|
49812
|
+
* @param actionUrl
|
|
49813
|
+
* @param fn
|
|
49814
|
+
*/
|
|
49815
|
+
_callAndListen(actionUrl, fn) {
|
|
49816
|
+
const reqId = uuid();
|
|
49817
|
+
const data = JSON.stringify({
|
|
49818
|
+
id: reqId,
|
|
49819
|
+
actionUrl,
|
|
49820
|
+
command: 'rsSchemeRequest',
|
|
49821
|
+
type: 'callAndListen',
|
|
49822
|
+
});
|
|
49823
|
+
const callback = (message) => {
|
|
49824
|
+
const { id, result, errmsg, command } = message;
|
|
49825
|
+
if (command === 'rsSchemeResponse' && id === reqId) {
|
|
49826
|
+
if (errmsg) {
|
|
49827
|
+
console.warn(errmsg);
|
|
49828
|
+
fn(false);
|
|
49829
|
+
}
|
|
49830
|
+
else {
|
|
49831
|
+
fn(result);
|
|
49832
|
+
}
|
|
49833
|
+
}
|
|
49834
|
+
};
|
|
49835
|
+
ws.onMessage(callback);
|
|
49836
|
+
this.send(data);
|
|
49837
|
+
}
|
|
49838
|
+
/**
|
|
49839
|
+
* 执行bridge上的方法
|
|
49840
|
+
* @param method 方法名
|
|
49841
|
+
* @param args 传递的参数
|
|
49842
|
+
* @returns
|
|
49843
|
+
*/
|
|
49844
|
+
async invoke(method, args) {
|
|
49845
|
+
return new Promise((success, fail) => {
|
|
49846
|
+
const reqId = uuid();
|
|
49847
|
+
const data = JSON.stringify({
|
|
49848
|
+
id: reqId,
|
|
49849
|
+
method,
|
|
49850
|
+
args,
|
|
49851
|
+
command: 'request',
|
|
49852
|
+
});
|
|
49853
|
+
let timer = null;
|
|
49854
|
+
const callback = (message) => {
|
|
49855
|
+
const { id, result, error, command } = message;
|
|
49856
|
+
if (command === 'response' &&
|
|
49857
|
+
id === reqId &&
|
|
49858
|
+
message.method === method) {
|
|
49859
|
+
ws.offMessage(callback);
|
|
49860
|
+
if (timer)
|
|
49861
|
+
clearTimeout(timer);
|
|
49862
|
+
if (error) {
|
|
49863
|
+
fail(error);
|
|
49864
|
+
}
|
|
49865
|
+
else {
|
|
49866
|
+
success(result);
|
|
49867
|
+
}
|
|
49868
|
+
}
|
|
49869
|
+
};
|
|
49870
|
+
ws.onMessage(callback);
|
|
49871
|
+
this.send(data);
|
|
49872
|
+
// 30s超时处理
|
|
49873
|
+
timer = setTimeout(() => fail('method invoke timeout'), 30000);
|
|
49874
|
+
});
|
|
49875
|
+
}
|
|
49876
|
+
}
|
|
49877
|
+
|
|
49878
|
+
/**
|
|
49879
|
+
* Android WebView 控件。
|
|
49880
|
+
*/
|
|
49881
|
+
class WxMiniprogramController extends BaseController {
|
|
49882
|
+
constructor() {
|
|
49883
|
+
super();
|
|
49884
|
+
this.initializing = false;
|
|
49885
|
+
Promise.resolve().then(async () => {
|
|
49886
|
+
try {
|
|
49887
|
+
await this.checkBridgeReady();
|
|
49888
|
+
}
|
|
49889
|
+
catch (error) {
|
|
49890
|
+
console.warn(error);
|
|
49891
|
+
}
|
|
49892
|
+
});
|
|
49893
|
+
}
|
|
49894
|
+
checkBridgeReady(timeout = 6000) {
|
|
49895
|
+
if (this.ready)
|
|
49896
|
+
return true;
|
|
49897
|
+
return new Promise(async (resolve, reject) => {
|
|
49898
|
+
if (this.ready)
|
|
49899
|
+
return resolve(true);
|
|
49900
|
+
if (this.initializing) {
|
|
49901
|
+
// 正在初始化中的时候
|
|
49902
|
+
const check = () => {
|
|
49903
|
+
if (this.ready)
|
|
49904
|
+
return resolve(true);
|
|
49905
|
+
requestAnimationFrame(check);
|
|
49906
|
+
};
|
|
49907
|
+
check();
|
|
49908
|
+
}
|
|
49909
|
+
else {
|
|
49910
|
+
this.initializing = true;
|
|
49911
|
+
const hybridBridge = new HybridBridge();
|
|
49912
|
+
const [res, error] = await hybridBridge.initialize(timeout);
|
|
49913
|
+
if (!res || error) {
|
|
49914
|
+
throw error || new Error('HybridBridge 初始化失败~');
|
|
49915
|
+
}
|
|
49916
|
+
hybridBridge === null || hybridBridge === void 0 ? void 0 : hybridBridge.getStaticData(registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
|
|
49917
|
+
this.deviceInfo = (() => {
|
|
49918
|
+
try {
|
|
49919
|
+
return JSON.parse(data);
|
|
49920
|
+
}
|
|
49921
|
+
catch (e) {
|
|
49922
|
+
return data;
|
|
49923
|
+
}
|
|
49924
|
+
})();
|
|
49925
|
+
this.hybridBridge = hybridBridge;
|
|
49926
|
+
this.initializing = false;
|
|
49927
|
+
return resolve(true);
|
|
49928
|
+
}));
|
|
49929
|
+
}
|
|
49930
|
+
});
|
|
49931
|
+
}
|
|
49932
|
+
async checkReady(timeout = 6000) {
|
|
49933
|
+
const res = [null, null];
|
|
49934
|
+
if (this.ready) {
|
|
49935
|
+
res[0] = true;
|
|
49936
|
+
return res;
|
|
49937
|
+
}
|
|
49938
|
+
try {
|
|
49939
|
+
res[0] = await this.checkBridgeReady(timeout);
|
|
49940
|
+
}
|
|
49941
|
+
catch (error) {
|
|
49942
|
+
res[0] = false;
|
|
49943
|
+
res[1] = error;
|
|
49944
|
+
}
|
|
49945
|
+
return res;
|
|
49946
|
+
}
|
|
49947
|
+
get ready() {
|
|
49948
|
+
var _a;
|
|
49949
|
+
return !!((_a = this.hybridBridge) === null || _a === void 0 ? void 0 : _a.isReady);
|
|
49950
|
+
}
|
|
49951
|
+
get scheme() {
|
|
49952
|
+
var _a;
|
|
49953
|
+
return ((_a = this.deviceInfo) === null || _a === void 0 ? void 0 : _a.scheme) || '';
|
|
49954
|
+
}
|
|
49955
|
+
createSchemeLink(schemeUrl) {
|
|
49956
|
+
if (schemeUrl.startsWith(this.scheme)) {
|
|
49957
|
+
return schemeUrl;
|
|
49958
|
+
}
|
|
49959
|
+
return this.scheme + '://' + schemeUrl;
|
|
49960
|
+
}
|
|
49961
|
+
async callAndBackfeed(scheme) {
|
|
49962
|
+
const res = [false, null];
|
|
49963
|
+
const [ready, readyError] = await this.checkReady();
|
|
49964
|
+
if (!ready) {
|
|
49965
|
+
res[0] = false;
|
|
49966
|
+
res[1] = readyError;
|
|
49967
|
+
return res;
|
|
49968
|
+
}
|
|
49969
|
+
return await new Promise(async (resolve) => {
|
|
49970
|
+
const actionUrl = this.createSchemeLink(scheme);
|
|
49971
|
+
const msg = JSON.stringify({
|
|
49972
|
+
actionUrl,
|
|
49973
|
+
functionName: registerGlobalValue(this.createSchemeLink(scheme), (data) => {
|
|
49974
|
+
let d = data;
|
|
49975
|
+
try {
|
|
49976
|
+
d = JSON.parse(data);
|
|
49977
|
+
}
|
|
49978
|
+
catch (e) {
|
|
49979
|
+
/** no-care */
|
|
49980
|
+
}
|
|
49981
|
+
res[0] = (() => {
|
|
49982
|
+
if (d === 1)
|
|
49983
|
+
return true;
|
|
49984
|
+
if (d === 0)
|
|
49985
|
+
return false;
|
|
49986
|
+
return d;
|
|
49987
|
+
})();
|
|
49988
|
+
resolve(res);
|
|
49989
|
+
}),
|
|
49990
|
+
});
|
|
49991
|
+
this.hybridBridge.callAndBackfeed(msg);
|
|
49992
|
+
});
|
|
49993
|
+
}
|
|
49994
|
+
async callAndListen(scheme, callback) {
|
|
49995
|
+
const res = [false, null];
|
|
49996
|
+
const [ready, readyError] = await this.checkReady();
|
|
49997
|
+
if (!ready) {
|
|
49998
|
+
res[0] = false;
|
|
49999
|
+
res[1] = readyError;
|
|
50000
|
+
return res;
|
|
50001
|
+
}
|
|
50002
|
+
return await new Promise(async (resolve) => {
|
|
50003
|
+
const actionUrl = this.createSchemeLink(scheme);
|
|
50004
|
+
const _callback = (data) => {
|
|
50005
|
+
let d = data;
|
|
50006
|
+
try {
|
|
50007
|
+
d = JSON.parse(data);
|
|
50008
|
+
}
|
|
50009
|
+
catch (e) {
|
|
50010
|
+
/** no-care */
|
|
50011
|
+
}
|
|
50012
|
+
const callbackParam = (() => {
|
|
50013
|
+
if (d === 1)
|
|
50014
|
+
return true;
|
|
50015
|
+
if (d === 0)
|
|
50016
|
+
return false;
|
|
50017
|
+
return d;
|
|
50018
|
+
})();
|
|
50019
|
+
callback(callbackParam);
|
|
50020
|
+
res[0] = () => {
|
|
50021
|
+
// 清理掉当前的回调引用
|
|
50022
|
+
const callbacks = cache[actionUrl];
|
|
50023
|
+
if (!callbacks)
|
|
50024
|
+
return;
|
|
50025
|
+
const idx = callbacks.queue.findIndex((func) => func.callback === _callback);
|
|
50026
|
+
if (idx !== -1) {
|
|
50027
|
+
callbacks.queue.splice(idx, 1);
|
|
50028
|
+
}
|
|
50029
|
+
};
|
|
50030
|
+
resolve(res);
|
|
50031
|
+
};
|
|
50032
|
+
const msg = JSON.stringify({
|
|
50033
|
+
actionUrl,
|
|
50034
|
+
functionName: registerGlobalValue(actionUrl, _callback, false),
|
|
50035
|
+
});
|
|
50036
|
+
this.hybridBridge.callAndListen(msg);
|
|
50037
|
+
});
|
|
50038
|
+
}
|
|
50039
|
+
async invoke(method, data) {
|
|
50040
|
+
var _a, _b;
|
|
50041
|
+
const [ready, readyError] = await this.checkReady();
|
|
50042
|
+
if (!ready) {
|
|
50043
|
+
throw readyError;
|
|
50044
|
+
}
|
|
50045
|
+
else {
|
|
50046
|
+
return (await ((_b = (_a = this.hybridBridge).invoke) === null || _b === void 0 ? void 0 : _b.call(_a, method, data)));
|
|
50047
|
+
}
|
|
50048
|
+
}
|
|
50049
|
+
}
|
|
50050
|
+
|
|
50051
|
+
/**
|
|
50052
|
+
* WebView 类型枚举。
|
|
50053
|
+
*/
|
|
50054
|
+
var WebViewTypeEnum;
|
|
50055
|
+
(function (WebViewTypeEnum) {
|
|
50056
|
+
/**
|
|
50057
|
+
* WebKit Android
|
|
50058
|
+
*/
|
|
50059
|
+
WebViewTypeEnum["WebView"] = "WebKit";
|
|
50060
|
+
/**
|
|
50061
|
+
* WKWebview iOS
|
|
50062
|
+
*/
|
|
50063
|
+
WebViewTypeEnum["WKWebview"] = "WKWebview";
|
|
50064
|
+
/**
|
|
50065
|
+
* UIWebview iOS
|
|
50066
|
+
*
|
|
50067
|
+
* @deprecated 性能因素被抛弃
|
|
50068
|
+
*/
|
|
50069
|
+
WebViewTypeEnum["UIWebview"] = "UIWebview";
|
|
50070
|
+
/**
|
|
50071
|
+
* Browser
|
|
50072
|
+
*
|
|
50073
|
+
* @description 浏览器
|
|
50074
|
+
*
|
|
50075
|
+
*/
|
|
50076
|
+
WebViewTypeEnum["Browser"] = "Browser";
|
|
50077
|
+
/**
|
|
50078
|
+
* WeChatMPWebView
|
|
50079
|
+
*/
|
|
50080
|
+
WebViewTypeEnum["WeChatMPWebView"] = "WxMiniProgramWebView";
|
|
50081
|
+
/**
|
|
50082
|
+
* Unsupported
|
|
50083
|
+
* @description 未支持的容器
|
|
50084
|
+
*/
|
|
50085
|
+
WebViewTypeEnum["Unsupported"] = "Unsupported";
|
|
50086
|
+
})(WebViewTypeEnum || (WebViewTypeEnum = {}));
|
|
50087
|
+
|
|
50088
|
+
/**
|
|
50089
|
+
* jsBridge 基础类
|
|
50090
|
+
*/
|
|
50091
|
+
class JSBridgeCore extends Subscribe {
|
|
50092
|
+
constructor() {
|
|
50093
|
+
super(...arguments);
|
|
50094
|
+
this.webViewType = WebViewTypeEnum.Unsupported;
|
|
50095
|
+
}
|
|
50096
|
+
}
|
|
50097
|
+
|
|
50098
|
+
const userAgent$1 = globalThis.navigator.userAgent;
|
|
50099
|
+
const isAndroid$1 = /android/gi.test(userAgent$1);
|
|
50100
|
+
const isIOS$1 = /iPhone|iPad\s+OS/gi.test(userAgent$1);
|
|
50101
|
+
const isWxMiniProgram$1 = /MicroMessenger/gi.test(userAgent$1) && /miniProgram/gi.test(userAgent$1);
|
|
50102
|
+
const isRealseeVRWebview$1 = /realsee/gi.test(userAgent$1);
|
|
50103
|
+
|
|
50104
|
+
const defaultOptions$1 = {
|
|
50105
|
+
timeout: 6000,
|
|
50106
|
+
};
|
|
50107
|
+
/**
|
|
50108
|
+
* App 客户端(iOS [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview) 或 Android [WebView](https://developer.android.google.cn/guide/webapps/webview))JSBridge。
|
|
50109
|
+
*/
|
|
50110
|
+
class JSBridgeApp extends JSBridgeCore {
|
|
50111
|
+
constructor(options = {}) {
|
|
50112
|
+
super();
|
|
50113
|
+
this.options = Object.assign(defaultOptions$1, options);
|
|
50114
|
+
if (!isRealseeVRWebview$1) {
|
|
50115
|
+
console.warn('未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... ');
|
|
50116
|
+
}
|
|
50117
|
+
this.webViewType = (() => {
|
|
50118
|
+
if (isAndroid$1)
|
|
50119
|
+
return WebViewTypeEnum.WebView;
|
|
50120
|
+
if (isIOS$1)
|
|
50121
|
+
return WebViewTypeEnum.WKWebview;
|
|
50122
|
+
return WebViewTypeEnum.Browser;
|
|
50123
|
+
})();
|
|
50124
|
+
this._controller = (() => {
|
|
50125
|
+
if (isAndroid$1)
|
|
50126
|
+
return new WebViewController();
|
|
50127
|
+
if (isIOS$1)
|
|
50128
|
+
return new WKWebViewController();
|
|
50129
|
+
return new BaseController();
|
|
50130
|
+
})();
|
|
50131
|
+
this.callAndListen('common/webViewState', (webviewState) => {
|
|
50132
|
+
this.emit('webViewStateChange', webviewState);
|
|
50133
|
+
});
|
|
50134
|
+
this.callAndListen('common/webViewError', (errorInfo) => {
|
|
50135
|
+
this.emit('error', errorInfo);
|
|
50136
|
+
});
|
|
50137
|
+
}
|
|
50138
|
+
async ready() {
|
|
50139
|
+
return await this._controller.checkReady(this.options.timeout);
|
|
50140
|
+
}
|
|
50141
|
+
async callAndBackfeed(schemeUrl) {
|
|
50142
|
+
return await this._controller.callAndBackfeed(schemeUrl);
|
|
50143
|
+
}
|
|
50144
|
+
async callAndListen(schemeUrl, callback) {
|
|
50145
|
+
var _a;
|
|
50146
|
+
return await ((_a = this._controller) === null || _a === void 0 ? void 0 : _a.callAndListen(schemeUrl, callback));
|
|
50147
|
+
}
|
|
50148
|
+
async setLeftTopBackButton(enable) {
|
|
50149
|
+
if (this.webViewType === WebViewTypeEnum.WebView) {
|
|
50150
|
+
return [true, null];
|
|
50151
|
+
}
|
|
50152
|
+
return await this.callAndBackfeed(`common/setLeftTopBackButton?enable=${enable ? 1 : 0}`);
|
|
50153
|
+
}
|
|
50154
|
+
async getBangsHeight() {
|
|
50155
|
+
return await this.callAndBackfeed('common/getBangsHeight');
|
|
50156
|
+
}
|
|
50157
|
+
async shock(duration = 4) {
|
|
50158
|
+
return await this.callAndBackfeed(`common/shock?duration=${duration}`);
|
|
50159
|
+
}
|
|
50160
|
+
async minimize() {
|
|
50161
|
+
return await this.callAndBackfeed(`common/minimize`);
|
|
50162
|
+
}
|
|
50163
|
+
async loadProgress(progress) {
|
|
50164
|
+
progress = progress < 0 ? 0 : progress > 100 ? 100 : progress;
|
|
50165
|
+
return await this.callAndBackfeed(`common/loadProgress?progress=${progress}`);
|
|
50166
|
+
}
|
|
50167
|
+
async closeLoading() {
|
|
50168
|
+
return await this.callAndBackfeed(`common/closeLoading`);
|
|
50169
|
+
}
|
|
50170
|
+
async setOrientation(orientation) {
|
|
50171
|
+
return await this.callAndBackfeed(`common/setOrientation?orientation=${orientation}`);
|
|
50172
|
+
}
|
|
50173
|
+
async keepScreenLight(enable) {
|
|
50174
|
+
return await this.callAndBackfeed(`common/keepScreenLight?enable=${enable ? 1 : 0}`);
|
|
50175
|
+
}
|
|
50176
|
+
async closeWebView() {
|
|
50177
|
+
return await this.callAndBackfeed(`common/closeWebView`);
|
|
50178
|
+
}
|
|
50179
|
+
async openWebView(url, way) {
|
|
50180
|
+
return await this.callAndBackfeed(`common/openWebView?way=${way}&url=${encodeURIComponent(url)}`);
|
|
50181
|
+
}
|
|
50182
|
+
async saveImage2Album(base64) {
|
|
50183
|
+
return await this.callAndBackfeed(`common/saveImage2Album?base64=${base64}`);
|
|
50184
|
+
}
|
|
50185
|
+
async actionShare(shareConfig) {
|
|
50186
|
+
return await this.callAndBackfeed(`common/actionShare?json=${JSON.stringify(shareConfig)}`);
|
|
50187
|
+
}
|
|
50188
|
+
async getDeviceInfo() {
|
|
50189
|
+
return await this.callAndBackfeed(`common/getDeviceInfo`);
|
|
50190
|
+
}
|
|
50191
|
+
async getUserInfo() {
|
|
50192
|
+
return await this.callAndBackfeed(`common/getUserInfo`);
|
|
50193
|
+
}
|
|
50194
|
+
async getWebViewState() {
|
|
50195
|
+
return await this.callAndBackfeed(`common/getWebViewState`);
|
|
50196
|
+
}
|
|
50197
|
+
async login() {
|
|
50198
|
+
const res = await this.callAndBackfeed(`common/login`);
|
|
50199
|
+
if (res[0]) {
|
|
50200
|
+
return await this.getUserInfo();
|
|
50201
|
+
}
|
|
50202
|
+
return res;
|
|
50203
|
+
}
|
|
50204
|
+
async logout() {
|
|
50205
|
+
return await this.callAndBackfeed(`common/logout`);
|
|
50206
|
+
}
|
|
50207
|
+
async detectMicro() {
|
|
50208
|
+
return await this.callAndBackfeed(`common/detectMicro`);
|
|
50209
|
+
}
|
|
50210
|
+
async preload(urls) {
|
|
50211
|
+
urls = urls.map((url) => {
|
|
50212
|
+
if (url.startsWith('//')) {
|
|
50213
|
+
return 'https:' + url;
|
|
50214
|
+
}
|
|
50215
|
+
return url;
|
|
50216
|
+
});
|
|
50217
|
+
return await this.callAndBackfeed(`common/preload?urls=${JSON.stringify(urls)}`);
|
|
50218
|
+
}
|
|
50219
|
+
createCacheProxyUrl(urls) {
|
|
50220
|
+
urls = Array.isArray(urls) ? urls : [urls];
|
|
50221
|
+
const userAgent = window.navigator.userAgent;
|
|
50222
|
+
// 不支持缓存代理
|
|
50223
|
+
if (!/supportCache/i.test(userAgent)) {
|
|
50224
|
+
return urls;
|
|
50225
|
+
}
|
|
50226
|
+
const proxyCache = (url) => {
|
|
50227
|
+
if (this.webViewType === WebViewTypeEnum.WKWebview) {
|
|
50228
|
+
return url.replace(/https*:/, '').replace(/\/\//, 'realseeproxycache://');
|
|
50229
|
+
}
|
|
50230
|
+
else if (this.webViewType === WebViewTypeEnum.WebView) {
|
|
50231
|
+
return url + (url.indexOf('?') !== -1 ? '&' : '?') + 'realseeproxycache=1';
|
|
50232
|
+
}
|
|
50233
|
+
return url;
|
|
50234
|
+
};
|
|
50235
|
+
return urls.map(proxyCache);
|
|
50236
|
+
}
|
|
50237
|
+
}
|
|
50238
|
+
|
|
50239
|
+
var OpenWebViewEnum;
|
|
50240
|
+
(function (OpenWebViewEnum) {
|
|
50241
|
+
/**
|
|
50242
|
+
* 在开启的 `VRWebView` 栈中追加一个 `WebView`。
|
|
50243
|
+
*/
|
|
50244
|
+
OpenWebViewEnum["Append"] = "Append";
|
|
50245
|
+
/**
|
|
50246
|
+
* 强制 先关闭当前的 `VRWebiView` 然后开启新的 `VRWebView`。
|
|
50247
|
+
*/
|
|
50248
|
+
OpenWebViewEnum["Replace"] = "Replace";
|
|
50249
|
+
/**
|
|
50250
|
+
* 删除所有的 `VRWebView`,仅保留本次新开启的 `VRWebView`。
|
|
50251
|
+
*/
|
|
50252
|
+
OpenWebViewEnum["Single"] = "Single";
|
|
50253
|
+
})(OpenWebViewEnum || (OpenWebViewEnum = {}));
|
|
50254
|
+
|
|
50255
|
+
/**
|
|
50256
|
+
* 浏览器端的jsbridge
|
|
50257
|
+
*/
|
|
50258
|
+
class JSBridgeBrowser extends JSBridgeCore {
|
|
50259
|
+
constructor() {
|
|
50260
|
+
super(...arguments);
|
|
50261
|
+
this.webViewType = WebViewTypeEnum.Browser;
|
|
50262
|
+
}
|
|
50263
|
+
ready() {
|
|
50264
|
+
return Promise.resolve([true, null]);
|
|
50265
|
+
}
|
|
50266
|
+
callAndBackfeed(schemeUrl) {
|
|
50267
|
+
return Promise.resolve([false, null]);
|
|
50268
|
+
}
|
|
50269
|
+
callAndListen(schemeUrl, callback) {
|
|
50270
|
+
return Promise.resolve([() => void 0, null]);
|
|
50271
|
+
}
|
|
50272
|
+
loadProgress(progress) {
|
|
50273
|
+
return Promise.resolve([true, null]);
|
|
50274
|
+
}
|
|
50275
|
+
closeLoading() {
|
|
50276
|
+
return Promise.resolve([true, null]);
|
|
50277
|
+
}
|
|
50278
|
+
getDeviceInfo() {
|
|
50279
|
+
return Promise.resolve([false, null]);
|
|
50280
|
+
}
|
|
50281
|
+
getWebViewState() {
|
|
50282
|
+
return Promise.resolve([false, null]);
|
|
50283
|
+
}
|
|
50284
|
+
setLeftTopBackButton(enable) {
|
|
50285
|
+
return Promise.resolve([false, null]);
|
|
50286
|
+
}
|
|
50287
|
+
login() {
|
|
50288
|
+
return Promise.resolve([false, null]);
|
|
50289
|
+
}
|
|
50290
|
+
logout() {
|
|
50291
|
+
return Promise.resolve([false, null]);
|
|
50292
|
+
}
|
|
50293
|
+
getUserInfo() {
|
|
50294
|
+
return Promise.resolve([false, null]);
|
|
50295
|
+
}
|
|
50296
|
+
openWebView(url, way) {
|
|
50297
|
+
switch (way) {
|
|
50298
|
+
case OpenWebViewEnum.Replace:
|
|
50299
|
+
case OpenWebViewEnum.Single: {
|
|
50300
|
+
setTimeout(() => globalThis.location.replace(url), 200);
|
|
50301
|
+
break;
|
|
50302
|
+
}
|
|
50303
|
+
case OpenWebViewEnum.Append:
|
|
50304
|
+
default: {
|
|
50305
|
+
setTimeout(() => (globalThis.location.href = url), 200);
|
|
50306
|
+
break;
|
|
50307
|
+
}
|
|
50308
|
+
}
|
|
50309
|
+
return Promise.resolve([true, null]);
|
|
50310
|
+
}
|
|
50311
|
+
closeWebView() {
|
|
50312
|
+
globalThis.close();
|
|
50313
|
+
return Promise.resolve([true, null]);
|
|
50314
|
+
}
|
|
50315
|
+
getBangsHeight() {
|
|
50316
|
+
return Promise.resolve([0, null]);
|
|
50317
|
+
}
|
|
50318
|
+
setOrientation(orientation) {
|
|
50319
|
+
return Promise.resolve([false, null]);
|
|
50320
|
+
}
|
|
50321
|
+
keepScreenLight(enable) {
|
|
50322
|
+
return Promise.resolve([false, null]);
|
|
50323
|
+
}
|
|
50324
|
+
shock(duration) {
|
|
50325
|
+
return Promise.resolve([false, null]);
|
|
50326
|
+
}
|
|
50327
|
+
minimize() {
|
|
50328
|
+
return Promise.resolve([false, null]);
|
|
50329
|
+
}
|
|
50330
|
+
saveImage2Album(base64) {
|
|
50331
|
+
return Promise.resolve([false, null]);
|
|
50332
|
+
}
|
|
50333
|
+
detectMicro() {
|
|
50334
|
+
return new Promise((resolve) => {
|
|
50335
|
+
const rule = { audio: true, video: false };
|
|
50336
|
+
try {
|
|
50337
|
+
globalThis.navigator.mediaDevices
|
|
50338
|
+
.getUserMedia(rule)
|
|
50339
|
+
.then(() => resolve([true, null]))
|
|
50340
|
+
.catch((e) => resolve([false, e]));
|
|
50341
|
+
}
|
|
50342
|
+
catch (e) {
|
|
50343
|
+
console.error(e);
|
|
50344
|
+
resolve([false, e]);
|
|
50345
|
+
}
|
|
50346
|
+
});
|
|
50347
|
+
}
|
|
50348
|
+
actionShare(shareConfig) {
|
|
50349
|
+
return Promise.resolve([false, null]);
|
|
50350
|
+
}
|
|
50351
|
+
preload(urls) {
|
|
50352
|
+
return Promise.resolve([false, null]);
|
|
50353
|
+
}
|
|
50354
|
+
createCacheProxyUrl(urls) {
|
|
50355
|
+
return [];
|
|
50356
|
+
}
|
|
50357
|
+
}
|
|
50358
|
+
|
|
50359
|
+
const defaultOptions = {
|
|
50360
|
+
timeout: 6000,
|
|
50361
|
+
};
|
|
50362
|
+
/**
|
|
50363
|
+
* 小程序 [web-view](https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html) JSBridge。
|
|
50364
|
+
*/
|
|
50365
|
+
class JSBridgeMiniprogram extends JSBridgeCore {
|
|
50366
|
+
constructor(options = {}) {
|
|
50367
|
+
super();
|
|
50368
|
+
this._controller = new WxMiniprogramController();
|
|
50369
|
+
this.options = Object.assign(defaultOptions, options);
|
|
50370
|
+
if (!isWxMiniProgram$1) {
|
|
50371
|
+
console.warn('未知容器:此版本 `jsBridge` 不支持当前 WebView 容器 ... ');
|
|
50372
|
+
}
|
|
50373
|
+
this.webViewType = WebViewTypeEnum.WeChatMPWebView;
|
|
50374
|
+
this.callAndListen('common/webViewState', (webviewState) => {
|
|
50375
|
+
this.emit('webViewStateChange', webviewState);
|
|
50376
|
+
});
|
|
50377
|
+
this.callAndListen('common/webViewError', (errorInfo) => {
|
|
50378
|
+
this.emit('error', errorInfo);
|
|
50379
|
+
});
|
|
50380
|
+
}
|
|
50381
|
+
async ready() {
|
|
50382
|
+
return await this._controller.checkReady(this.options.timeout);
|
|
50383
|
+
}
|
|
50384
|
+
async callAndBackfeed(schemeUrl) {
|
|
50385
|
+
return await this._controller.callAndBackfeed(schemeUrl);
|
|
50386
|
+
}
|
|
50387
|
+
async callAndListen(schemeUrl, callback) {
|
|
50388
|
+
return await this._controller.callAndListen(schemeUrl, callback);
|
|
50389
|
+
}
|
|
50390
|
+
async setLeftTopBackButton(enable) {
|
|
50391
|
+
if (this.webViewType === WebViewTypeEnum.WebView) {
|
|
50392
|
+
return [true, null];
|
|
50393
|
+
}
|
|
50394
|
+
return await this.callAndBackfeed(`common/setLeftTopBackButton?enable=${enable ? 1 : 0}`);
|
|
50395
|
+
}
|
|
50396
|
+
async getBangsHeight() {
|
|
50397
|
+
return await this.callAndBackfeed('common/getBangsHeight');
|
|
50398
|
+
}
|
|
50399
|
+
async shock(duration = 4) {
|
|
50400
|
+
return await this.callAndBackfeed(`common/shock?duration=${duration}`);
|
|
50401
|
+
}
|
|
50402
|
+
async minimize() {
|
|
50403
|
+
return await this.callAndBackfeed(`common/minimize`);
|
|
50404
|
+
}
|
|
50405
|
+
async loadProgress(progress) {
|
|
50406
|
+
progress = progress < 0 ? 0 : progress > 100 ? 100 : progress;
|
|
50407
|
+
return await this.callAndBackfeed(`common/loadProgress?progress=${progress}`);
|
|
50408
|
+
}
|
|
50409
|
+
async closeLoading() {
|
|
50410
|
+
return await this.callAndBackfeed(`common/closeLoading`);
|
|
50411
|
+
}
|
|
50412
|
+
async setOrientation(orientation) {
|
|
50413
|
+
return await this.callAndBackfeed(`common/setOrientation?orientation=${orientation}`);
|
|
50414
|
+
}
|
|
50415
|
+
async keepScreenLight(enable) {
|
|
50416
|
+
return await this.callAndBackfeed(`common/keepScreenLight?enable=${enable ? 1 : 0}`);
|
|
50417
|
+
}
|
|
50418
|
+
async closeWebView() {
|
|
50419
|
+
return await this.callAndBackfeed(`common/closeWebView`);
|
|
50420
|
+
}
|
|
50421
|
+
async openWebView(url, way) {
|
|
50422
|
+
return await this.callAndBackfeed(`common/openWebView?way=${way}&url=${encodeURIComponent(url)}`);
|
|
50423
|
+
}
|
|
50424
|
+
async saveImage2Album(base64) {
|
|
50425
|
+
return await this.callAndBackfeed(`common/saveImage2Album?base64=${base64}`);
|
|
50426
|
+
}
|
|
50427
|
+
async actionShare(shareConfig) {
|
|
50428
|
+
var _a, _b, _c;
|
|
50429
|
+
const config = {
|
|
50430
|
+
path: (_a = shareConfig.miniprogram) === null || _a === void 0 ? void 0 : _a[0].path,
|
|
50431
|
+
title: (_b = shareConfig.miniprogram) === null || _b === void 0 ? void 0 : _b[0].title,
|
|
50432
|
+
imageUrl: (_c = shareConfig.miniprogram) === null || _c === void 0 ? void 0 : _c[0].hdImageData,
|
|
50433
|
+
};
|
|
50434
|
+
return await this.callAndBackfeed(`common/actionShare?json=${JSON.stringify(config)}`);
|
|
50435
|
+
}
|
|
50436
|
+
async getDeviceInfo() {
|
|
50437
|
+
return await this.callAndBackfeed(`common/getDeviceInfo`);
|
|
50438
|
+
}
|
|
50439
|
+
async getUserInfo() {
|
|
50440
|
+
return await this.callAndBackfeed(`common/getUserInfo`);
|
|
50441
|
+
}
|
|
50442
|
+
async getWebViewState() {
|
|
50443
|
+
return await this.callAndBackfeed(`common/getWebViewState`);
|
|
50444
|
+
}
|
|
50445
|
+
async login() {
|
|
50446
|
+
const res = await this.callAndBackfeed(`common/login`);
|
|
50447
|
+
if (res[0]) {
|
|
50448
|
+
return await this.getUserInfo();
|
|
50449
|
+
}
|
|
50450
|
+
return res;
|
|
50451
|
+
}
|
|
50452
|
+
async logout() {
|
|
50453
|
+
return await this.callAndBackfeed(`common/logout`);
|
|
50454
|
+
}
|
|
50455
|
+
async detectMicro() {
|
|
50456
|
+
return await this.callAndBackfeed(`common/detectMicro`);
|
|
50457
|
+
}
|
|
50458
|
+
async preload(urls) {
|
|
50459
|
+
urls = urls.map((url) => {
|
|
50460
|
+
if (url.startsWith('//')) {
|
|
50461
|
+
return 'https:' + url;
|
|
50462
|
+
}
|
|
50463
|
+
return url;
|
|
50464
|
+
});
|
|
50465
|
+
return await this.callAndBackfeed(`common/preload?urls=${JSON.stringify(urls)}`);
|
|
50466
|
+
}
|
|
50467
|
+
createCacheProxyUrl(urls) {
|
|
50468
|
+
urls = Array.isArray(urls) ? urls : [urls];
|
|
50469
|
+
const userAgent = window.navigator.userAgent;
|
|
50470
|
+
// 不支持缓存代理
|
|
50471
|
+
if (!/supportCache/i.test(userAgent)) {
|
|
50472
|
+
return urls;
|
|
50473
|
+
}
|
|
50474
|
+
const proxyCache = (url) => {
|
|
50475
|
+
if (this.webViewType === WebViewTypeEnum.WKWebview) {
|
|
50476
|
+
return url.replace(/https*:/, '').replace(/\/\//, 'realseeproxycache://');
|
|
50477
|
+
}
|
|
50478
|
+
else if (this.webViewType === WebViewTypeEnum.WebView) {
|
|
50479
|
+
return url + (url.indexOf('?') !== -1 ? '&' : '?') + 'realseeproxycache=1';
|
|
50480
|
+
}
|
|
50481
|
+
return url;
|
|
50482
|
+
};
|
|
50483
|
+
return urls.map(proxyCache);
|
|
50484
|
+
}
|
|
50485
|
+
async invokeNativeApi(method, data) {
|
|
50486
|
+
return await this._controller.invoke(method, data);
|
|
50487
|
+
}
|
|
50488
|
+
}
|
|
50489
|
+
|
|
50490
|
+
/**
|
|
50491
|
+
* 平台相关的jsBridge类,根据平台自动加载不同的jsBridge实例
|
|
50492
|
+
*/
|
|
50493
|
+
// @ts-ignore
|
|
50494
|
+
class JSBridge extends JSBridgeCore {
|
|
50495
|
+
constructor(options = {}) {
|
|
50496
|
+
super();
|
|
50497
|
+
if (isRealseeVRWebview$1 && (isAndroid$1 || isIOS$1))
|
|
50498
|
+
return new JSBridgeApp(options);
|
|
50499
|
+
if (isWxMiniProgram$1)
|
|
50500
|
+
return new JSBridgeMiniprogram(options);
|
|
50501
|
+
return new JSBridgeBrowser();
|
|
50502
|
+
}
|
|
50503
|
+
}
|
|
50504
|
+
|
|
48777
50505
|
function appendUri(uri, query) {
|
|
48778
50506
|
const hasQuery = uri.indexOf('?') !== -1;
|
|
48779
50507
|
const newQuery = Object.keys(query).reduce((accu, curr, idx) => `${accu}${(idx === 0 && !hasQuery) ? '?' : '&'}${curr}=${query[curr]}`, '');
|
|
48780
50508
|
return uri + newQuery;
|
|
48781
50509
|
}
|
|
48782
50510
|
|
|
50511
|
+
const userAgent = globalThis.navigator.userAgent;
|
|
50512
|
+
const isAndroid = /android/gi.test(userAgent);
|
|
50513
|
+
const isIOS = /iPhone|iPad\s+OS/gi.test(userAgent);
|
|
50514
|
+
const isWxMiniProgram = /MicroMessenger/gi.test(userAgent) && /miniProgram/gi.test(userAgent);
|
|
50515
|
+
const isRealseeVRWebview = /realsee/gi.test(userAgent);
|
|
50516
|
+
|
|
48783
50517
|
/**
|
|
48784
50518
|
* 判断是否是真实的对象类型
|
|
48785
50519
|
* @param value
|
|
@@ -49140,13 +50874,13 @@
|
|
|
49140
50874
|
: [];
|
|
49141
50875
|
if (toUserIds)
|
|
49142
50876
|
data['to_user_ids'] = toUserIds;
|
|
49143
|
-
return { command, front_request_id: uuid(), data };
|
|
50877
|
+
return { command, front_request_id: uuid$1(), data };
|
|
49144
50878
|
};
|
|
49145
|
-
class LiveTpl extends Subscribe {
|
|
50879
|
+
class LiveTpl extends Subscribe$1 {
|
|
49146
50880
|
constructor() {
|
|
49147
|
-
var _a;
|
|
50881
|
+
var _a, _b, _c;
|
|
49148
50882
|
super();
|
|
49149
|
-
this.keyframes = new Subscribe();
|
|
50883
|
+
this.keyframes = new Subscribe$1();
|
|
49150
50884
|
// 没有传rtc实例时
|
|
49151
50885
|
if (!options.rtc) {
|
|
49152
50886
|
// 取指定的内部rtc类型
|
|
@@ -49187,6 +50921,34 @@
|
|
|
49187
50921
|
}
|
|
49188
50922
|
}
|
|
49189
50923
|
}
|
|
50924
|
+
// 都不满足时取内置
|
|
50925
|
+
if (options.useBuiltInRTC) {
|
|
50926
|
+
if (!options.getVoiceSign) {
|
|
50927
|
+
throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
50928
|
+
}
|
|
50929
|
+
const getVoiceSign = (_b = options.getVoiceSign) !== null && _b !== void 0 ? _b : unimplementedGetVoiceSign;
|
|
50930
|
+
const jsBridge = ((_c = options.jsBridge) !== null && _c !== void 0 ? _c : options.useBuiltInJsBridge)
|
|
50931
|
+
? new JSBridge()
|
|
50932
|
+
: null;
|
|
50933
|
+
if (!jsBridge) {
|
|
50934
|
+
throw new Error('jsBridge instance must be passed when using built-in RTC instances');
|
|
50935
|
+
}
|
|
50936
|
+
options.jsBridge = jsBridge;
|
|
50937
|
+
// vrwebview 默认
|
|
50938
|
+
if ((isRealseeVRWebview && (isAndroid || isIOS)) || isWxMiniProgram) {
|
|
50939
|
+
liveController.options.rtc = new VRWebViewRTC({
|
|
50940
|
+
jsBridge,
|
|
50941
|
+
getVoiceSign,
|
|
50942
|
+
});
|
|
50943
|
+
}
|
|
50944
|
+
else {
|
|
50945
|
+
// 其它终端使用
|
|
50946
|
+
liveController.options.rtc =
|
|
50947
|
+
options.builtInRTCType === exports.BuiltInRTCType.RealseeXChimeRTC
|
|
50948
|
+
? new BrowserRTC4Chime({ getVoiceSign })
|
|
50949
|
+
: new BrowserRTC({ getVoiceSign });
|
|
50950
|
+
}
|
|
50951
|
+
}
|
|
49190
50952
|
}
|
|
49191
50953
|
if (!liveController.options.rtc) {
|
|
49192
50954
|
console.warn('unused rtc');
|
|
@@ -49234,6 +50996,9 @@
|
|
|
49234
50996
|
get $RTC() {
|
|
49235
50997
|
return liveController.options.rtc;
|
|
49236
50998
|
}
|
|
50999
|
+
get jsBridge() {
|
|
51000
|
+
return liveController.options.jsBridge;
|
|
51001
|
+
}
|
|
49237
51002
|
async setSelfInfo(userInfo) {
|
|
49238
51003
|
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
49239
51004
|
return new Error('The connection is not open and ready to communicate.');
|