@realsee/live 0.5.0-alpha.10 → 0.5.0-alpha.13
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/live/createLiveReact.d.ts +2 -2
- package/dist/realsee-live.cjs.development.js +19 -19
- 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 +19 -19
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +494 -413
- 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/modules.html +5 -5
- package/package.json +1 -1
|
@@ -49245,48 +49245,38 @@
|
|
|
49245
49245
|
WeappBridgeMessage["alive"] = "I`m alive!";
|
|
49246
49246
|
})(WeappBridgeMessage || (WeappBridgeMessage = {}));
|
|
49247
49247
|
|
|
49248
|
+
const endpoint = 'wss://ws.realsee.com';
|
|
49249
|
+
var defaultWsEndpoint = endpoint;
|
|
49250
|
+
|
|
49248
49251
|
/**
|
|
49249
|
-
* ws
|
|
49250
|
-
*
|
|
49252
|
+
* 拼接ws链接
|
|
49253
|
+
* @param tpl
|
|
49254
|
+
* @param params
|
|
49255
|
+
* @returns
|
|
49251
49256
|
*/
|
|
49252
|
-
|
|
49253
|
-
|
|
49254
|
-
|
|
49255
|
-
|
|
49256
|
-
|
|
49257
|
-
|
|
49258
|
-
|
|
49257
|
+
const generateWssUrl = (tpl, params) => {
|
|
49258
|
+
const url = Object.keys(params).reduce((res, curr) => res.replace(`{{${curr}}}`, `${params[curr]}`), tpl);
|
|
49259
|
+
return encodeURI(url);
|
|
49260
|
+
};
|
|
49261
|
+
var generateWssUrl$1 = generateWssUrl;
|
|
49262
|
+
|
|
49263
|
+
const isValidKey = (key, object) => key in object;
|
|
49264
|
+
var isValidKey$1 = isValidKey;
|
|
49259
49265
|
|
|
49260
49266
|
/**
|
|
49261
|
-
*
|
|
49267
|
+
* 解析参数
|
|
49268
|
+
* @param query
|
|
49269
|
+
* @returns
|
|
49262
49270
|
*/
|
|
49263
|
-
const
|
|
49264
|
-
|
|
49265
|
-
|
|
49266
|
-
|
|
49267
|
-
|
|
49268
|
-
|
|
49269
|
-
|
|
49270
|
-
|
|
49271
|
-
|
|
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
|
-
};
|
|
49271
|
+
const parseQuery = (query = '') => query
|
|
49272
|
+
.replace('?', '')
|
|
49273
|
+
.split('&')
|
|
49274
|
+
.map((qs) => {
|
|
49275
|
+
const [k, v] = qs.split('=');
|
|
49276
|
+
return { [k]: decodeURIComponent(v) };
|
|
49277
|
+
})
|
|
49278
|
+
.reduce((result, curr) => ({ ...result, ...curr }), {});
|
|
49279
|
+
var parseQuery$1 = parseQuery;
|
|
49290
49280
|
|
|
49291
49281
|
const EVENT_SYMBOL = '$$REALSEE_JSBRIDGE_EVENT$$';
|
|
49292
49282
|
function __generateEventIfNotExisted(instance) {
|
|
@@ -49401,228 +49391,269 @@
|
|
|
49401
49391
|
}
|
|
49402
49392
|
|
|
49403
49393
|
/**
|
|
49404
|
-
*
|
|
49394
|
+
* 具有鲁棒性的WebSocket封装
|
|
49395
|
+
* 1、自动重连
|
|
49396
|
+
* 2、可根据网络情况进行重连
|
|
49405
49397
|
*/
|
|
49406
|
-
|
|
49407
|
-
|
|
49408
|
-
|
|
49409
|
-
|
|
49410
|
-
|
|
49411
|
-
|
|
49412
|
-
|
|
49413
|
-
|
|
49414
|
-
|
|
49415
|
-
|
|
49416
|
-
|
|
49417
|
-
|
|
49398
|
+
class RobustWebSocket$1 extends Subscribe {
|
|
49399
|
+
constructor(options) {
|
|
49400
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
49401
|
+
super();
|
|
49402
|
+
this._options = {
|
|
49403
|
+
timeout: 10000,
|
|
49404
|
+
shouldReconnect: (event, ws) => {
|
|
49405
|
+
if (event.code === 1008 || event.code === 1011)
|
|
49406
|
+
return;
|
|
49407
|
+
return [0, 3000, 10000][ws.attempts];
|
|
49408
|
+
},
|
|
49409
|
+
should1000Reconnect: false,
|
|
49410
|
+
ignoreConnectivityEvents: false,
|
|
49411
|
+
automaticOpen: false,
|
|
49412
|
+
};
|
|
49413
|
+
this._attempts = 0;
|
|
49414
|
+
this._reconnects = -1;
|
|
49415
|
+
this._reconnectWhenOnlineAgain = false;
|
|
49416
|
+
this._explicitlyClosed = false;
|
|
49417
|
+
this._connectivityEventsAttached = false;
|
|
49418
49418
|
/**
|
|
49419
|
-
*
|
|
49420
|
-
* @param listener 事件回调函数
|
|
49421
|
-
* @param once 是否只执行一次
|
|
49422
|
-
* @returns
|
|
49419
|
+
* 清理连接中的请求
|
|
49423
49420
|
*/
|
|
49424
|
-
this.
|
|
49421
|
+
this._clearPendingReconnectIfNeeded = () => {
|
|
49422
|
+
if (this._pendingReconnect) {
|
|
49423
|
+
clearTimeout(this._pendingReconnect);
|
|
49424
|
+
this._pendingReconnect = undefined;
|
|
49425
|
+
}
|
|
49426
|
+
};
|
|
49425
49427
|
/**
|
|
49426
|
-
*
|
|
49427
|
-
* @param
|
|
49428
|
+
* 当网页连接上网络进行重连
|
|
49429
|
+
* @param event
|
|
49428
49430
|
*/
|
|
49429
|
-
this.
|
|
49431
|
+
this._online = (event) => {
|
|
49432
|
+
if (this._reconnectWhenOnlineAgain) {
|
|
49433
|
+
this._clearPendingReconnectIfNeeded();
|
|
49434
|
+
this._reconnect(event);
|
|
49435
|
+
}
|
|
49436
|
+
};
|
|
49430
49437
|
/**
|
|
49431
|
-
*
|
|
49432
|
-
* @param listener 事件回调函数
|
|
49433
|
-
* @returns
|
|
49438
|
+
* 当网页断开网络进行关闭
|
|
49434
49439
|
*/
|
|
49435
|
-
this.
|
|
49440
|
+
this._offline = () => {
|
|
49441
|
+
var _a;
|
|
49442
|
+
this._reconnectWhenOnlineAgain = true;
|
|
49443
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000);
|
|
49444
|
+
};
|
|
49436
49445
|
/**
|
|
49437
|
-
*
|
|
49438
|
-
* @param listener 事件回调函数
|
|
49439
|
-
* @param once 是否只执行一次
|
|
49440
|
-
* @returns
|
|
49446
|
+
* 解除网络监听事件
|
|
49441
49447
|
*/
|
|
49442
|
-
this.
|
|
49448
|
+
this._detachConnectivityEvents = () => {
|
|
49449
|
+
if (this._connectivityEventsAttached) {
|
|
49450
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('online', this._online);
|
|
49451
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('offline', this._offline);
|
|
49452
|
+
this._connectivityEventsAttached = false;
|
|
49453
|
+
}
|
|
49454
|
+
};
|
|
49443
49455
|
/**
|
|
49444
|
-
*
|
|
49445
|
-
* @param listener 事件回调函数
|
|
49456
|
+
* 注册网络监听事件
|
|
49446
49457
|
*/
|
|
49447
|
-
this.
|
|
49458
|
+
this._attachConnectivityEvents = () => {
|
|
49459
|
+
if (!this._connectivityEventsAttached) {
|
|
49460
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('online', this._online);
|
|
49461
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('offline', this._offline);
|
|
49462
|
+
this._connectivityEventsAttached = true;
|
|
49463
|
+
}
|
|
49464
|
+
};
|
|
49448
49465
|
/**
|
|
49449
|
-
*
|
|
49450
|
-
* @param
|
|
49466
|
+
* 发送消息
|
|
49467
|
+
* @param data
|
|
49451
49468
|
* @returns
|
|
49452
49469
|
*/
|
|
49453
|
-
this.
|
|
49470
|
+
this.send = (data) => {
|
|
49471
|
+
var _a, _b, _c;
|
|
49472
|
+
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
|
|
49473
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
|
|
49474
|
+
}
|
|
49475
|
+
};
|
|
49454
49476
|
/**
|
|
49455
|
-
*
|
|
49456
|
-
* @param
|
|
49457
|
-
* @param
|
|
49477
|
+
* 关闭连接
|
|
49478
|
+
* @param code 代码
|
|
49479
|
+
* @param reason 原因
|
|
49458
49480
|
* @returns
|
|
49459
49481
|
*/
|
|
49460
|
-
this.
|
|
49482
|
+
this.close = (code, reason) => {
|
|
49483
|
+
var _a;
|
|
49484
|
+
if (typeof code !== 'number') {
|
|
49485
|
+
reason = code;
|
|
49486
|
+
code = 1000;
|
|
49487
|
+
}
|
|
49488
|
+
this._clearPendingReconnectIfNeeded();
|
|
49489
|
+
this._reconnectWhenOnlineAgain = false;
|
|
49490
|
+
this._explicitlyClosed = true;
|
|
49491
|
+
this._detachConnectivityEvents();
|
|
49492
|
+
return (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(code, reason);
|
|
49493
|
+
};
|
|
49494
|
+
/**
|
|
49495
|
+
* 进行ws连接
|
|
49496
|
+
*/
|
|
49497
|
+
this.open = (url) => {
|
|
49498
|
+
var _a, _b;
|
|
49499
|
+
if (url) {
|
|
49500
|
+
this._url = url;
|
|
49501
|
+
}
|
|
49502
|
+
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) !== WebSocket.OPEN &&
|
|
49503
|
+
((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.readyState) !== WebSocket.CONNECTING) {
|
|
49504
|
+
this._clearPendingReconnectIfNeeded();
|
|
49505
|
+
this._reconnectWhenOnlineAgain = false;
|
|
49506
|
+
this._explicitlyClosed = false;
|
|
49507
|
+
this._createWebSocket();
|
|
49508
|
+
}
|
|
49509
|
+
};
|
|
49510
|
+
/**
|
|
49511
|
+
* 创建ws连接
|
|
49512
|
+
*/
|
|
49513
|
+
this._createWebSocket = () => {
|
|
49514
|
+
var _a, _b, _c;
|
|
49515
|
+
const newUrl = typeof this._url === 'string' ? this._url : (_a = this._url) === null || _a === void 0 ? void 0 : _a.call(this, this);
|
|
49516
|
+
if (!newUrl)
|
|
49517
|
+
return;
|
|
49518
|
+
this._pendingReconnect = undefined;
|
|
49519
|
+
this._removeWebSocketEvent();
|
|
49520
|
+
this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
|
|
49521
|
+
this._attempts = this._attempts + 1;
|
|
49522
|
+
this.emit('connecting', new CustomEvent('connecting', {
|
|
49523
|
+
detail: { attempts: this._attempts, reconnects: this._reconnects },
|
|
49524
|
+
}));
|
|
49525
|
+
const timeoutCallback = () => {
|
|
49526
|
+
this._connectTimeout = undefined;
|
|
49527
|
+
this._detachConnectivityEvents();
|
|
49528
|
+
this.emit('timeout', new CustomEvent('connecting', {
|
|
49529
|
+
detail: {
|
|
49530
|
+
attempts: this._attempts,
|
|
49531
|
+
reconnects: this._reconnects,
|
|
49532
|
+
},
|
|
49533
|
+
}));
|
|
49534
|
+
};
|
|
49535
|
+
this._connectTimeout = setTimeout(timeoutCallback, (_b = this._options) === null || _b === void 0 ? void 0 : _b.timeout);
|
|
49536
|
+
this._dispatchWebSocketEvent();
|
|
49537
|
+
if (!((_c = this._options) === null || _c === void 0 ? void 0 : _c.ignoreConnectivityEvents)) {
|
|
49538
|
+
this._attachConnectivityEvents();
|
|
49539
|
+
}
|
|
49540
|
+
};
|
|
49541
|
+
/**
|
|
49542
|
+
* 断开ws事件
|
|
49543
|
+
*/
|
|
49544
|
+
this._removeWebSocketEvent = () => {
|
|
49545
|
+
var _a, _b, _c, _d;
|
|
49546
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
|
|
49547
|
+
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
|
|
49548
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
|
|
49549
|
+
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
|
|
49550
|
+
};
|
|
49461
49551
|
/**
|
|
49462
|
-
*
|
|
49463
|
-
* @param listener 事件回调函数
|
|
49552
|
+
* 分发ws事件
|
|
49464
49553
|
*/
|
|
49465
|
-
this.
|
|
49554
|
+
this._dispatchWebSocketEvent = () => {
|
|
49555
|
+
var _a, _b, _c, _d;
|
|
49556
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.addEventListener('open', this._webSocketOpenHandler);
|
|
49557
|
+
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.addEventListener('close', this._webSocketCloseHandler);
|
|
49558
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.addEventListener('error', this._webSocketErrorHandler);
|
|
49559
|
+
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.addEventListener('message', this._webSocketMessageHandler);
|
|
49560
|
+
};
|
|
49466
49561
|
/**
|
|
49467
|
-
*
|
|
49468
|
-
* @param listener 事件回调函数
|
|
49562
|
+
* ws连接事件
|
|
49469
49563
|
* @returns
|
|
49470
49564
|
*/
|
|
49471
|
-
this.
|
|
49565
|
+
this._webSocketOpenHandler = (event) => {
|
|
49566
|
+
if (this._connectTimeout) {
|
|
49567
|
+
clearTimeout(this._connectTimeout);
|
|
49568
|
+
this._connectTimeout = undefined;
|
|
49569
|
+
}
|
|
49570
|
+
const reconnects = ++this._reconnects;
|
|
49571
|
+
const attempts = this._attempts;
|
|
49572
|
+
this._attempts = 0;
|
|
49573
|
+
this._reconnectWhenOnlineAgain = false;
|
|
49574
|
+
return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
|
|
49575
|
+
};
|
|
49472
49576
|
/**
|
|
49473
|
-
*
|
|
49474
|
-
* @param
|
|
49475
|
-
* @param once 是否只执行一次
|
|
49577
|
+
* ws 关闭事件
|
|
49578
|
+
* @param event
|
|
49476
49579
|
* @returns
|
|
49477
49580
|
*/
|
|
49478
|
-
this.
|
|
49581
|
+
this._webSocketCloseHandler = (event) => {
|
|
49582
|
+
this._reconnect(event);
|
|
49583
|
+
return this.emit('close', event);
|
|
49584
|
+
};
|
|
49479
49585
|
/**
|
|
49480
|
-
*
|
|
49481
|
-
* @param
|
|
49586
|
+
* ws 异常
|
|
49587
|
+
* @param event
|
|
49588
|
+
* @returns
|
|
49482
49589
|
*/
|
|
49483
|
-
this.
|
|
49590
|
+
this._webSocketErrorHandler = (event) => {
|
|
49591
|
+
return this.emit('error', new CustomEvent('error', { detail: { error: event } }));
|
|
49592
|
+
};
|
|
49484
49593
|
/**
|
|
49485
|
-
*
|
|
49486
|
-
* @param
|
|
49594
|
+
* ws消息
|
|
49595
|
+
* @param event
|
|
49487
49596
|
* @returns
|
|
49488
49597
|
*/
|
|
49489
|
-
this.
|
|
49490
|
-
|
|
49491
|
-
|
|
49492
|
-
|
|
49493
|
-
|
|
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
|
-
});
|
|
49598
|
+
this._webSocketMessageHandler = (event) => {
|
|
49599
|
+
return this.emit('message', event);
|
|
49600
|
+
};
|
|
49601
|
+
if (options) {
|
|
49602
|
+
this.setOptions(options);
|
|
49603
|
+
}
|
|
49513
49604
|
}
|
|
49514
|
-
|
|
49515
|
-
|
|
49516
|
-
* @returns
|
|
49517
|
-
*/
|
|
49518
|
-
async reconnect() {
|
|
49519
|
-
this.close(WebSocketCloseOptions.reconnect);
|
|
49520
|
-
if (this._wsOptions)
|
|
49521
|
-
this.connect(this._wsOptions);
|
|
49605
|
+
get attempts() {
|
|
49606
|
+
return this._attempts;
|
|
49522
49607
|
}
|
|
49523
|
-
|
|
49524
|
-
|
|
49525
|
-
|
|
49526
|
-
|
|
49527
|
-
|
|
49528
|
-
|
|
49529
|
-
|
|
49530
|
-
|
|
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
|
-
}
|
|
49608
|
+
setOptions(options) {
|
|
49609
|
+
if (!options)
|
|
49610
|
+
return;
|
|
49611
|
+
this._url = options.url;
|
|
49612
|
+
this._protocols = options.protocols;
|
|
49613
|
+
const opts = Object.assign(this._options, options.robustOptions || {});
|
|
49614
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.timeout) !== 'number') {
|
|
49615
|
+
throw new Error('timeout must be the number of milliseconds to timeout a connection attempt');
|
|
49539
49616
|
}
|
|
49540
|
-
|
|
49541
|
-
|
|
49542
|
-
|
|
49617
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.shouldReconnect) !== 'function') {
|
|
49618
|
+
throw new Error('shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.');
|
|
49619
|
+
}
|
|
49620
|
+
this._options = opts;
|
|
49621
|
+
if (this._options.automaticOpen) {
|
|
49622
|
+
this._createWebSocket();
|
|
49543
49623
|
}
|
|
49544
49624
|
}
|
|
49545
49625
|
/**
|
|
49546
|
-
*
|
|
49547
|
-
* @param
|
|
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事件
|
|
49626
|
+
* 进行重连
|
|
49627
|
+
* @param event
|
|
49628
|
+
* @returns
|
|
49563
49629
|
*/
|
|
49564
|
-
|
|
49630
|
+
_reconnect(event) {
|
|
49565
49631
|
var _a, _b, _c, _d;
|
|
49566
|
-
(_a = this.
|
|
49567
|
-
|
|
49568
|
-
|
|
49569
|
-
|
|
49570
|
-
|
|
49571
|
-
|
|
49572
|
-
|
|
49573
|
-
|
|
49574
|
-
|
|
49575
|
-
|
|
49576
|
-
|
|
49577
|
-
this.
|
|
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));
|
|
49632
|
+
if ((!((_a = this._options) === null || _a === void 0 ? void 0 : _a.should1000Reconnect) && event.code === 1000) ||
|
|
49633
|
+
this._explicitlyClosed) {
|
|
49634
|
+
this._attempts = 0;
|
|
49635
|
+
return;
|
|
49636
|
+
}
|
|
49637
|
+
if (((_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _b === void 0 ? void 0 : _b.onLine) === false) {
|
|
49638
|
+
this._reconnectWhenOnlineAgain = true;
|
|
49639
|
+
return;
|
|
49640
|
+
}
|
|
49641
|
+
const delay = (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.shouldReconnect) === null || _d === void 0 ? void 0 : _d.call(_c, event, this);
|
|
49642
|
+
if (typeof delay === 'number') {
|
|
49643
|
+
this._pendingReconnect = setTimeout(this._createWebSocket, delay);
|
|
49644
|
+
}
|
|
49581
49645
|
}
|
|
49582
|
-
}
|
|
49583
|
-
var Ws4Webview$1 = Ws4Webview;
|
|
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;
|
|
49646
|
+
}
|
|
49617
49647
|
|
|
49618
|
-
const ws = (() => new Ws4Webview$1())();
|
|
49619
49648
|
class HybridBridge {
|
|
49620
49649
|
constructor() {
|
|
49650
|
+
var _a, _b;
|
|
49621
49651
|
/**
|
|
49622
49652
|
* @deprecated 兼容旧逻辑
|
|
49623
49653
|
*/
|
|
49624
49654
|
this._rsWeappBridgeMethodAdapter = {};
|
|
49625
|
-
this.
|
|
49655
|
+
this._ws = new RobustWebSocket$1();
|
|
49656
|
+
this._readyState = 'close';
|
|
49626
49657
|
/**
|
|
49627
49658
|
* 进行jsbridge的初始化,即打通ws通道
|
|
49628
49659
|
* @param timeout 超时计时
|
|
@@ -49645,7 +49676,7 @@
|
|
|
49645
49676
|
sign: wssig,
|
|
49646
49677
|
});
|
|
49647
49678
|
try {
|
|
49648
|
-
const result = await
|
|
49679
|
+
const result = await this._open(url);
|
|
49649
49680
|
if (result) {
|
|
49650
49681
|
this.initBuiltInHandlers();
|
|
49651
49682
|
res[0] = await this.waitReady(timeout);
|
|
@@ -49659,6 +49690,130 @@
|
|
|
49659
49690
|
}
|
|
49660
49691
|
return res;
|
|
49661
49692
|
};
|
|
49693
|
+
/**
|
|
49694
|
+
* 内建的处理函数
|
|
49695
|
+
*/
|
|
49696
|
+
this.initBuiltInHandlers = () => {
|
|
49697
|
+
this._registerLifecycleHandler();
|
|
49698
|
+
this._registerHeartbeatHandler();
|
|
49699
|
+
this._registerMessageHandler();
|
|
49700
|
+
this._registerBridgeRequestHandler();
|
|
49701
|
+
this._registerReadyHandler();
|
|
49702
|
+
};
|
|
49703
|
+
/**
|
|
49704
|
+
* 进行连接
|
|
49705
|
+
* @param url ws链接
|
|
49706
|
+
* @returns
|
|
49707
|
+
*/
|
|
49708
|
+
this._open = (url) => new Promise((resolve) => {
|
|
49709
|
+
const handleOpen = () => {
|
|
49710
|
+
this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true), true);
|
|
49711
|
+
this._ws.once('timeout', () => resolve(false));
|
|
49712
|
+
this.send(WeappBridgeMessage.isReady);
|
|
49713
|
+
};
|
|
49714
|
+
this._ws.once('open', handleOpen);
|
|
49715
|
+
this._ws.open(url);
|
|
49716
|
+
});
|
|
49717
|
+
/**
|
|
49718
|
+
* 注册生命周期回调
|
|
49719
|
+
*/
|
|
49720
|
+
this._registerLifecycleHandler = () => {
|
|
49721
|
+
this._ws.on('connecting', () => {
|
|
49722
|
+
console.log('RsWeappBridge connecting');
|
|
49723
|
+
this._readyState = 'connecting';
|
|
49724
|
+
});
|
|
49725
|
+
this._ws.on('open', () => {
|
|
49726
|
+
console.log('RsWeappBridge open');
|
|
49727
|
+
this._readyState = 'open';
|
|
49728
|
+
});
|
|
49729
|
+
this._ws.on('close', () => {
|
|
49730
|
+
this._readyState = 'close';
|
|
49731
|
+
});
|
|
49732
|
+
this._ws.on('error', () => {
|
|
49733
|
+
console.log('RsWeappBridge error');
|
|
49734
|
+
this._readyState = 'close';
|
|
49735
|
+
});
|
|
49736
|
+
this._ws.on('timeout', () => {
|
|
49737
|
+
console.log('RsWeappBridge timeout');
|
|
49738
|
+
this._readyState = 'close';
|
|
49739
|
+
});
|
|
49740
|
+
};
|
|
49741
|
+
/**
|
|
49742
|
+
* 注册心跳的回调
|
|
49743
|
+
* @deprecated 兼容老的容器SDK
|
|
49744
|
+
*/
|
|
49745
|
+
this._registerHeartbeatHandler = () => {
|
|
49746
|
+
// 收到ping时回复pong
|
|
49747
|
+
this._receivedMessage(WeappBridgeMessage.ping, () => setTimeout(() => this._ws.send(WeappBridgeMessage.pong), 500));
|
|
49748
|
+
// 收到pong时回复ping
|
|
49749
|
+
this._receivedMessage(WeappBridgeMessage.pong, () => setTimeout(() => this._ws.send(WeappBridgeMessage.ping), 1000));
|
|
49750
|
+
};
|
|
49751
|
+
/**
|
|
49752
|
+
* 当收到某消息时
|
|
49753
|
+
* @param targetMessage 目标消息
|
|
49754
|
+
* @param handler 回调
|
|
49755
|
+
* @param once 是否一次性处理
|
|
49756
|
+
*/
|
|
49757
|
+
this._receivedMessage = (targetMessage, handler, once) => {
|
|
49758
|
+
const msgHandler = (evnet) => {
|
|
49759
|
+
if (evnet.data === targetMessage) {
|
|
49760
|
+
handler();
|
|
49761
|
+
if (once) {
|
|
49762
|
+
this._ws.off('message', msgHandler);
|
|
49763
|
+
}
|
|
49764
|
+
}
|
|
49765
|
+
};
|
|
49766
|
+
this._ws.on('message', msgHandler);
|
|
49767
|
+
};
|
|
49768
|
+
/**
|
|
49769
|
+
* 注册准备就绪的回调
|
|
49770
|
+
*/
|
|
49771
|
+
this._registerReadyHandler = () => {
|
|
49772
|
+
// 收到就绪询问时回复已就绪
|
|
49773
|
+
this._receivedMessage(WeappBridgeMessage.isReady, () => this._ws.send(WeappBridgeMessage.ready));
|
|
49774
|
+
};
|
|
49775
|
+
/**
|
|
49776
|
+
* 发送消息
|
|
49777
|
+
*/
|
|
49778
|
+
this.send = (data) => {
|
|
49779
|
+
this._ws.send(data);
|
|
49780
|
+
};
|
|
49781
|
+
/**
|
|
49782
|
+
* 等待响应
|
|
49783
|
+
* @param timeout 超时计时
|
|
49784
|
+
* @returns
|
|
49785
|
+
*/
|
|
49786
|
+
this.waitReady = (timeout = 6000) => {
|
|
49787
|
+
return new Promise((resolve, reject) => {
|
|
49788
|
+
this._receivedMessage(WeappBridgeMessage.ready, () => resolve(true));
|
|
49789
|
+
this.send(WeappBridgeMessage.isReady);
|
|
49790
|
+
setTimeout(() => reject('HybridBridge 初始化超时~'), timeout);
|
|
49791
|
+
});
|
|
49792
|
+
};
|
|
49793
|
+
this._parseMessage = (event) => {
|
|
49794
|
+
try {
|
|
49795
|
+
return JSON.parse(event.data);
|
|
49796
|
+
}
|
|
49797
|
+
catch (e) {
|
|
49798
|
+
return event.data;
|
|
49799
|
+
}
|
|
49800
|
+
};
|
|
49801
|
+
/**
|
|
49802
|
+
* 注册消息投递回调
|
|
49803
|
+
* @deprecated 兼容老方法
|
|
49804
|
+
*/
|
|
49805
|
+
this._registerMessageHandler = () => {
|
|
49806
|
+
this._ws.on('message', (event) => {
|
|
49807
|
+
const message = this._parseMessage(event);
|
|
49808
|
+
if (typeof message === 'object') {
|
|
49809
|
+
const { id, command, data } = message;
|
|
49810
|
+
if (command === 'message' &&
|
|
49811
|
+
typeof this._rsWeappBridgeMethodAdapter.bindMessage === 'function') {
|
|
49812
|
+
this._rsWeappBridgeMethodAdapter.bindMessage({ id, data });
|
|
49813
|
+
}
|
|
49814
|
+
}
|
|
49815
|
+
});
|
|
49816
|
+
};
|
|
49662
49817
|
this.getStaticData = (callbackFunctionName) => {
|
|
49663
49818
|
this.callAndBackfeed(JSON.stringify({
|
|
49664
49819
|
actionUrl: 'common/staticData',
|
|
@@ -49705,134 +49860,52 @@
|
|
|
49705
49860
|
callback(false);
|
|
49706
49861
|
}
|
|
49707
49862
|
};
|
|
49708
|
-
|
|
49709
|
-
|
|
49710
|
-
|
|
49711
|
-
|
|
49712
|
-
|
|
49713
|
-
|
|
49714
|
-
|
|
49715
|
-
|
|
49716
|
-
|
|
49717
|
-
|
|
49718
|
-
|
|
49719
|
-
|
|
49720
|
-
|
|
49721
|
-
|
|
49722
|
-
|
|
49723
|
-
|
|
49724
|
-
|
|
49725
|
-
|
|
49726
|
-
|
|
49727
|
-
|
|
49728
|
-
|
|
49729
|
-
|
|
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;
|
|
49863
|
+
/**
|
|
49864
|
+
* 执行
|
|
49865
|
+
* @param method
|
|
49866
|
+
* @param args
|
|
49867
|
+
* @returns
|
|
49868
|
+
*/
|
|
49869
|
+
this.execute = async (method, args) => await this._invokeBridgeMethod(method, args);
|
|
49870
|
+
/**
|
|
49871
|
+
*
|
|
49872
|
+
* @param method
|
|
49873
|
+
* @param args
|
|
49874
|
+
* @returns
|
|
49875
|
+
* @deprecated 兼容老方法
|
|
49876
|
+
*/
|
|
49877
|
+
this._invokeBridgeMethod = (method, args) => new Promise((success, fail) => {
|
|
49878
|
+
const id = uuid();
|
|
49879
|
+
const wsBridgeResponsehandler = (event) => {
|
|
49880
|
+
const result = this._parseMessage(event);
|
|
49881
|
+
if (typeof result === 'object') {
|
|
49882
|
+
if (result.method === method && result.id === id) {
|
|
49883
|
+
this._ws.off('message', wsBridgeResponsehandler);
|
|
49884
|
+
result.error ? fail(result.error) : success(result.data);
|
|
49744
49885
|
}
|
|
49745
49886
|
}
|
|
49746
|
-
}
|
|
49747
|
-
|
|
49748
|
-
|
|
49749
|
-
}
|
|
49750
|
-
if (this._forceClose)
|
|
49751
|
-
this._forceClose = false;
|
|
49752
|
-
});
|
|
49753
|
-
ws.onError((err) => console.error(err));
|
|
49754
|
-
}
|
|
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);
|
|
49887
|
+
};
|
|
49888
|
+
this._ws.on('message', wsBridgeResponsehandler);
|
|
49889
|
+
this.send(JSON.stringify({ method, args, id }));
|
|
49813
49890
|
});
|
|
49891
|
+
if (((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) === null || _a === void 0 ? void 0 : _a.__Realsee_WxMini_HybridBridge__) instanceof HybridBridge) {
|
|
49892
|
+
return (_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) === null || _b === void 0 ? void 0 : _b.__Realsee_WxMini_HybridBridge__;
|
|
49893
|
+
}
|
|
49894
|
+
if (globalThis === null || globalThis === void 0 ? void 0 : globalThis.window) {
|
|
49895
|
+
globalThis.window.__Realsee_WxMini_HybridBridge__ = this;
|
|
49896
|
+
this.initBuiltInHandlers();
|
|
49897
|
+
}
|
|
49814
49898
|
}
|
|
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
|
-
});
|
|
49899
|
+
get isReady() {
|
|
49900
|
+
return this._readyState === 'open';
|
|
49829
49901
|
}
|
|
49830
49902
|
/**
|
|
49831
49903
|
* 注册bridge方法回调
|
|
49832
49904
|
* @deprecated 兼容老方法
|
|
49833
49905
|
*/
|
|
49834
49906
|
_registerBridgeRequestHandler() {
|
|
49835
|
-
|
|
49907
|
+
this._ws.on('message', async (event) => {
|
|
49908
|
+
const request = this._parseMessage(event);
|
|
49836
49909
|
if (typeof request === 'object') {
|
|
49837
49910
|
const { id, method, args, command } = request;
|
|
49838
49911
|
if (command === 'request') {
|
|
@@ -49885,22 +49958,25 @@
|
|
|
49885
49958
|
type: 'callAndBackfeed',
|
|
49886
49959
|
});
|
|
49887
49960
|
let timer = null;
|
|
49888
|
-
const callback = (
|
|
49889
|
-
const
|
|
49890
|
-
if (
|
|
49891
|
-
|
|
49892
|
-
if (
|
|
49893
|
-
|
|
49894
|
-
|
|
49895
|
-
|
|
49896
|
-
|
|
49897
|
-
|
|
49898
|
-
|
|
49899
|
-
|
|
49961
|
+
const callback = (event) => {
|
|
49962
|
+
const message = this._parseMessage(event);
|
|
49963
|
+
if (typeof message === 'object') {
|
|
49964
|
+
const { id, result, errmsg, command } = message;
|
|
49965
|
+
if (command === 'rsSchemeResponse' && id === reqId) {
|
|
49966
|
+
this._ws.off('message', callback);
|
|
49967
|
+
if (timer)
|
|
49968
|
+
clearTimeout(timer);
|
|
49969
|
+
if (errmsg) {
|
|
49970
|
+
console.warn(errmsg);
|
|
49971
|
+
backfeed(0);
|
|
49972
|
+
}
|
|
49973
|
+
else {
|
|
49974
|
+
backfeed(result);
|
|
49975
|
+
}
|
|
49900
49976
|
}
|
|
49901
49977
|
}
|
|
49902
49978
|
};
|
|
49903
|
-
|
|
49979
|
+
this._ws.on('message', callback);
|
|
49904
49980
|
this.send(data);
|
|
49905
49981
|
// 30s超时处理
|
|
49906
49982
|
timer = globalThis.setTimeout(() => {
|
|
@@ -49921,19 +49997,22 @@
|
|
|
49921
49997
|
command: 'rsSchemeRequest',
|
|
49922
49998
|
type: 'callAndListen',
|
|
49923
49999
|
});
|
|
49924
|
-
const callback = (
|
|
49925
|
-
const
|
|
49926
|
-
if (
|
|
49927
|
-
|
|
49928
|
-
|
|
49929
|
-
|
|
49930
|
-
|
|
49931
|
-
|
|
49932
|
-
|
|
50000
|
+
const callback = (event) => {
|
|
50001
|
+
const message = this._parseMessage(event);
|
|
50002
|
+
if (typeof message === 'object') {
|
|
50003
|
+
const { id, result, errmsg, command } = message;
|
|
50004
|
+
if (command === 'rsSchemeResponse' && id === reqId) {
|
|
50005
|
+
if (errmsg) {
|
|
50006
|
+
console.warn(errmsg);
|
|
50007
|
+
fn(false);
|
|
50008
|
+
}
|
|
50009
|
+
else {
|
|
50010
|
+
fn(result);
|
|
50011
|
+
}
|
|
49933
50012
|
}
|
|
49934
50013
|
}
|
|
49935
50014
|
};
|
|
49936
|
-
|
|
50015
|
+
this._ws.on('message', callback);
|
|
49937
50016
|
this.send(data);
|
|
49938
50017
|
}
|
|
49939
50018
|
/**
|
|
@@ -49952,23 +50031,26 @@
|
|
|
49952
50031
|
command: 'request',
|
|
49953
50032
|
});
|
|
49954
50033
|
let timer = null;
|
|
49955
|
-
const callback = (
|
|
49956
|
-
const
|
|
49957
|
-
if (
|
|
49958
|
-
id
|
|
49959
|
-
|
|
49960
|
-
|
|
49961
|
-
|
|
49962
|
-
|
|
49963
|
-
|
|
49964
|
-
|
|
49965
|
-
|
|
49966
|
-
|
|
49967
|
-
|
|
50034
|
+
const callback = (event) => {
|
|
50035
|
+
const message = this._parseMessage(event);
|
|
50036
|
+
if (typeof message === 'object') {
|
|
50037
|
+
const { id, result, error, command } = message;
|
|
50038
|
+
if (command === 'response' &&
|
|
50039
|
+
id === reqId &&
|
|
50040
|
+
message.method === method) {
|
|
50041
|
+
this._ws.off('message', callback);
|
|
50042
|
+
if (timer)
|
|
50043
|
+
clearTimeout(timer);
|
|
50044
|
+
if (error) {
|
|
50045
|
+
fail(error);
|
|
50046
|
+
}
|
|
50047
|
+
else {
|
|
50048
|
+
success(result);
|
|
50049
|
+
}
|
|
49968
50050
|
}
|
|
49969
50051
|
}
|
|
49970
50052
|
};
|
|
49971
|
-
|
|
50053
|
+
this._ws.on('message', callback);
|
|
49972
50054
|
this.send(data);
|
|
49973
50055
|
// 30s超时处理
|
|
49974
50056
|
timer = setTimeout(() => fail('method invoke timeout'), 30000);
|
|
@@ -49981,18 +50063,14 @@
|
|
|
49981
50063
|
*/
|
|
49982
50064
|
class WxMiniprogramController extends BaseController {
|
|
49983
50065
|
constructor() {
|
|
49984
|
-
super();
|
|
50066
|
+
super(...arguments);
|
|
50067
|
+
this._hybridBridge = new HybridBridge();
|
|
49985
50068
|
this.initializing = false;
|
|
49986
|
-
Promise.resolve().then(async () => {
|
|
49987
|
-
try {
|
|
49988
|
-
await this.checkBridgeReady();
|
|
49989
|
-
}
|
|
49990
|
-
catch (error) {
|
|
49991
|
-
console.warn(error);
|
|
49992
|
-
}
|
|
49993
|
-
});
|
|
49994
50069
|
}
|
|
49995
|
-
|
|
50070
|
+
get hybridBridge() {
|
|
50071
|
+
return this._hybridBridge;
|
|
50072
|
+
}
|
|
50073
|
+
checkBridgeReady(timeout = 60000) {
|
|
49996
50074
|
if (this.ready)
|
|
49997
50075
|
return true;
|
|
49998
50076
|
return new Promise(async (resolve, reject) => {
|
|
@@ -50009,12 +50087,11 @@
|
|
|
50009
50087
|
}
|
|
50010
50088
|
else {
|
|
50011
50089
|
this.initializing = true;
|
|
50012
|
-
const
|
|
50013
|
-
const [res, error] = await hybridBridge.initialize(timeout);
|
|
50090
|
+
const [res, error] = await this._hybridBridge.initialize(timeout);
|
|
50014
50091
|
if (!res || error) {
|
|
50015
50092
|
throw error || new Error('HybridBridge 初始化失败~');
|
|
50016
50093
|
}
|
|
50017
|
-
|
|
50094
|
+
this._hybridBridge.getStaticData(registerGlobalValue('HYBRID_BRIDGE_NAME', (data) => {
|
|
50018
50095
|
this.deviceInfo = (() => {
|
|
50019
50096
|
try {
|
|
50020
50097
|
return JSON.parse(data);
|
|
@@ -50023,14 +50100,13 @@
|
|
|
50023
50100
|
return data;
|
|
50024
50101
|
}
|
|
50025
50102
|
})();
|
|
50026
|
-
this.hybridBridge = hybridBridge;
|
|
50027
|
-
this.initializing = false;
|
|
50028
|
-
return resolve(true);
|
|
50029
50103
|
}));
|
|
50104
|
+
this.initializing = false;
|
|
50105
|
+
return resolve(true);
|
|
50030
50106
|
}
|
|
50031
50107
|
});
|
|
50032
50108
|
}
|
|
50033
|
-
async checkReady(timeout =
|
|
50109
|
+
async checkReady(timeout = 60000) {
|
|
50034
50110
|
const res = [null, null];
|
|
50035
50111
|
if (this.ready) {
|
|
50036
50112
|
res[0] = true;
|
|
@@ -50046,8 +50122,7 @@
|
|
|
50046
50122
|
return res;
|
|
50047
50123
|
}
|
|
50048
50124
|
get ready() {
|
|
50049
|
-
|
|
50050
|
-
return !!((_a = this.hybridBridge) === null || _a === void 0 ? void 0 : _a.isReady);
|
|
50125
|
+
return !!this._hybridBridge.isReady;
|
|
50051
50126
|
}
|
|
50052
50127
|
get scheme() {
|
|
50053
50128
|
var _a;
|
|
@@ -50089,7 +50164,7 @@
|
|
|
50089
50164
|
resolve(res);
|
|
50090
50165
|
}),
|
|
50091
50166
|
});
|
|
50092
|
-
this.
|
|
50167
|
+
this._hybridBridge.callAndBackfeed(msg);
|
|
50093
50168
|
});
|
|
50094
50169
|
}
|
|
50095
50170
|
async callAndListen(scheme, callback) {
|
|
@@ -50134,7 +50209,7 @@
|
|
|
50134
50209
|
actionUrl,
|
|
50135
50210
|
functionName: registerGlobalValue(actionUrl, _callback, false),
|
|
50136
50211
|
});
|
|
50137
|
-
this.
|
|
50212
|
+
this._hybridBridge.callAndListen(msg);
|
|
50138
50213
|
});
|
|
50139
50214
|
}
|
|
50140
50215
|
async invoke(method, data) {
|
|
@@ -50144,7 +50219,7 @@
|
|
|
50144
50219
|
throw readyError;
|
|
50145
50220
|
}
|
|
50146
50221
|
else {
|
|
50147
|
-
return (await ((_b = (_a = this.
|
|
50222
|
+
return (await ((_b = (_a = this._hybridBridge).invoke) === null || _b === void 0 ? void 0 : _b.call(_a, method, data)));
|
|
50148
50223
|
}
|
|
50149
50224
|
}
|
|
50150
50225
|
}
|
|
@@ -50458,7 +50533,7 @@
|
|
|
50458
50533
|
}
|
|
50459
50534
|
|
|
50460
50535
|
const defaultOptions = {
|
|
50461
|
-
timeout:
|
|
50536
|
+
timeout: 60000,
|
|
50462
50537
|
};
|
|
50463
50538
|
/**
|
|
50464
50539
|
* 小程序 [web-view](https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html) JSBridge。
|
|
@@ -50574,10 +50649,12 @@
|
|
|
50574
50649
|
}
|
|
50575
50650
|
const proxyCache = (url) => {
|
|
50576
50651
|
if (this.webViewType === WebViewTypeEnum.WKWebview) {
|
|
50577
|
-
return url
|
|
50652
|
+
return url
|
|
50653
|
+
.replace(/https*:/, '')
|
|
50654
|
+
.replace(/\/\//, 'realseeproxycache://');
|
|
50578
50655
|
}
|
|
50579
50656
|
else if (this.webViewType === WebViewTypeEnum.WebView) {
|
|
50580
|
-
return url + (url.indexOf('?') !== -1 ? '&' : '?') + 'realseeproxycache=1';
|
|
50657
|
+
return (url + (url.indexOf('?') !== -1 ? '&' : '?') + 'realseeproxycache=1');
|
|
50581
50658
|
}
|
|
50582
50659
|
return url;
|
|
50583
50660
|
};
|
|
@@ -50586,6 +50663,10 @@
|
|
|
50586
50663
|
async invokeNativeApi(method, data) {
|
|
50587
50664
|
return await this._controller.invoke(method, data);
|
|
50588
50665
|
}
|
|
50666
|
+
async execute(method, args) {
|
|
50667
|
+
var _a, _b, _c;
|
|
50668
|
+
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));
|
|
50669
|
+
}
|
|
50589
50670
|
}
|
|
50590
50671
|
|
|
50591
50672
|
/**
|
|
@@ -54311,11 +54392,11 @@
|
|
|
54311
54392
|
* @deprecated
|
|
54312
54393
|
* @returns
|
|
54313
54394
|
*/
|
|
54314
|
-
const unsafe__useLiveInstance = () =>
|
|
54395
|
+
const unsafe__useLiveInstance = () => live;
|
|
54315
54396
|
/**
|
|
54316
54397
|
* 使用rtc实例
|
|
54317
54398
|
*/
|
|
54318
|
-
const useRTCInstance = () =>
|
|
54399
|
+
const useRTCInstance = () => live.$RTC;
|
|
54319
54400
|
/**
|
|
54320
54401
|
* 不建议这样使用
|
|
54321
54402
|
* @deprecated
|
|
@@ -54325,7 +54406,7 @@
|
|
|
54325
54406
|
/**
|
|
54326
54407
|
* 带看连接操作
|
|
54327
54408
|
*/
|
|
54328
|
-
const useConnect = (options) => __awaiter$$(this, void 0, void 0, function* () { return yield
|
|
54409
|
+
const useConnect = () => (options) => __awaiter$$(this, void 0, void 0, function* () { return yield live.connect(options); });
|
|
54329
54410
|
/**
|
|
54330
54411
|
*
|
|
54331
54412
|
* @param name
|
|
@@ -54349,17 +54430,17 @@
|
|
|
54349
54430
|
*/
|
|
54350
54431
|
function useLiveAction() {
|
|
54351
54432
|
const live = useLiveInstance();
|
|
54352
|
-
const connect =
|
|
54353
|
-
const toggleMicro =
|
|
54354
|
-
const broadcast =
|
|
54355
|
-
const exit =
|
|
54356
|
-
const kick =
|
|
54357
|
-
const forbidMicro =
|
|
54358
|
-
const forbidSync =
|
|
54359
|
-
const getFramesByKey =
|
|
54360
|
-
const sendKeyframe =
|
|
54361
|
-
const setSelfInfo =
|
|
54362
|
-
const updateStatus =
|
|
54433
|
+
const connect = (options) => __awaiter$$(this, void 0, void 0, function* () { return yield live.connect(options); });
|
|
54434
|
+
const toggleMicro = (microStatus) => live.toggleMicro(microStatus);
|
|
54435
|
+
const broadcast = (data, toUserIds, timeout = 0) => __awaiter$$(this, void 0, void 0, function* () { return yield live.broadcast(data, toUserIds, timeout); });
|
|
54436
|
+
const exit = () => __awaiter$$(this, void 0, void 0, function* () { return yield live.exit(); });
|
|
54437
|
+
const kick = (toUserIds) => __awaiter$$(this, void 0, void 0, function* () { return yield live.kick(toUserIds); });
|
|
54438
|
+
const forbidMicro = (micro, toUserIds = []) => __awaiter$$(this, void 0, void 0, function* () { return yield live.forbidMicro(micro, toUserIds); });
|
|
54439
|
+
const forbidSync = (sync, toUserIds = []) => live.forbidSync(sync, toUserIds);
|
|
54440
|
+
const getFramesByKey = (key) => live.getFramesByKey(key);
|
|
54441
|
+
const sendKeyframe = (key, frame) => live.sendKeyframe(key, frame);
|
|
54442
|
+
const setSelfInfo = (userInfo) => live.setSelfInfo(userInfo);
|
|
54443
|
+
const updateStatus = (evtType, atnType, status, toUserIds) => live.updateStatus(evtType, atnType, status, toUserIds);
|
|
54363
54444
|
return {
|
|
54364
54445
|
connect,
|
|
54365
54446
|
broadcast,
|
|
@@ -54413,11 +54494,11 @@
|
|
|
54413
54494
|
}
|
|
54414
54495
|
function useRTCAction() {
|
|
54415
54496
|
const live = useLiveInstance();
|
|
54416
|
-
const join =
|
|
54417
|
-
const quit =
|
|
54418
|
-
const shock =
|
|
54419
|
-
const toggleMicro =
|
|
54420
|
-
const detectMicro =
|
|
54497
|
+
const join = (options) => live.$RTC.join(options);
|
|
54498
|
+
const quit = () => live.$RTC.quit();
|
|
54499
|
+
const shock = () => { var _a, _b; return (_b = (_a = live.$RTC).shock) === null || _b === void 0 ? void 0 : _b.call(_a); };
|
|
54500
|
+
const toggleMicro = (flag) => live.$RTC.toggleMicro(flag);
|
|
54501
|
+
const detectMicro = () => live.$RTC.detectMicro();
|
|
54421
54502
|
return {
|
|
54422
54503
|
join,
|
|
54423
54504
|
quit,
|