@realsee/live 0.5.0-alpha.6 → 0.5.0-alpha.9
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 +39 -17
- 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 +39 -17
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +433 -492
- 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/VRWebViewRTC.html +4 -4
- package/package.json +1 -1
|
@@ -48513,7 +48513,7 @@
|
|
|
48513
48513
|
this.voiceId = '';
|
|
48514
48514
|
this.options = { jsBridge, getVoiceSign };
|
|
48515
48515
|
// TO-DO: 在微信小程序下有个音量上报的BUG会导致消息体过大从而jsbridge异常断开
|
|
48516
|
-
if (this.jsBridge.webViewType !==
|
|
48516
|
+
if (this.jsBridge.webViewType !== 'WxMiniProgramWebView') {
|
|
48517
48517
|
this.jsBridge.callAndListen('live/userVolumes', (userVolumes) => {
|
|
48518
48518
|
this.emit('userVolumes', userVolumes);
|
|
48519
48519
|
});
|
|
@@ -48528,25 +48528,37 @@
|
|
|
48528
48528
|
}
|
|
48529
48529
|
join(options) {
|
|
48530
48530
|
return __awaiter$$(this, void 0, void 0, function* () {
|
|
48531
|
-
|
|
48532
|
-
|
|
48533
|
-
|
|
48534
|
-
|
|
48535
|
-
|
|
48536
|
-
|
|
48537
|
-
|
|
48538
|
-
}
|
|
48539
|
-
else {
|
|
48540
|
-
if (res.code === exports.RTCJoinedInfoCodeEnum.Success) {
|
|
48541
|
-
this.emit('joined');
|
|
48542
|
-
this.joined = true;
|
|
48531
|
+
try {
|
|
48532
|
+
this.emit('joinWillStart');
|
|
48533
|
+
const { sdkAppId, userId, userSig } = yield this.options.getVoiceSign(options);
|
|
48534
|
+
if (!(Boolean(sdkAppId) && Boolean(userId) && Boolean(userSig))) {
|
|
48535
|
+
this.emit('error', new Error('加入房间失败:rtc 签名请求异常'));
|
|
48536
|
+
this.joined = false;
|
|
48537
|
+
return this.joined;
|
|
48543
48538
|
}
|
|
48544
|
-
|
|
48545
|
-
|
|
48539
|
+
this.type = options.type;
|
|
48540
|
+
const [res, error] = yield this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${sdkAppId}&userID=${userId}&roomID=${Number(options.voiceId)}&userSig=${userSig}`);
|
|
48541
|
+
if (!res) {
|
|
48542
|
+
this.emit('error', error ? error : new Error('加入房间失败:未知异常。'));
|
|
48546
48543
|
this.joined = false;
|
|
48547
48544
|
}
|
|
48545
|
+
else {
|
|
48546
|
+
if (res.code === exports.RTCJoinedInfoCodeEnum.Success) {
|
|
48547
|
+
this.emit('joined');
|
|
48548
|
+
this.joined = true;
|
|
48549
|
+
}
|
|
48550
|
+
else {
|
|
48551
|
+
this.emit('error', res);
|
|
48552
|
+
this.joined = false;
|
|
48553
|
+
}
|
|
48554
|
+
}
|
|
48555
|
+
return this.joined;
|
|
48556
|
+
}
|
|
48557
|
+
catch (e) {
|
|
48558
|
+
this.emit('error', new Error('加入房间失败:' + e.message));
|
|
48559
|
+
this.joined = false;
|
|
48560
|
+
return this.joined;
|
|
48548
48561
|
}
|
|
48549
|
-
return this.joined;
|
|
48550
48562
|
});
|
|
48551
48563
|
}
|
|
48552
48564
|
quit() {
|
|
@@ -49233,38 +49245,48 @@
|
|
|
49233
49245
|
WeappBridgeMessage["alive"] = "I`m alive!";
|
|
49234
49246
|
})(WeappBridgeMessage || (WeappBridgeMessage = {}));
|
|
49235
49247
|
|
|
49236
|
-
const endpoint = 'wss://ws.realsee.com';
|
|
49237
|
-
var defaultWsEndpoint = endpoint;
|
|
49238
|
-
|
|
49239
49248
|
/**
|
|
49240
|
-
*
|
|
49241
|
-
*
|
|
49242
|
-
* @param params
|
|
49243
|
-
* @returns
|
|
49249
|
+
* ws的状态
|
|
49250
|
+
* 参考https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
|
49244
49251
|
*/
|
|
49245
|
-
|
|
49246
|
-
|
|
49247
|
-
|
|
49248
|
-
|
|
49249
|
-
|
|
49250
|
-
|
|
49251
|
-
|
|
49252
|
-
var isValidKey$1 = isValidKey;
|
|
49252
|
+
var WebSocketState;
|
|
49253
|
+
(function (WebSocketState) {
|
|
49254
|
+
WebSocketState[WebSocketState["CONNECTING"] = 0] = "CONNECTING";
|
|
49255
|
+
WebSocketState[WebSocketState["OPEN"] = 1] = "OPEN";
|
|
49256
|
+
WebSocketState[WebSocketState["CLOSING"] = 2] = "CLOSING";
|
|
49257
|
+
WebSocketState[WebSocketState["CLOSED"] = 3] = "CLOSED";
|
|
49258
|
+
})(WebSocketState || (WebSocketState = {}));
|
|
49253
49259
|
|
|
49254
49260
|
/**
|
|
49255
|
-
*
|
|
49256
|
-
* @param query
|
|
49257
|
-
* @returns
|
|
49261
|
+
* ws 关闭的原因
|
|
49258
49262
|
*/
|
|
49259
|
-
const
|
|
49260
|
-
|
|
49261
|
-
|
|
49262
|
-
|
|
49263
|
-
|
|
49264
|
-
|
|
49265
|
-
|
|
49266
|
-
|
|
49267
|
-
|
|
49263
|
+
const WebSocketCloseOptions = {
|
|
49264
|
+
/**
|
|
49265
|
+
* 重连关闭
|
|
49266
|
+
*/
|
|
49267
|
+
reconnect: { code: 1000, reason: 'close websocket when reconnecting' },
|
|
49268
|
+
/**
|
|
49269
|
+
* 主动关闭
|
|
49270
|
+
*/
|
|
49271
|
+
normalClosure: { code: 1000, reason: 'normal closure' },
|
|
49272
|
+
/**
|
|
49273
|
+
* 强制关闭
|
|
49274
|
+
*/
|
|
49275
|
+
forceClosure: { code: 1000, reason: 'force closure' },
|
|
49276
|
+
/**
|
|
49277
|
+
* 切换到后台,被微信杀掉,需要重连连接
|
|
49278
|
+
*/
|
|
49279
|
+
interrupted: { code: 1000, reason: 'interrupted' },
|
|
49280
|
+
/**
|
|
49281
|
+
* 服务端拒绝连接
|
|
49282
|
+
*/
|
|
49283
|
+
streamEndEncountered: { code: 1000, reason: 'stream end encountered' },
|
|
49284
|
+
/**
|
|
49285
|
+
* 丢失心跳
|
|
49286
|
+
* @deprecated
|
|
49287
|
+
*/
|
|
49288
|
+
lostHeartbeat: { code: 1000, reason: 'lost heartbeat' },
|
|
49289
|
+
};
|
|
49268
49290
|
|
|
49269
49291
|
const EVENT_SYMBOL = '$$REALSEE_JSBRIDGE_EVENT$$';
|
|
49270
49292
|
function __generateEventIfNotExisted(instance) {
|
|
@@ -49379,269 +49401,228 @@
|
|
|
49379
49401
|
}
|
|
49380
49402
|
|
|
49381
49403
|
/**
|
|
49382
|
-
*
|
|
49383
|
-
* 1、自动重连
|
|
49384
|
-
* 2、可根据网络情况进行重连
|
|
49404
|
+
* ws的事件
|
|
49385
49405
|
*/
|
|
49386
|
-
|
|
49387
|
-
|
|
49388
|
-
|
|
49389
|
-
|
|
49390
|
-
|
|
49391
|
-
|
|
49392
|
-
|
|
49393
|
-
|
|
49394
|
-
|
|
49395
|
-
|
|
49396
|
-
|
|
49397
|
-
|
|
49398
|
-
ignoreConnectivityEvents: false,
|
|
49399
|
-
automaticOpen: false,
|
|
49400
|
-
};
|
|
49401
|
-
this._attempts = 0;
|
|
49402
|
-
this._reconnects = -1;
|
|
49403
|
-
this._reconnectWhenOnlineAgain = false;
|
|
49404
|
-
this._explicitlyClosed = false;
|
|
49405
|
-
this._connectivityEventsAttached = false;
|
|
49406
|
-
/**
|
|
49407
|
-
* 清理连接中的请求
|
|
49408
|
-
*/
|
|
49409
|
-
this._clearPendingReconnectIfNeeded = () => {
|
|
49410
|
-
if (this._pendingReconnect) {
|
|
49411
|
-
clearTimeout(this._pendingReconnect);
|
|
49412
|
-
this._pendingReconnect = undefined;
|
|
49413
|
-
}
|
|
49414
|
-
};
|
|
49415
|
-
/**
|
|
49416
|
-
* 当网页连接上网络进行重连
|
|
49417
|
-
* @param event
|
|
49418
|
-
*/
|
|
49419
|
-
this._online = (event) => {
|
|
49420
|
-
if (this._reconnectWhenOnlineAgain) {
|
|
49421
|
-
this._clearPendingReconnectIfNeeded();
|
|
49422
|
-
this._reconnect(event);
|
|
49423
|
-
}
|
|
49424
|
-
};
|
|
49406
|
+
var WebSocketEvent;
|
|
49407
|
+
(function (WebSocketEvent) {
|
|
49408
|
+
WebSocketEvent["open"] = "open";
|
|
49409
|
+
WebSocketEvent["close"] = "close";
|
|
49410
|
+
WebSocketEvent["error"] = "error";
|
|
49411
|
+
WebSocketEvent["message"] = "message";
|
|
49412
|
+
})(WebSocketEvent || (WebSocketEvent = {}));
|
|
49413
|
+
|
|
49414
|
+
class Ws4Webview extends Subscribe {
|
|
49415
|
+
constructor() {
|
|
49416
|
+
super(...arguments);
|
|
49417
|
+
this._state = null;
|
|
49425
49418
|
/**
|
|
49426
|
-
*
|
|
49419
|
+
* @description 注册ws接通事件回调
|
|
49420
|
+
* @param listener 事件回调函数
|
|
49421
|
+
* @param once 是否只执行一次
|
|
49422
|
+
* @returns
|
|
49427
49423
|
*/
|
|
49428
|
-
this.
|
|
49429
|
-
var _a;
|
|
49430
|
-
this._reconnectWhenOnlineAgain = true;
|
|
49431
|
-
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000);
|
|
49432
|
-
};
|
|
49424
|
+
this.onOpen = (listener, once) => once ? this.once(WebSocketEvent.open, listener) : this.on(WebSocketEvent.open, listener);
|
|
49433
49425
|
/**
|
|
49434
|
-
*
|
|
49426
|
+
* @description 注册一次ws接通事件回调
|
|
49427
|
+
* @param listener 事件回调函数
|
|
49435
49428
|
*/
|
|
49436
|
-
this.
|
|
49437
|
-
if (this._connectivityEventsAttached) {
|
|
49438
|
-
globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('online', this._online);
|
|
49439
|
-
globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('offline', this._offline);
|
|
49440
|
-
this._connectivityEventsAttached = false;
|
|
49441
|
-
}
|
|
49442
|
-
};
|
|
49429
|
+
this.onceOpen = (listener) => this.onOpen(listener, true);
|
|
49443
49430
|
/**
|
|
49444
|
-
*
|
|
49445
|
-
|
|
49446
|
-
this._attachConnectivityEvents = () => {
|
|
49447
|
-
if (!this._connectivityEventsAttached) {
|
|
49448
|
-
globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('online', this._online);
|
|
49449
|
-
globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('offline', this._offline);
|
|
49450
|
-
this._connectivityEventsAttached = true;
|
|
49451
|
-
}
|
|
49452
|
-
};
|
|
49453
|
-
/**
|
|
49454
|
-
* 发送消息
|
|
49455
|
-
* @param data
|
|
49431
|
+
* @description 移除ws接通事件回调
|
|
49432
|
+
* @param listener 事件回调函数
|
|
49456
49433
|
* @returns
|
|
49457
49434
|
*/
|
|
49458
|
-
this.
|
|
49459
|
-
var _a, _b, _c;
|
|
49460
|
-
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
|
|
49461
|
-
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
|
|
49462
|
-
}
|
|
49463
|
-
};
|
|
49435
|
+
this.offOpen = (listener) => this.hasListener(WebSocketEvent.open) && this.off(WebSocketEvent.open, listener);
|
|
49464
49436
|
/**
|
|
49465
|
-
*
|
|
49466
|
-
* @param
|
|
49467
|
-
* @param
|
|
49437
|
+
* @description 注册ws消息事件回调
|
|
49438
|
+
* @param listener 事件回调函数
|
|
49439
|
+
* @param once 是否只执行一次
|
|
49468
49440
|
* @returns
|
|
49469
49441
|
*/
|
|
49470
|
-
this.
|
|
49471
|
-
var _a;
|
|
49472
|
-
if (typeof code !== 'number') {
|
|
49473
|
-
reason = code;
|
|
49474
|
-
code = 1000;
|
|
49475
|
-
}
|
|
49476
|
-
this._clearPendingReconnectIfNeeded();
|
|
49477
|
-
this._reconnectWhenOnlineAgain = false;
|
|
49478
|
-
this._explicitlyClosed = true;
|
|
49479
|
-
this._detachConnectivityEvents();
|
|
49480
|
-
return (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(code, reason);
|
|
49481
|
-
};
|
|
49442
|
+
this.onMessage = (listener, once) => once ? this.once(WebSocketEvent.message, listener) : this.on(WebSocketEvent.message, listener);
|
|
49482
49443
|
/**
|
|
49483
|
-
*
|
|
49444
|
+
* @description 注册一次ws消息事件回调
|
|
49445
|
+
* @param listener 事件回调函数
|
|
49484
49446
|
*/
|
|
49485
|
-
this.
|
|
49486
|
-
var _a, _b;
|
|
49487
|
-
if (url) {
|
|
49488
|
-
this._url = url;
|
|
49489
|
-
}
|
|
49490
|
-
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) !== WebSocket.OPEN &&
|
|
49491
|
-
((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.readyState) !== WebSocket.CONNECTING) {
|
|
49492
|
-
this._clearPendingReconnectIfNeeded();
|
|
49493
|
-
this._reconnectWhenOnlineAgain = false;
|
|
49494
|
-
this._explicitlyClosed = false;
|
|
49495
|
-
this._createWebSocket();
|
|
49496
|
-
}
|
|
49497
|
-
};
|
|
49447
|
+
this.onceMessage = (listener) => this.onMessage(listener, true);
|
|
49498
49448
|
/**
|
|
49499
|
-
*
|
|
49449
|
+
* @description 移除ws接通事件回调
|
|
49450
|
+
* @param listener 事件回调函数
|
|
49451
|
+
* @returns
|
|
49500
49452
|
*/
|
|
49501
|
-
this.
|
|
49502
|
-
var _a, _b, _c;
|
|
49503
|
-
const newUrl = typeof this._url === 'string' ? this._url : (_a = this._url) === null || _a === void 0 ? void 0 : _a.call(this, this);
|
|
49504
|
-
if (!newUrl)
|
|
49505
|
-
return;
|
|
49506
|
-
this._pendingReconnect = undefined;
|
|
49507
|
-
this._removeWebSocketEvent();
|
|
49508
|
-
this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
|
|
49509
|
-
this._attempts = this._attempts + 1;
|
|
49510
|
-
this.emit('connecting', new CustomEvent('connecting', {
|
|
49511
|
-
detail: { attempts: this._attempts, reconnects: this._reconnects },
|
|
49512
|
-
}));
|
|
49513
|
-
const timeoutCallback = () => {
|
|
49514
|
-
this._connectTimeout = undefined;
|
|
49515
|
-
this._detachConnectivityEvents();
|
|
49516
|
-
this.emit('timeout', new CustomEvent('connecting', {
|
|
49517
|
-
detail: {
|
|
49518
|
-
attempts: this._attempts,
|
|
49519
|
-
reconnects: this._reconnects,
|
|
49520
|
-
},
|
|
49521
|
-
}));
|
|
49522
|
-
};
|
|
49523
|
-
this._connectTimeout = setTimeout(timeoutCallback, (_b = this._options) === null || _b === void 0 ? void 0 : _b.timeout);
|
|
49524
|
-
this._dispatchWebSocketEvent();
|
|
49525
|
-
if (!((_c = this._options) === null || _c === void 0 ? void 0 : _c.ignoreConnectivityEvents)) {
|
|
49526
|
-
this._attachConnectivityEvents();
|
|
49527
|
-
}
|
|
49528
|
-
};
|
|
49453
|
+
this.offMessage = (listener) => this.hasListener(WebSocketEvent.message) && this.off(WebSocketEvent.message, listener);
|
|
49529
49454
|
/**
|
|
49530
|
-
*
|
|
49455
|
+
* @description 注册ws错误事件回调
|
|
49456
|
+
* @param listener 事件回调函数
|
|
49457
|
+
* @param once 是否只执行一次
|
|
49458
|
+
* @returns
|
|
49531
49459
|
*/
|
|
49532
|
-
this.
|
|
49533
|
-
var _a, _b, _c, _d;
|
|
49534
|
-
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
|
|
49535
|
-
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
|
|
49536
|
-
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
|
|
49537
|
-
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
|
|
49538
|
-
};
|
|
49460
|
+
this.onError = (listener, once) => once ? this.once(WebSocketEvent.error, listener) : this.on(WebSocketEvent.error, listener);
|
|
49539
49461
|
/**
|
|
49540
|
-
*
|
|
49462
|
+
* @description 注册一次ws消息事件回调
|
|
49463
|
+
* @param listener 事件回调函数
|
|
49541
49464
|
*/
|
|
49542
|
-
this.
|
|
49543
|
-
var _a, _b, _c, _d;
|
|
49544
|
-
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.addEventListener('open', this._webSocketOpenHandler);
|
|
49545
|
-
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.addEventListener('close', this._webSocketCloseHandler);
|
|
49546
|
-
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.addEventListener('error', this._webSocketErrorHandler);
|
|
49547
|
-
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.addEventListener('message', this._webSocketMessageHandler);
|
|
49548
|
-
};
|
|
49465
|
+
this.onceError = (listener) => this.onError(listener, true);
|
|
49549
49466
|
/**
|
|
49550
|
-
* ws
|
|
49467
|
+
* @description 移除ws接通事件回调
|
|
49468
|
+
* @param listener 事件回调函数
|
|
49551
49469
|
* @returns
|
|
49552
49470
|
*/
|
|
49553
|
-
this.
|
|
49554
|
-
if (this._connectTimeout) {
|
|
49555
|
-
clearTimeout(this._connectTimeout);
|
|
49556
|
-
this._connectTimeout = undefined;
|
|
49557
|
-
}
|
|
49558
|
-
const reconnects = ++this._reconnects;
|
|
49559
|
-
const attempts = this._attempts;
|
|
49560
|
-
this._attempts = 0;
|
|
49561
|
-
this._reconnectWhenOnlineAgain = false;
|
|
49562
|
-
return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
|
|
49563
|
-
};
|
|
49471
|
+
this.offError = (listener) => this.hasListener(WebSocketEvent.error) && this.off(WebSocketEvent.error, listener);
|
|
49564
49472
|
/**
|
|
49565
|
-
* ws
|
|
49566
|
-
* @param
|
|
49473
|
+
* @description 注册ws错误事件回调
|
|
49474
|
+
* @param listener 事件回调函数
|
|
49475
|
+
* @param once 是否只执行一次
|
|
49567
49476
|
* @returns
|
|
49568
49477
|
*/
|
|
49569
|
-
this.
|
|
49570
|
-
this._reconnect(event);
|
|
49571
|
-
return this.emit('close', event);
|
|
49572
|
-
};
|
|
49478
|
+
this.onClose = (listener, once) => once ? this.once(WebSocketEvent.close, listener) : this.on(WebSocketEvent.close, listener);
|
|
49573
49479
|
/**
|
|
49574
|
-
* ws
|
|
49575
|
-
* @param
|
|
49576
|
-
* @returns
|
|
49480
|
+
* @description 注册一次ws消息事件回调
|
|
49481
|
+
* @param listener 事件回调函数
|
|
49577
49482
|
*/
|
|
49578
|
-
this.
|
|
49579
|
-
return this.emit('error', new CustomEvent('error', { detail: { error: event } }));
|
|
49580
|
-
};
|
|
49483
|
+
this.onceClose = (listener) => this.onClose(listener, true);
|
|
49581
49484
|
/**
|
|
49582
|
-
* ws
|
|
49583
|
-
* @param
|
|
49485
|
+
* @description 移除ws接通事件回调
|
|
49486
|
+
* @param listener 事件回调函数
|
|
49584
49487
|
* @returns
|
|
49585
49488
|
*/
|
|
49586
|
-
this.
|
|
49587
|
-
return this.emit('message', event);
|
|
49588
|
-
};
|
|
49589
|
-
if (options) {
|
|
49590
|
-
this.setOptions(options);
|
|
49591
|
-
}
|
|
49489
|
+
this.offClose = (listener) => this.hasListener(WebSocketEvent.close) && this.off(WebSocketEvent.close, listener);
|
|
49592
49490
|
}
|
|
49593
|
-
get
|
|
49594
|
-
return this.
|
|
49491
|
+
get readyState() {
|
|
49492
|
+
return this._state;
|
|
49595
49493
|
}
|
|
49596
|
-
|
|
49597
|
-
|
|
49598
|
-
|
|
49599
|
-
|
|
49600
|
-
|
|
49601
|
-
|
|
49602
|
-
|
|
49603
|
-
|
|
49604
|
-
|
|
49605
|
-
|
|
49606
|
-
|
|
49607
|
-
|
|
49608
|
-
|
|
49609
|
-
|
|
49610
|
-
this.
|
|
49611
|
-
|
|
49494
|
+
/**
|
|
49495
|
+
* 连接ws
|
|
49496
|
+
* @param options
|
|
49497
|
+
*/
|
|
49498
|
+
connect(options) {
|
|
49499
|
+
if (this._state === WebSocketState.CONNECTING || this._state === WebSocketState.OPEN)
|
|
49500
|
+
return Promise.reject("\u5DF2\u5B58\u5728\u4E00\u4E2A\u8FDE\u63A5\u4E2D\u6216\u6253\u5F00\u72B6\u6001\u7684websocket\u5B9E\u4F8B" /* ErrorMessage.WsAlreadyExists */);
|
|
49501
|
+
return new Promise((resolve, reject) => {
|
|
49502
|
+
const { url } = options;
|
|
49503
|
+
if (!url)
|
|
49504
|
+
throw new Error("\u975E\u6CD5\u7684websocket\u94FE\u63A5" /* ErrorMessage.WsUrlInvalid */);
|
|
49505
|
+
this._wsOptions = options;
|
|
49506
|
+
this._state = WebSocketState.CONNECTING;
|
|
49507
|
+
this._wsTask = new WebSocket(url);
|
|
49508
|
+
this.registerEventHandler();
|
|
49509
|
+
this.handleConnected();
|
|
49510
|
+
this.onceOpen(() => resolve(true));
|
|
49511
|
+
this.onceError((err) => reject(err));
|
|
49512
|
+
});
|
|
49612
49513
|
}
|
|
49613
49514
|
/**
|
|
49614
|
-
*
|
|
49615
|
-
* @param event
|
|
49515
|
+
* 重连websocket
|
|
49616
49516
|
* @returns
|
|
49617
49517
|
*/
|
|
49618
|
-
|
|
49619
|
-
|
|
49620
|
-
if (
|
|
49621
|
-
this.
|
|
49622
|
-
|
|
49623
|
-
|
|
49624
|
-
|
|
49625
|
-
|
|
49626
|
-
|
|
49627
|
-
|
|
49518
|
+
async reconnect() {
|
|
49519
|
+
this.close(WebSocketCloseOptions.reconnect);
|
|
49520
|
+
if (this._wsOptions)
|
|
49521
|
+
this.connect(this._wsOptions);
|
|
49522
|
+
}
|
|
49523
|
+
/**
|
|
49524
|
+
* @description 发送消息
|
|
49525
|
+
* @param data 消息体
|
|
49526
|
+
*/
|
|
49527
|
+
send(data) {
|
|
49528
|
+
try {
|
|
49529
|
+
if (this._wsTask && this.readyState === WebSocketState.OPEN) {
|
|
49530
|
+
this._wsTask.send(data);
|
|
49531
|
+
}
|
|
49532
|
+
else if (this._wsTask && this.readyState === WebSocketState.CONNECTING) {
|
|
49533
|
+
this.once(WebSocketEvent.open, () => { var _a; return (_a = this._wsTask) === null || _a === void 0 ? void 0 : _a.send(data); });
|
|
49534
|
+
}
|
|
49535
|
+
else {
|
|
49536
|
+
this.once(WebSocketEvent.open, () => this.send(data));
|
|
49537
|
+
this.reconnect();
|
|
49538
|
+
}
|
|
49628
49539
|
}
|
|
49629
|
-
|
|
49630
|
-
|
|
49631
|
-
this.
|
|
49540
|
+
catch (e) {
|
|
49541
|
+
this.once(WebSocketEvent.open, () => this.send(data));
|
|
49542
|
+
this.reconnect();
|
|
49632
49543
|
}
|
|
49633
49544
|
}
|
|
49634
|
-
|
|
49545
|
+
/**
|
|
49546
|
+
* @description 手动关闭ws
|
|
49547
|
+
* @param options 关闭ws的配置参数
|
|
49548
|
+
*/
|
|
49549
|
+
close(options) {
|
|
49550
|
+
var _a;
|
|
49551
|
+
this._state = WebSocketState.CLOSING;
|
|
49552
|
+
(_a = this._wsTask) === null || _a === void 0 ? void 0 : _a.close(options.code, options.reason);
|
|
49553
|
+
}
|
|
49554
|
+
/**
|
|
49555
|
+
* 处理连接后的事件绑定
|
|
49556
|
+
*/
|
|
49557
|
+
handleConnected() {
|
|
49558
|
+
this.onceOpen(() => (this._state = WebSocketState.OPEN));
|
|
49559
|
+
this.onClose(() => (this._state = WebSocketState.CLOSED));
|
|
49560
|
+
}
|
|
49561
|
+
/**
|
|
49562
|
+
* 注册websocket事件
|
|
49563
|
+
*/
|
|
49564
|
+
registerEventHandler() {
|
|
49565
|
+
var _a, _b, _c, _d;
|
|
49566
|
+
(_a = this._wsTask) === null || _a === void 0 ? void 0 : _a.addEventListener(WebSocketEvent.open, (ev) => this.emit(WebSocketEvent.open, ev));
|
|
49567
|
+
(_b = this._wsTask) === null || _b === void 0 ? void 0 : _b.addEventListener(WebSocketEvent.message, (result) => {
|
|
49568
|
+
let data = result.data;
|
|
49569
|
+
try {
|
|
49570
|
+
if (typeof result.data === 'string') {
|
|
49571
|
+
data = JSON.parse(result.data);
|
|
49572
|
+
}
|
|
49573
|
+
}
|
|
49574
|
+
catch (e) {
|
|
49575
|
+
/** 不可序列化的数据不用处理 */
|
|
49576
|
+
}
|
|
49577
|
+
this.emit(WebSocketEvent.message, data);
|
|
49578
|
+
});
|
|
49579
|
+
(_c = this._wsTask) === null || _c === void 0 ? void 0 : _c.addEventListener(WebSocketEvent.close, (ev) => this.emit(WebSocketEvent.close, ev));
|
|
49580
|
+
(_d = this._wsTask) === null || _d === void 0 ? void 0 : _d.addEventListener(WebSocketEvent.error, (ev) => this.emit(WebSocketEvent.error, ev));
|
|
49581
|
+
}
|
|
49582
|
+
}
|
|
49583
|
+
var Ws4Webview$1 = Ws4Webview;
|
|
49635
49584
|
|
|
49585
|
+
const endpoint = 'wss://ws.realsee.com';
|
|
49586
|
+
var defaultWsEndpoint = endpoint;
|
|
49587
|
+
|
|
49588
|
+
/**
|
|
49589
|
+
* 拼接ws链接
|
|
49590
|
+
* @param tpl
|
|
49591
|
+
* @param params
|
|
49592
|
+
* @returns
|
|
49593
|
+
*/
|
|
49594
|
+
const generateWssUrl = (tpl, params) => {
|
|
49595
|
+
const url = Object.keys(params).reduce((res, curr) => res.replace(`{{${curr}}}`, `${params[curr]}`), tpl);
|
|
49596
|
+
return encodeURI(url);
|
|
49597
|
+
};
|
|
49598
|
+
var generateWssUrl$1 = generateWssUrl;
|
|
49599
|
+
|
|
49600
|
+
const isValidKey = (key, object) => key in object;
|
|
49601
|
+
var isValidKey$1 = isValidKey;
|
|
49602
|
+
|
|
49603
|
+
/**
|
|
49604
|
+
* 解析参数
|
|
49605
|
+
* @param query
|
|
49606
|
+
* @returns
|
|
49607
|
+
*/
|
|
49608
|
+
const parseQuery = (query = '') => query
|
|
49609
|
+
.replace('?', '')
|
|
49610
|
+
.split('&')
|
|
49611
|
+
.map((qs) => {
|
|
49612
|
+
const [k, v] = qs.split('=');
|
|
49613
|
+
return { [k]: decodeURIComponent(v) };
|
|
49614
|
+
})
|
|
49615
|
+
.reduce((result, curr) => ({ ...result, ...curr }), {});
|
|
49616
|
+
var parseQuery$1 = parseQuery;
|
|
49617
|
+
|
|
49618
|
+
const ws = (() => new Ws4Webview$1())();
|
|
49636
49619
|
class HybridBridge {
|
|
49637
49620
|
constructor() {
|
|
49638
|
-
var _a, _b;
|
|
49639
49621
|
/**
|
|
49640
49622
|
* @deprecated 兼容旧逻辑
|
|
49641
49623
|
*/
|
|
49642
49624
|
this._rsWeappBridgeMethodAdapter = {};
|
|
49643
|
-
this.
|
|
49644
|
-
this._readyState = 'close';
|
|
49625
|
+
this._forceClose = false;
|
|
49645
49626
|
/**
|
|
49646
49627
|
* 进行jsbridge的初始化,即打通ws通道
|
|
49647
49628
|
* @param timeout 超时计时
|
|
@@ -49664,7 +49645,7 @@
|
|
|
49664
49645
|
sign: wssig,
|
|
49665
49646
|
});
|
|
49666
49647
|
try {
|
|
49667
|
-
const result = await
|
|
49648
|
+
const result = await ws.connect({ url });
|
|
49668
49649
|
if (result) {
|
|
49669
49650
|
this.initBuiltInHandlers();
|
|
49670
49651
|
res[0] = await this.waitReady(timeout);
|
|
@@ -49678,130 +49659,6 @@
|
|
|
49678
49659
|
}
|
|
49679
49660
|
return res;
|
|
49680
49661
|
};
|
|
49681
|
-
/**
|
|
49682
|
-
* 内建的处理函数
|
|
49683
|
-
*/
|
|
49684
|
-
this.initBuiltInHandlers = () => {
|
|
49685
|
-
this._registerLifecycleHandler();
|
|
49686
|
-
this._registerHeartbeatHandler();
|
|
49687
|
-
this._registerMessageHandler();
|
|
49688
|
-
this._registerBridgeRequestHandler();
|
|
49689
|
-
this._registerReadyHandler();
|
|
49690
|
-
};
|
|
49691
|
-
/**
|
|
49692
|
-
* 进行连接
|
|
49693
|
-
* @param url ws链接
|
|
49694
|
-
* @returns
|
|
49695
|
-
*/
|
|
49696
|
-
this._open = (url) => new Promise((resolve) => {
|
|
49697
|
-
const handleOpen = () => {
|
|
49698
|
-
this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true), true);
|
|
49699
|
-
this._ws.once('timeout', () => resolve(false));
|
|
49700
|
-
this.send(WeappBridgeMessage.isReady);
|
|
49701
|
-
};
|
|
49702
|
-
this._ws.once('open', handleOpen);
|
|
49703
|
-
this._ws.open(url);
|
|
49704
|
-
});
|
|
49705
|
-
/**
|
|
49706
|
-
* 注册生命周期回调
|
|
49707
|
-
*/
|
|
49708
|
-
this._registerLifecycleHandler = () => {
|
|
49709
|
-
this._ws.on('connecting', () => {
|
|
49710
|
-
console.log('RsWeappBridge connecting');
|
|
49711
|
-
this._readyState = 'connecting';
|
|
49712
|
-
});
|
|
49713
|
-
this._ws.on('open', () => {
|
|
49714
|
-
console.log('RsWeappBridge open');
|
|
49715
|
-
this._readyState = 'open';
|
|
49716
|
-
});
|
|
49717
|
-
this._ws.on('close', () => {
|
|
49718
|
-
this._readyState = 'close';
|
|
49719
|
-
});
|
|
49720
|
-
this._ws.on('error', () => {
|
|
49721
|
-
console.log('RsWeappBridge error');
|
|
49722
|
-
this._readyState = 'close';
|
|
49723
|
-
});
|
|
49724
|
-
this._ws.on('timeout', () => {
|
|
49725
|
-
console.log('RsWeappBridge timeout');
|
|
49726
|
-
this._readyState = 'close';
|
|
49727
|
-
});
|
|
49728
|
-
};
|
|
49729
|
-
/**
|
|
49730
|
-
* 注册心跳的回调
|
|
49731
|
-
* @deprecated 兼容老的容器SDK
|
|
49732
|
-
*/
|
|
49733
|
-
this._registerHeartbeatHandler = () => {
|
|
49734
|
-
// 收到ping时回复pong
|
|
49735
|
-
this._receivedMessage(WeappBridgeMessage.ping, () => setTimeout(() => this._ws.send(WeappBridgeMessage.pong), 500));
|
|
49736
|
-
// 收到pong时回复ping
|
|
49737
|
-
this._receivedMessage(WeappBridgeMessage.pong, () => setTimeout(() => this._ws.send(WeappBridgeMessage.ping), 1000));
|
|
49738
|
-
};
|
|
49739
|
-
/**
|
|
49740
|
-
* 当收到某消息时
|
|
49741
|
-
* @param targetMessage 目标消息
|
|
49742
|
-
* @param handler 回调
|
|
49743
|
-
* @param once 是否一次性处理
|
|
49744
|
-
*/
|
|
49745
|
-
this._receivedMessage = (targetMessage, handler, once) => {
|
|
49746
|
-
const msgHandler = (evnet) => {
|
|
49747
|
-
if (evnet.data === targetMessage) {
|
|
49748
|
-
handler();
|
|
49749
|
-
if (once) {
|
|
49750
|
-
this._ws.off('message', msgHandler);
|
|
49751
|
-
}
|
|
49752
|
-
}
|
|
49753
|
-
};
|
|
49754
|
-
this._ws.on('message', msgHandler);
|
|
49755
|
-
};
|
|
49756
|
-
/**
|
|
49757
|
-
* 注册准备就绪的回调
|
|
49758
|
-
*/
|
|
49759
|
-
this._registerReadyHandler = () => {
|
|
49760
|
-
// 收到就绪询问时回复已就绪
|
|
49761
|
-
this._receivedMessage(WeappBridgeMessage.isReady, () => this._ws.send(WeappBridgeMessage.ready));
|
|
49762
|
-
};
|
|
49763
|
-
/**
|
|
49764
|
-
* 发送消息
|
|
49765
|
-
*/
|
|
49766
|
-
this.send = (data) => {
|
|
49767
|
-
this._ws.send(data);
|
|
49768
|
-
};
|
|
49769
|
-
/**
|
|
49770
|
-
* 等待响应
|
|
49771
|
-
* @param timeout 超时计时
|
|
49772
|
-
* @returns
|
|
49773
|
-
*/
|
|
49774
|
-
this.waitReady = (timeout = 6000) => {
|
|
49775
|
-
return new Promise((resolve, reject) => {
|
|
49776
|
-
this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true));
|
|
49777
|
-
this.send(WeappBridgeMessage.isReady);
|
|
49778
|
-
setTimeout(() => reject('HybridBridge 初始化超时~'), timeout);
|
|
49779
|
-
});
|
|
49780
|
-
};
|
|
49781
|
-
this._parseMessage = (event) => {
|
|
49782
|
-
try {
|
|
49783
|
-
return JSON.parse(event.data);
|
|
49784
|
-
}
|
|
49785
|
-
catch (e) {
|
|
49786
|
-
return event.data;
|
|
49787
|
-
}
|
|
49788
|
-
};
|
|
49789
|
-
/**
|
|
49790
|
-
* 注册消息投递回调
|
|
49791
|
-
* @deprecated 兼容老方法
|
|
49792
|
-
*/
|
|
49793
|
-
this._registerMessageHandler = () => {
|
|
49794
|
-
this._ws.on('message', (event) => {
|
|
49795
|
-
const message = this._parseMessage(event);
|
|
49796
|
-
if (typeof message === 'object') {
|
|
49797
|
-
const { id, command, data } = message;
|
|
49798
|
-
if (command === 'message' &&
|
|
49799
|
-
typeof this._rsWeappBridgeMethodAdapter.bindMessage === 'function') {
|
|
49800
|
-
this._rsWeappBridgeMethodAdapter.bindMessage({ id, data });
|
|
49801
|
-
}
|
|
49802
|
-
}
|
|
49803
|
-
});
|
|
49804
|
-
};
|
|
49805
49662
|
this.getStaticData = (callbackFunctionName) => {
|
|
49806
49663
|
this.callAndBackfeed(JSON.stringify({
|
|
49807
49664
|
actionUrl: 'common/staticData',
|
|
@@ -49848,52 +49705,134 @@
|
|
|
49848
49705
|
callback(false);
|
|
49849
49706
|
}
|
|
49850
49707
|
};
|
|
49851
|
-
|
|
49852
|
-
|
|
49853
|
-
|
|
49854
|
-
|
|
49855
|
-
|
|
49856
|
-
|
|
49857
|
-
|
|
49858
|
-
|
|
49859
|
-
|
|
49860
|
-
|
|
49861
|
-
|
|
49862
|
-
|
|
49863
|
-
|
|
49864
|
-
|
|
49865
|
-
|
|
49866
|
-
|
|
49867
|
-
|
|
49868
|
-
|
|
49869
|
-
|
|
49870
|
-
|
|
49871
|
-
|
|
49872
|
-
|
|
49708
|
+
}
|
|
49709
|
+
get isReady() {
|
|
49710
|
+
return ws.readyState === WebSocketState.OPEN;
|
|
49711
|
+
}
|
|
49712
|
+
/**
|
|
49713
|
+
* 内建的处理函数
|
|
49714
|
+
*/
|
|
49715
|
+
initBuiltInHandlers() {
|
|
49716
|
+
this._registerLifecycleHandler();
|
|
49717
|
+
this._registerHeartbeatHandler();
|
|
49718
|
+
this._registerMessageHandler();
|
|
49719
|
+
this._registerBridgeRequestHandler();
|
|
49720
|
+
this._registerReadyHandler();
|
|
49721
|
+
}
|
|
49722
|
+
/**
|
|
49723
|
+
* 注册生命周期回调
|
|
49724
|
+
*/
|
|
49725
|
+
_registerLifecycleHandler() {
|
|
49726
|
+
ws.onOpen(() => console.log('RsWeappBridge open'));
|
|
49727
|
+
ws.onClose((res) => {
|
|
49728
|
+
console.log('RsWeappBridge close');
|
|
49729
|
+
if (res.code === 1000) {
|
|
49730
|
+
switch ((res.reason + '').toLowerCase()) {
|
|
49731
|
+
case WebSocketCloseOptions.lostHeartbeat.reason: {
|
|
49732
|
+
// 心跳丢失
|
|
49733
|
+
ws.reconnect();
|
|
49734
|
+
break;
|
|
49735
|
+
}
|
|
49736
|
+
// case WebSocketCloseOptions.normalClosure.reason: // 主动关闭
|
|
49737
|
+
case WebSocketCloseOptions.interrupted.reason: // 切换到后台,被微信杀掉,需要重连连接
|
|
49738
|
+
case WebSocketCloseOptions.streamEndEncountered.reason: // 服务端拒绝连接
|
|
49739
|
+
default: {
|
|
49740
|
+
if (!this._forceClose) {
|
|
49741
|
+
ws.reconnect();
|
|
49742
|
+
}
|
|
49743
|
+
break;
|
|
49873
49744
|
}
|
|
49874
49745
|
}
|
|
49875
|
-
}
|
|
49876
|
-
this.
|
|
49877
|
-
|
|
49746
|
+
}
|
|
49747
|
+
if (res.code !== 1000 && !this._forceClose) {
|
|
49748
|
+
ws.reconnect();
|
|
49749
|
+
}
|
|
49750
|
+
if (this._forceClose)
|
|
49751
|
+
this._forceClose = false;
|
|
49878
49752
|
});
|
|
49879
|
-
|
|
49880
|
-
return (_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) === null || _b === void 0 ? void 0 : _b.__Realsee_WxMini_HybridBridge__;
|
|
49881
|
-
}
|
|
49882
|
-
if (globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) {
|
|
49883
|
-
globalThis.window.__Realsee_WxMini_HybridBridge__ = this;
|
|
49884
|
-
this.initBuiltInHandlers();
|
|
49885
|
-
}
|
|
49753
|
+
ws.onError((err) => console.error(err));
|
|
49886
49754
|
}
|
|
49887
|
-
|
|
49888
|
-
|
|
49755
|
+
/**
|
|
49756
|
+
* 注册心跳的回调
|
|
49757
|
+
* @deprecated 兼容老的容器SDK
|
|
49758
|
+
*/
|
|
49759
|
+
_registerHeartbeatHandler() {
|
|
49760
|
+
// 收到ping时回复pong
|
|
49761
|
+
this._receivedMessage(WeappBridgeMessage.ping, () => ws.send(WeappBridgeMessage.pong));
|
|
49762
|
+
// 收到pong时回复ping
|
|
49763
|
+
this._receivedMessage(WeappBridgeMessage.pong, () => ws.send(WeappBridgeMessage.ping));
|
|
49764
|
+
}
|
|
49765
|
+
/**
|
|
49766
|
+
* 当收到某消息时
|
|
49767
|
+
* @param targetMessage 目标消息
|
|
49768
|
+
* @param handler 回调
|
|
49769
|
+
* @param once 是否一次性处理
|
|
49770
|
+
*/
|
|
49771
|
+
_receivedMessage(targetMessage, handler, once) {
|
|
49772
|
+
const msgHandler = (msg) => {
|
|
49773
|
+
if (msg === targetMessage) {
|
|
49774
|
+
handler();
|
|
49775
|
+
if (once) {
|
|
49776
|
+
ws.offMessage(msgHandler);
|
|
49777
|
+
}
|
|
49778
|
+
}
|
|
49779
|
+
};
|
|
49780
|
+
ws.onMessage(msgHandler);
|
|
49781
|
+
}
|
|
49782
|
+
/**
|
|
49783
|
+
* 强制关闭ws
|
|
49784
|
+
* @param options
|
|
49785
|
+
*/
|
|
49786
|
+
forceClose(options) {
|
|
49787
|
+
this._forceClose = true;
|
|
49788
|
+
ws.close(options);
|
|
49789
|
+
}
|
|
49790
|
+
/**
|
|
49791
|
+
* 注册准备就绪的回调
|
|
49792
|
+
*/
|
|
49793
|
+
_registerReadyHandler() {
|
|
49794
|
+
// 收到就绪询问时回复已就绪
|
|
49795
|
+
this._receivedMessage(WeappBridgeMessage.isReady, () => ws.send(WeappBridgeMessage.ready));
|
|
49796
|
+
}
|
|
49797
|
+
/**
|
|
49798
|
+
* 发送消息
|
|
49799
|
+
*/
|
|
49800
|
+
send(data) {
|
|
49801
|
+
ws.send(data);
|
|
49802
|
+
}
|
|
49803
|
+
/**
|
|
49804
|
+
* 等待响应
|
|
49805
|
+
* @param timeout 超时计时
|
|
49806
|
+
* @returns
|
|
49807
|
+
*/
|
|
49808
|
+
waitReady(timeout = 6000) {
|
|
49809
|
+
return new Promise((resolve, reject) => {
|
|
49810
|
+
this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true));
|
|
49811
|
+
this.send(WeappBridgeMessage.isReady);
|
|
49812
|
+
setTimeout(() => reject('HybridBridge 初始化超时~'), timeout);
|
|
49813
|
+
});
|
|
49814
|
+
}
|
|
49815
|
+
/**
|
|
49816
|
+
* 注册消息投递回调
|
|
49817
|
+
* @deprecated 兼容老方法
|
|
49818
|
+
*/
|
|
49819
|
+
_registerMessageHandler() {
|
|
49820
|
+
ws.onMessage((message) => {
|
|
49821
|
+
if (typeof message === 'object') {
|
|
49822
|
+
const { id, command, data } = message;
|
|
49823
|
+
if (command === 'message' &&
|
|
49824
|
+
typeof this._rsWeappBridgeMethodAdapter.bindMessage === 'function') {
|
|
49825
|
+
this._rsWeappBridgeMethodAdapter.bindMessage({ id, data });
|
|
49826
|
+
}
|
|
49827
|
+
}
|
|
49828
|
+
});
|
|
49889
49829
|
}
|
|
49890
49830
|
/**
|
|
49891
49831
|
* 注册bridge方法回调
|
|
49892
49832
|
* @deprecated 兼容老方法
|
|
49893
49833
|
*/
|
|
49894
49834
|
_registerBridgeRequestHandler() {
|
|
49895
|
-
|
|
49896
|
-
const request = this._parseMessage(event);
|
|
49835
|
+
ws.onMessage(async (request) => {
|
|
49897
49836
|
if (typeof request === 'object') {
|
|
49898
49837
|
const { id, method, args, command } = request;
|
|
49899
49838
|
if (command === 'request') {
|
|
@@ -49946,25 +49885,22 @@
|
|
|
49946
49885
|
type: 'callAndBackfeed',
|
|
49947
49886
|
});
|
|
49948
49887
|
let timer = null;
|
|
49949
|
-
const callback = (
|
|
49950
|
-
const
|
|
49951
|
-
if (
|
|
49952
|
-
|
|
49953
|
-
if (
|
|
49954
|
-
|
|
49955
|
-
|
|
49956
|
-
|
|
49957
|
-
|
|
49958
|
-
|
|
49959
|
-
|
|
49960
|
-
|
|
49961
|
-
else {
|
|
49962
|
-
backfeed(result);
|
|
49963
|
-
}
|
|
49888
|
+
const callback = (message) => {
|
|
49889
|
+
const { id, result, errmsg, command } = message;
|
|
49890
|
+
if (command === 'rsSchemeResponse' && id === reqId) {
|
|
49891
|
+
ws.offMessage(callback);
|
|
49892
|
+
if (timer)
|
|
49893
|
+
clearTimeout(timer);
|
|
49894
|
+
if (errmsg) {
|
|
49895
|
+
console.warn(errmsg);
|
|
49896
|
+
backfeed(0);
|
|
49897
|
+
}
|
|
49898
|
+
else {
|
|
49899
|
+
backfeed(result);
|
|
49964
49900
|
}
|
|
49965
49901
|
}
|
|
49966
49902
|
};
|
|
49967
|
-
|
|
49903
|
+
ws.onMessage(callback);
|
|
49968
49904
|
this.send(data);
|
|
49969
49905
|
// 30s超时处理
|
|
49970
49906
|
timer = globalThis.setTimeout(() => {
|
|
@@ -49985,22 +49921,19 @@
|
|
|
49985
49921
|
command: 'rsSchemeRequest',
|
|
49986
49922
|
type: 'callAndListen',
|
|
49987
49923
|
});
|
|
49988
|
-
const callback = (
|
|
49989
|
-
const
|
|
49990
|
-
if (
|
|
49991
|
-
|
|
49992
|
-
|
|
49993
|
-
|
|
49994
|
-
|
|
49995
|
-
|
|
49996
|
-
|
|
49997
|
-
else {
|
|
49998
|
-
fn(result);
|
|
49999
|
-
}
|
|
49924
|
+
const callback = (message) => {
|
|
49925
|
+
const { id, result, errmsg, command } = message;
|
|
49926
|
+
if (command === 'rsSchemeResponse' && id === reqId) {
|
|
49927
|
+
if (errmsg) {
|
|
49928
|
+
console.warn(errmsg);
|
|
49929
|
+
fn(false);
|
|
49930
|
+
}
|
|
49931
|
+
else {
|
|
49932
|
+
fn(result);
|
|
50000
49933
|
}
|
|
50001
49934
|
}
|
|
50002
49935
|
};
|
|
50003
|
-
|
|
49936
|
+
ws.onMessage(callback);
|
|
50004
49937
|
this.send(data);
|
|
50005
49938
|
}
|
|
50006
49939
|
/**
|
|
@@ -50019,26 +49952,23 @@
|
|
|
50019
49952
|
command: 'request',
|
|
50020
49953
|
});
|
|
50021
49954
|
let timer = null;
|
|
50022
|
-
const callback = (
|
|
50023
|
-
const
|
|
50024
|
-
if (
|
|
50025
|
-
|
|
50026
|
-
|
|
50027
|
-
|
|
50028
|
-
|
|
50029
|
-
|
|
50030
|
-
|
|
50031
|
-
|
|
50032
|
-
|
|
50033
|
-
|
|
50034
|
-
|
|
50035
|
-
else {
|
|
50036
|
-
success(result);
|
|
50037
|
-
}
|
|
49955
|
+
const callback = (message) => {
|
|
49956
|
+
const { id, result, error, command } = message;
|
|
49957
|
+
if (command === 'response' &&
|
|
49958
|
+
id === reqId &&
|
|
49959
|
+
message.method === method) {
|
|
49960
|
+
ws.offMessage(callback);
|
|
49961
|
+
if (timer)
|
|
49962
|
+
clearTimeout(timer);
|
|
49963
|
+
if (error) {
|
|
49964
|
+
fail(error);
|
|
49965
|
+
}
|
|
49966
|
+
else {
|
|
49967
|
+
success(result);
|
|
50038
49968
|
}
|
|
50039
49969
|
}
|
|
50040
49970
|
};
|
|
50041
|
-
|
|
49971
|
+
ws.onMessage(callback);
|
|
50042
49972
|
this.send(data);
|
|
50043
49973
|
// 30s超时处理
|
|
50044
49974
|
timer = setTimeout(() => fail('method invoke timeout'), 30000);
|
|
@@ -50051,14 +49981,18 @@
|
|
|
50051
49981
|
*/
|
|
50052
49982
|
class WxMiniprogramController extends BaseController {
|
|
50053
49983
|
constructor() {
|
|
50054
|
-
super(
|
|
50055
|
-
this._hybridBridge = new HybridBridge();
|
|
49984
|
+
super();
|
|
50056
49985
|
this.initializing = false;
|
|
49986
|
+
Promise.resolve().then(async () => {
|
|
49987
|
+
try {
|
|
49988
|
+
await this.checkBridgeReady();
|
|
49989
|
+
}
|
|
49990
|
+
catch (error) {
|
|
49991
|
+
console.warn(error);
|
|
49992
|
+
}
|
|
49993
|
+
});
|
|
50057
49994
|
}
|
|
50058
|
-
|
|
50059
|
-
return this._hybridBridge;
|
|
50060
|
-
}
|
|
50061
|
-
checkBridgeReady(timeout = 60000) {
|
|
49995
|
+
checkBridgeReady(timeout = 6000) {
|
|
50062
49996
|
if (this.ready)
|
|
50063
49997
|
return true;
|
|
50064
49998
|
return new Promise(async (resolve, reject) => {
|
|
@@ -50075,11 +50009,12 @@
|
|
|
50075
50009
|
}
|
|
50076
50010
|
else {
|
|
50077
50011
|
this.initializing = true;
|
|
50078
|
-
const
|
|
50012
|
+
const hybridBridge = new HybridBridge();
|
|
50013
|
+
const [res, error] = await hybridBridge.initialize(timeout);
|
|
50079
50014
|
if (!res || error) {
|
|
50080
50015
|
throw error || new Error('HybridBridge 初始化失败~');
|
|
50081
50016
|
}
|
|
50082
|
-
|
|
50017
|
+
hybridBridge === null || hybridBridge === void 0 ? void 0 : hybridBridge.getStaticData(registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
|
|
50083
50018
|
this.deviceInfo = (() => {
|
|
50084
50019
|
try {
|
|
50085
50020
|
return JSON.parse(data);
|
|
@@ -50088,13 +50023,14 @@
|
|
|
50088
50023
|
return data;
|
|
50089
50024
|
}
|
|
50090
50025
|
})();
|
|
50026
|
+
this.hybridBridge = hybridBridge;
|
|
50027
|
+
this.initializing = false;
|
|
50028
|
+
return resolve(true);
|
|
50091
50029
|
}));
|
|
50092
|
-
this.initializing = false;
|
|
50093
|
-
return resolve(true);
|
|
50094
50030
|
}
|
|
50095
50031
|
});
|
|
50096
50032
|
}
|
|
50097
|
-
async checkReady(timeout =
|
|
50033
|
+
async checkReady(timeout = 6000) {
|
|
50098
50034
|
const res = [null, null];
|
|
50099
50035
|
if (this.ready) {
|
|
50100
50036
|
res[0] = true;
|
|
@@ -50110,7 +50046,8 @@
|
|
|
50110
50046
|
return res;
|
|
50111
50047
|
}
|
|
50112
50048
|
get ready() {
|
|
50113
|
-
|
|
50049
|
+
var _a;
|
|
50050
|
+
return !!((_a = this.hybridBridge) === null || _a === void 0 ? void 0 : _a.isReady);
|
|
50114
50051
|
}
|
|
50115
50052
|
get scheme() {
|
|
50116
50053
|
var _a;
|
|
@@ -50152,7 +50089,7 @@
|
|
|
50152
50089
|
resolve(res);
|
|
50153
50090
|
}),
|
|
50154
50091
|
});
|
|
50155
|
-
this.
|
|
50092
|
+
this.hybridBridge.callAndBackfeed(msg);
|
|
50156
50093
|
});
|
|
50157
50094
|
}
|
|
50158
50095
|
async callAndListen(scheme, callback) {
|
|
@@ -50197,7 +50134,7 @@
|
|
|
50197
50134
|
actionUrl,
|
|
50198
50135
|
functionName: registerGlobalValue(actionUrl, _callback, false),
|
|
50199
50136
|
});
|
|
50200
|
-
this.
|
|
50137
|
+
this.hybridBridge.callAndListen(msg);
|
|
50201
50138
|
});
|
|
50202
50139
|
}
|
|
50203
50140
|
async invoke(method, data) {
|
|
@@ -50207,7 +50144,7 @@
|
|
|
50207
50144
|
throw readyError;
|
|
50208
50145
|
}
|
|
50209
50146
|
else {
|
|
50210
|
-
return (await ((_b = (_a = this.
|
|
50147
|
+
return (await ((_b = (_a = this.hybridBridge).invoke) === null || _b === void 0 ? void 0 : _b.call(_a, method, data)));
|
|
50211
50148
|
}
|
|
50212
50149
|
}
|
|
50213
50150
|
}
|
|
@@ -50521,7 +50458,7 @@
|
|
|
50521
50458
|
}
|
|
50522
50459
|
|
|
50523
50460
|
const defaultOptions = {
|
|
50524
|
-
timeout:
|
|
50461
|
+
timeout: 6000,
|
|
50525
50462
|
};
|
|
50526
50463
|
/**
|
|
50527
50464
|
* 小程序 [web-view](https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html) JSBridge。
|
|
@@ -50637,12 +50574,10 @@
|
|
|
50637
50574
|
}
|
|
50638
50575
|
const proxyCache = (url) => {
|
|
50639
50576
|
if (this.webViewType === WebViewTypeEnum.WKWebview) {
|
|
50640
|
-
return url
|
|
50641
|
-
.replace(/https*:/, '')
|
|
50642
|
-
.replace(/\/\//, 'realseeproxycache://');
|
|
50577
|
+
return url.replace(/https*:/, '').replace(/\/\//, 'realseeproxycache://');
|
|
50643
50578
|
}
|
|
50644
50579
|
else if (this.webViewType === WebViewTypeEnum.WebView) {
|
|
50645
|
-
return
|
|
50580
|
+
return url + (url.indexOf('?') !== -1 ? '&' : '?') + 'realseeproxycache=1';
|
|
50646
50581
|
}
|
|
50647
50582
|
return url;
|
|
50648
50583
|
};
|
|
@@ -50651,10 +50586,6 @@
|
|
|
50651
50586
|
async invokeNativeApi(method, data) {
|
|
50652
50587
|
return await this._controller.invoke(method, data);
|
|
50653
50588
|
}
|
|
50654
|
-
async execute(method, args) {
|
|
50655
|
-
var _a, _b, _c;
|
|
50656
|
-
return await ((_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));
|
|
50657
|
-
}
|
|
50658
50589
|
}
|
|
50659
50590
|
|
|
50660
50591
|
/**
|
|
@@ -51166,7 +51097,10 @@
|
|
|
51166
51097
|
/**
|
|
51167
51098
|
* ws代理器
|
|
51168
51099
|
*/
|
|
51169
|
-
this._ws = new RobustWebSocket(
|
|
51100
|
+
this._ws = new RobustWebSocket({
|
|
51101
|
+
url: '',
|
|
51102
|
+
robustOptions: { timeout: 180000 },
|
|
51103
|
+
});
|
|
51170
51104
|
/**
|
|
51171
51105
|
* 带看连接状态
|
|
51172
51106
|
*/
|
|
@@ -51569,6 +51503,13 @@
|
|
|
51569
51503
|
return false;
|
|
51570
51504
|
}
|
|
51571
51505
|
const { force = false } = options;
|
|
51506
|
+
// 检测一下麦克风权限,hack
|
|
51507
|
+
if (this._options.rtc && this._options.jsBridge) {
|
|
51508
|
+
const res = yield this._options.jsBridge.detectMicro();
|
|
51509
|
+
if (!res) {
|
|
51510
|
+
return new Error('Failed to obtain microphone authorization');
|
|
51511
|
+
}
|
|
51512
|
+
}
|
|
51572
51513
|
// 检查是否已有实例在使用
|
|
51573
51514
|
const currentState = this.state;
|
|
51574
51515
|
if (currentState === exports.LiveState.CONNECTING ||
|