fcr-ui-widget-sdk 3.10.0 → 3.10.1
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/lib/index.d.ts +1 -1
- package/lib/sdk.d.ts +20 -4
- package/lib/sdk.js +189 -75
- package/lib/type.d.ts +69 -114
- package/lib/type.js +15 -1
- package/lib/utils.d.ts +3 -2
- package/lib/utils.js +8 -1
- package/lib-es/sdk.js +195 -80
- package/lib-es/type.js +13 -1
- package/lib-es/utils.js +7 -0
- package/package.json +30 -30
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { FcrUIWidgetSDKImpl as FcrUIWidgetSDK } from './sdk';
|
|
2
|
-
export type {
|
|
2
|
+
export type { FcrUIWidgetSDKCallback, FcrUIWidgetSDKApiResponse, FcrUIWidgetSDKApiRequest, FcrUIWidgetSDKObserver, FcrUIWidgetSDKMethodName, FcrUIWidgetSDKCallbacName, } from './type';
|
package/lib/sdk.d.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import type { FcrIPConnectorSessionParams, FcrPhoneConnectorSessionParams, FcrRoomInfo, FcrRoomSchedule, FcrRoomState, FcrUserInfo } from 'fcr-core/lib/type';
|
|
2
|
-
import {
|
|
2
|
+
import { FcrUIWidgetSDKObserver, FcrUIWidgetSDK } from './type';
|
|
3
3
|
export declare class FcrUIWidgetSDKImpl implements FcrUIWidgetSDK {
|
|
4
4
|
protected logger: import("agora-foundation/lib/logger").Logger;
|
|
5
5
|
private _observable;
|
|
6
6
|
private _requestPromises;
|
|
7
|
+
private static _globalCounter;
|
|
7
8
|
constructor();
|
|
8
9
|
private _addLogObserver;
|
|
9
10
|
private _createCallId;
|
|
10
11
|
private _createRequestParams;
|
|
11
12
|
private _sendRequest;
|
|
13
|
+
private _bridgeReady;
|
|
14
|
+
/** 避免 __onFcrJSBridgeReady__ / BRIDGE_READY postMessage 重复执行初始化 */
|
|
15
|
+
private _onBridgeReadyRan;
|
|
16
|
+
private _pendingRequests;
|
|
17
|
+
/**
|
|
18
|
+
* 等待 bridge 就绪后再发起请求。桥接没准备好时先缓存请求,待bridge ready之后批量发送。
|
|
19
|
+
* - 已就绪则直接走_sendRequest
|
|
20
|
+
* - 未就绪则放入_pendingRequests,超时10s自动reject
|
|
21
|
+
*/
|
|
22
|
+
private _ensureBridgeReady;
|
|
23
|
+
private _handleBridgeReadyMessage;
|
|
24
|
+
private _onBridgeReady;
|
|
12
25
|
getRoomInfo(): Promise<FcrRoomInfo>;
|
|
13
26
|
getRoomSchedule(): Promise<FcrRoomSchedule>;
|
|
14
27
|
getRoomState(): Promise<FcrRoomState>;
|
|
@@ -17,8 +30,11 @@ export declare class FcrUIWidgetSDKImpl implements FcrUIWidgetSDK {
|
|
|
17
30
|
getAllUserCount(): Promise<number>;
|
|
18
31
|
startSessionByPhone(params: FcrPhoneConnectorSessionParams): Promise<string>;
|
|
19
32
|
startSessionByIP(params: FcrIPConnectorSessionParams): Promise<string>;
|
|
20
|
-
stopSession(sessionId: string): Promise<
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
stopSession(sessionId: string): Promise<number>;
|
|
34
|
+
active(): Promise<void>;
|
|
35
|
+
inactive(): Promise<void>;
|
|
36
|
+
getActivity(): Promise<boolean>;
|
|
37
|
+
addObserver(observer: FcrUIWidgetSDKObserver): void;
|
|
38
|
+
removeObserver(observer: FcrUIWidgetSDKObserver): void;
|
|
23
39
|
private _handlePostMessage;
|
|
24
40
|
}
|
package/lib/sdk.js
CHANGED
|
@@ -3,31 +3,38 @@
|
|
|
3
3
|
require("core-js/modules/es.symbol.js");
|
|
4
4
|
require("core-js/modules/es.symbol.description.js");
|
|
5
5
|
require("core-js/modules/es.symbol.to-primitive.js");
|
|
6
|
-
require("core-js/modules/es.error.cause.js");
|
|
7
|
-
require("core-js/modules/es.error.to-string.js");
|
|
8
|
-
require("core-js/modules/es.array.push.js");
|
|
9
6
|
require("core-js/modules/es.date.to-primitive.js");
|
|
10
7
|
require("core-js/modules/es.function.bind.js");
|
|
11
8
|
require("core-js/modules/es.function.name.js");
|
|
9
|
+
require("core-js/modules/es.number.constructor.js");
|
|
12
10
|
require("core-js/modules/es.object.create.js");
|
|
13
11
|
require("core-js/modules/es.object.define-property.js");
|
|
14
12
|
require("core-js/modules/es.object.get-own-property-descriptor.js");
|
|
15
13
|
require("core-js/modules/esnext.function.metadata.js");
|
|
16
14
|
require("core-js/modules/esnext.symbol.metadata.js");
|
|
17
15
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
18
|
-
var
|
|
16
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
19
17
|
Object.defineProperty(exports, "__esModule", {
|
|
20
18
|
value: true
|
|
21
19
|
});
|
|
22
20
|
exports.FcrUIWidgetSDKImpl = void 0;
|
|
21
|
+
require("core-js/modules/es.error.cause.js");
|
|
22
|
+
require("core-js/modules/es.error.to-string.js");
|
|
23
23
|
require("core-js/modules/es.array.concat.js");
|
|
24
|
+
require("core-js/modules/es.array.for-each.js");
|
|
25
|
+
require("core-js/modules/es.array.index-of.js");
|
|
24
26
|
require("core-js/modules/es.array.is-array.js");
|
|
25
27
|
require("core-js/modules/es.array.iterator.js");
|
|
26
|
-
require("core-js/modules/es.
|
|
28
|
+
require("core-js/modules/es.array.push.js");
|
|
29
|
+
require("core-js/modules/es.array.slice.js");
|
|
30
|
+
require("core-js/modules/es.array.splice.js");
|
|
31
|
+
require("core-js/modules/es.date.now.js");
|
|
27
32
|
require("core-js/modules/es.map.js");
|
|
28
|
-
require("core-js/modules/es.number.constructor.js");
|
|
29
33
|
require("core-js/modules/es.object.to-string.js");
|
|
34
|
+
require("core-js/modules/es.promise.js");
|
|
30
35
|
require("core-js/modules/es.string.iterator.js");
|
|
36
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
37
|
+
require("core-js/modules/esnext.iterator.for-each.js");
|
|
31
38
|
require("core-js/modules/esnext.map.delete-all.js");
|
|
32
39
|
require("core-js/modules/esnext.map.emplace.js");
|
|
33
40
|
require("core-js/modules/esnext.map.every.js");
|
|
@@ -42,26 +49,29 @@ require("core-js/modules/esnext.map.merge.js");
|
|
|
42
49
|
require("core-js/modules/esnext.map.reduce.js");
|
|
43
50
|
require("core-js/modules/esnext.map.some.js");
|
|
44
51
|
require("core-js/modules/esnext.map.update.js");
|
|
52
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
45
53
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
54
|
+
require("core-js/modules/web.timers.js");
|
|
46
55
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
47
56
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
48
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
49
57
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
50
58
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
51
59
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
52
60
|
var _bound = require("agora-foundation/lib/decorator/bound");
|
|
53
61
|
var _observable = require("agora-foundation/lib/utilities/observable");
|
|
62
|
+
var _type = require("./type");
|
|
54
63
|
var _logger = require("./logger");
|
|
55
64
|
var _utils = require("./utils");
|
|
56
65
|
var _FcrUIWidgetSDKImpl;
|
|
57
66
|
var _initProto;
|
|
58
|
-
function _applyDecs(e, t, r, n, o, a) { function i(e, t, r) { return function (n, o) { return r && r(n), e[t].call(n, o); }; } function c(e, t) { for (var r = 0; r < e.length; r++) e[r].call(t); return t; } function s(e, t, r, n) { if ("function" != typeof e && (n || void 0 !== e)) throw new TypeError(t + " must " + (r || "be") + " a function" + (n ? "" : " or undefined")); return e; } function applyDec(e, t, r, n, o, a, c, u, l, f, p, d, h) { function m(e) { if (!h(e)) throw new TypeError("Attempted to access private element on non-instance"); } var y, v = t[0], g = t[3], b = !u; if (!b) { r || Array.isArray(v) || (v = [v]); var w = {}, S = [], A = 3 === o ? "get" : 4 === o || d ? "set" : "value"; f ? (p || d ? w = { get: _setFunctionName(function () { return g(this); }, n, "get"), set: function set(e) { t[4](this, e); } } : w[A] = g, p || _setFunctionName(w[A], n, 2 === o ? "" : A)) : p || (w = Object.getOwnPropertyDescriptor(e, n)); } for (var P = e, j = v.length - 1; j >= 0; j -= r ? 2 : 1) { var D = v[j], E = r ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o], name: n, metadata: a, addInitializer: function (e, t) { if (e.v) throw Error("attempted to call addInitializer after decoration was finished"); s(t, "An initializer", "be", !0), c.push(t); }.bind(null, I) }; try { if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);else { var k, F; O["static"] = l, O["private"] = f, f ? 2 === o ? k = function k(e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function k(e) { return e[n]; }, (o < 2 || 4 === o) && (F = function F(e, t) { e[n] = t; })); var N = O.access = { has: f ? h.bind() : function (e) { return n in e; } }; if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) { if ("object" ==
|
|
59
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" ==
|
|
60
|
-
function _toPrimitive(t, r) { if ("object" !=
|
|
61
|
-
function _setFunctionName(e, t, n) { "symbol" ==
|
|
62
|
-
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ?
|
|
67
|
+
function _applyDecs(e, t, r, n, o, a) { function i(e, t, r) { return function (n, o) { return r && r(n), e[t].call(n, o); }; } function c(e, t) { for (var r = 0; r < e.length; r++) e[r].call(t); return t; } function s(e, t, r, n) { if ("function" != typeof e && (n || void 0 !== e)) throw new TypeError(t + " must " + (r || "be") + " a function" + (n ? "" : " or undefined")); return e; } function applyDec(e, t, r, n, o, a, c, u, l, f, p, d, h) { function m(e) { if (!h(e)) throw new TypeError("Attempted to access private element on non-instance"); } var y, v = t[0], g = t[3], b = !u; if (!b) { r || Array.isArray(v) || (v = [v]); var w = {}, S = [], A = 3 === o ? "get" : 4 === o || d ? "set" : "value"; f ? (p || d ? w = { get: _setFunctionName(function () { return g(this); }, n, "get"), set: function set(e) { t[4](this, e); } } : w[A] = g, p || _setFunctionName(w[A], n, 2 === o ? "" : A)) : p || (w = Object.getOwnPropertyDescriptor(e, n)); } for (var P = e, j = v.length - 1; j >= 0; j -= r ? 2 : 1) { var D = v[j], E = r ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o], name: n, metadata: a, addInitializer: function (e, t) { if (e.v) throw Error("attempted to call addInitializer after decoration was finished"); s(t, "An initializer", "be", !0), c.push(t); }.bind(null, I) }; try { if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);else { var k, F; O["static"] = l, O["private"] = f, f ? 2 === o ? k = function k(e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function k(e) { return e[n]; }, (o < 2 || 4 === o) && (F = function F(e, t) { e[n] = t; })); var N = O.access = { has: f ? h.bind() : function (e) { return n in e; } }; if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) { if ("object" == _typeof(P) && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); } else s(P, (p ? "field" : "method") + " decorators", "return") && (p ? S.push(P) : w[A] = P); } } finally { I.v = !0; } } return (p || d) && u.push(function (e, t) { for (var r = S.length - 1; r >= 0; r--) t = S[r].call(e, t); return t; }), p || b || (f ? d ? u.push(i(w, "get"), i(w, "set")) : u.push(2 === o ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e, n, w)), P; } function u(e, t) { return Object.defineProperty(e, Symbol.metadata || Symbol["for"]("Symbol.metadata"), { configurable: !0, enumerable: !0, value: t }); } if (arguments.length >= 6) var l = a[Symbol.metadata || Symbol["for"]("Symbol.metadata")]; var f = Object.create(null == l ? null : l), p = function (e, t, r, n) { var o, a, i = [], s = function s(t) { return _checkInRHS(t) === e; }, u = new Map(); function l(e) { e && i.push(c.bind(null, e)); } for (var f = 0; f < t.length; f++) { var p = t[f]; if (Array.isArray(p)) { var d = p[1], h = p[2], m = p.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v; if (!g && !m) { var w = u.get(b); if (!0 === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h); u.set(b, !(d > 2) || d); } applyDec(v ? e : e.prototype, p, y, m ? "#" + h : _toPropertyKey(h), d, n, v ? a = a || [] : o = o || [], i, v, m, g, 1 === d, v && m ? s : r); } } return l(o), l(a), i; }(e, t, o, f); return r.length || u(e, f), { e: p, get c() { var t = []; return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t), f), c.bind(null, t, e)]; } }; }
|
|
68
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
69
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
70
|
+
function _setFunctionName(e, t, n) { "symbol" == _typeof(t) && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
|
|
71
|
+
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? _typeof(e) : "null")); return e; }
|
|
63
72
|
var FcrUIWidgetSDKImpl = exports.FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
64
73
|
function FcrUIWidgetSDKImpl() {
|
|
74
|
+
var _this = this;
|
|
65
75
|
(0, _classCallCheck2["default"])(this, FcrUIWidgetSDKImpl);
|
|
66
76
|
(0, _defineProperty2["default"])(this, "logger", (_initProto(this), (0, _logger.createLogger)({
|
|
67
77
|
prefix: 'FcrUIWidgetSDK',
|
|
@@ -69,18 +79,59 @@ var FcrUIWidgetSDKImpl = exports.FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
69
79
|
})));
|
|
70
80
|
(0, _defineProperty2["default"])(this, "_observable", new _observable.AgoraObservable());
|
|
71
81
|
(0, _defineProperty2["default"])(this, "_requestPromises", new Map());
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
(0, _defineProperty2["default"])(this, "_bridgeReady", false);
|
|
83
|
+
/** 避免 __onFcrJSBridgeReady__ / BRIDGE_READY postMessage 重复执行初始化 */
|
|
84
|
+
(0, _defineProperty2["default"])(this, "_onBridgeReadyRan", false);
|
|
85
|
+
(0, _defineProperty2["default"])(this, "_pendingRequests", []);
|
|
86
|
+
(0, _defineProperty2["default"])(this, "_handleBridgeReadyMessage", function (event) {
|
|
87
|
+
var _data$payload;
|
|
88
|
+
var data = event.data;
|
|
89
|
+
if ((data === null || data === void 0 ? void 0 : data.type) === _type.FcrJSBridgeMessageEvent && ((_data$payload = data.payload) === null || _data$payload === void 0 ? void 0 : _data$payload.action) === _type.FcrUIWidgetSDKActionEnum.BRIDGE_READY) {
|
|
90
|
+
_this._onBridgeReady();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
(0, _defineProperty2["default"])(this, "_onBridgeReady", function () {
|
|
94
|
+
if (_this._onBridgeReadyRan) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
_this._onBridgeReadyRan = true;
|
|
98
|
+
_this._bridgeReady = true;
|
|
99
|
+
window.removeEventListener('message', _this._handleBridgeReadyMessage);
|
|
100
|
+
window.addEventListener('message', _this._handlePostMessage);
|
|
101
|
+
_this._addLogObserver();
|
|
102
|
+
_this.logger.debug('init sdk onBridgeReady');
|
|
103
|
+
// flush pending requests
|
|
104
|
+
var requests = _this._pendingRequests.slice();
|
|
105
|
+
_this._pendingRequests = [];
|
|
106
|
+
requests.forEach(function (_ref) {
|
|
107
|
+
var funcName = _ref.funcName,
|
|
108
|
+
parameters = _ref.parameters,
|
|
109
|
+
resolve = _ref.resolve,
|
|
110
|
+
reject = _ref.reject;
|
|
111
|
+
_this._sendRequest(funcName, parameters).then(resolve)["catch"](reject);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
this._bridgeReady = typeof window.__fcrJSBridgeReady__ === 'boolean' ? window.__fcrJSBridgeReady__ : false;
|
|
115
|
+
window.addEventListener('message', this._handleBridgeReadyMessage);
|
|
116
|
+
if (window.__fcrJSBridgeReady__) {
|
|
117
|
+
this._onBridgeReady();
|
|
118
|
+
} else {
|
|
119
|
+
window.__onFcrJSBridgeReady__ = this._onBridgeReady;
|
|
120
|
+
}
|
|
74
121
|
}
|
|
75
122
|
return (0, _createClass2["default"])(FcrUIWidgetSDKImpl, [{
|
|
76
123
|
key: "_addLogObserver",
|
|
77
124
|
value: function _addLogObserver() {
|
|
78
125
|
this.addObserver((0, _logger.generateLogObserver)(this.logger, ['onRoomStateUpdated', 'onRemoteUsersJoined', 'onRemoteUsersLeft', 'onUserInfoUpdated', 'onAllUserCountUpdated']));
|
|
79
126
|
}
|
|
127
|
+
|
|
128
|
+
// private _createCallId(prefix: string) {
|
|
129
|
+
// return `${prefix}-${++this._callIdCounter}-${Date.now()}`;
|
|
130
|
+
// }
|
|
80
131
|
}, {
|
|
81
132
|
key: "_createCallId",
|
|
82
133
|
value: function _createCallId(prefix) {
|
|
83
|
-
return "".concat(prefix, "-").concat(
|
|
134
|
+
return "".concat(prefix, "-").concat(++FcrUIWidgetSDKImpl._globalCounter, "-").concat(Date.now());
|
|
84
135
|
}
|
|
85
136
|
}, {
|
|
86
137
|
key: "_createRequestParams",
|
|
@@ -88,7 +139,7 @@ var FcrUIWidgetSDKImpl = exports.FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
88
139
|
var callId = this._createCallId(funcName);
|
|
89
140
|
var finalParameters = parameters !== null && parameters !== void 0 ? parameters : [];
|
|
90
141
|
return {
|
|
91
|
-
action:
|
|
142
|
+
action: _type.FcrUIWidgetSDKActionEnum.API_REQUEST,
|
|
92
143
|
callId: callId,
|
|
93
144
|
method: funcName,
|
|
94
145
|
parameters: finalParameters
|
|
@@ -101,118 +152,182 @@ var FcrUIWidgetSDKImpl = exports.FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
101
152
|
var p = (0, _utils.createControlledPromise)();
|
|
102
153
|
this._requestPromises.set(params.callId, p);
|
|
103
154
|
try {
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
func(params);
|
|
108
|
-
this.logger.debug('sendRequest + JsBridge: ', params);
|
|
109
|
-
}
|
|
155
|
+
if (typeof window.postMessageToFcrJSBridge === 'function' && window.postMessageToFcrJSBridge !== null) {
|
|
156
|
+
window.postMessageToFcrJSBridge(params);
|
|
157
|
+
this.logger.debug('sendRequest + postMessageToFcrJSBridge: ', params);
|
|
110
158
|
} else {
|
|
111
|
-
|
|
112
|
-
|
|
159
|
+
if ((0, _utils.isNativePlatform)()) {
|
|
160
|
+
this.logger.warn('sendRequest + postMessageToFcrJSBridge is not supported in native platform');
|
|
161
|
+
var reject = p.reject;
|
|
162
|
+
reject && reject(new Error('postMessageToFcrJSBridge is not available on native platform'));
|
|
163
|
+
} else {
|
|
164
|
+
this.logger.debug('sendRequest + postMessage: ', params);
|
|
165
|
+
window.parent.postMessage(params, '*');
|
|
166
|
+
}
|
|
113
167
|
}
|
|
114
168
|
} catch (error) {
|
|
115
169
|
this.logger.error('Error sending request:', error);
|
|
116
|
-
var
|
|
117
|
-
|
|
170
|
+
var _reject = p.reject;
|
|
171
|
+
_reject && _reject(error);
|
|
118
172
|
}
|
|
119
173
|
return p.promise;
|
|
120
174
|
}
|
|
175
|
+
}, {
|
|
176
|
+
key: "_ensureBridgeReady",
|
|
177
|
+
value:
|
|
178
|
+
/**
|
|
179
|
+
* 等待 bridge 就绪后再发起请求。桥接没准备好时先缓存请求,待bridge ready之后批量发送。
|
|
180
|
+
* - 已就绪则直接走_sendRequest
|
|
181
|
+
* - 未就绪则放入_pendingRequests,超时10s自动reject
|
|
182
|
+
*/
|
|
183
|
+
function _ensureBridgeReady(funcName, parameters) {
|
|
184
|
+
var _this2 = this;
|
|
185
|
+
if (this._bridgeReady) {
|
|
186
|
+
// bridge已就绪,直接请求
|
|
187
|
+
return this._sendRequest(funcName, parameters);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// bridge未就绪,请求进入pending队列
|
|
191
|
+
return new Promise(function (resolve, reject) {
|
|
192
|
+
var timeoutId;
|
|
193
|
+
|
|
194
|
+
// 同步清理timeout
|
|
195
|
+
var wrappedResolve = function wrappedResolve(value) {
|
|
196
|
+
clearTimeout(timeoutId);
|
|
197
|
+
resolve(value);
|
|
198
|
+
};
|
|
199
|
+
var wrappedReject = function wrappedReject(reason) {
|
|
200
|
+
clearTimeout(timeoutId);
|
|
201
|
+
reject(reason);
|
|
202
|
+
};
|
|
203
|
+
var pendingRequest = {
|
|
204
|
+
funcName: funcName,
|
|
205
|
+
parameters: parameters,
|
|
206
|
+
resolve: wrappedResolve,
|
|
207
|
+
reject: wrappedReject
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// 添加到pending队列
|
|
211
|
+
_this2._pendingRequests.push(pendingRequest);
|
|
212
|
+
|
|
213
|
+
// 设定10s超时,超时未ready自动失败并移除
|
|
214
|
+
timeoutId = setTimeout(function () {
|
|
215
|
+
// 找到并移除pendingRequest
|
|
216
|
+
var idx = _this2._pendingRequests.indexOf(pendingRequest);
|
|
217
|
+
if (idx > -1) {
|
|
218
|
+
_this2._pendingRequests.splice(idx, 1);
|
|
219
|
+
}
|
|
220
|
+
reject(new Error('Bridge ready timeout'));
|
|
221
|
+
}, 10000);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
121
224
|
}, {
|
|
122
225
|
key: "getRoomInfo",
|
|
123
|
-
value: function
|
|
124
|
-
|
|
125
|
-
getRoomInfo() {
|
|
126
|
-
return this._sendRequest('getRoomInfo');
|
|
226
|
+
value: function getRoomInfo() {
|
|
227
|
+
return this._ensureBridgeReady('getRoomInfo');
|
|
127
228
|
}
|
|
128
229
|
}, {
|
|
129
230
|
key: "getRoomSchedule",
|
|
130
|
-
value: function
|
|
131
|
-
|
|
132
|
-
getRoomSchedule() {
|
|
133
|
-
return this._sendRequest('getRoomSchedule');
|
|
231
|
+
value: function getRoomSchedule() {
|
|
232
|
+
return this._ensureBridgeReady('getRoomSchedule');
|
|
134
233
|
}
|
|
135
234
|
}, {
|
|
136
235
|
key: "getRoomState",
|
|
137
|
-
value: function
|
|
138
|
-
|
|
139
|
-
getRoomState() {
|
|
140
|
-
return this._sendRequest('getRoomState');
|
|
236
|
+
value: function getRoomState() {
|
|
237
|
+
return this._ensureBridgeReady('getRoomState');
|
|
141
238
|
}
|
|
142
239
|
}, {
|
|
143
240
|
key: "getLocalUser",
|
|
144
|
-
value: function
|
|
145
|
-
|
|
146
|
-
getLocalUser() {
|
|
147
|
-
return this._sendRequest('getLocalUser');
|
|
241
|
+
value: function getLocalUser() {
|
|
242
|
+
return this._ensureBridgeReady('getLocalUser');
|
|
148
243
|
}
|
|
149
244
|
}, {
|
|
150
245
|
key: "getUserList",
|
|
151
|
-
value: function
|
|
152
|
-
|
|
153
|
-
getUserList() {
|
|
154
|
-
return this._sendRequest('getUserList');
|
|
246
|
+
value: function getUserList() {
|
|
247
|
+
return this._ensureBridgeReady('getUserList');
|
|
155
248
|
}
|
|
156
249
|
}, {
|
|
157
250
|
key: "getAllUserCount",
|
|
158
|
-
value: function
|
|
159
|
-
|
|
160
|
-
getAllUserCount() {
|
|
161
|
-
return this._sendRequest('getAllUserCount');
|
|
251
|
+
value: function getAllUserCount() {
|
|
252
|
+
return this._ensureBridgeReady('getAllUserCount');
|
|
162
253
|
}
|
|
163
254
|
}, {
|
|
164
255
|
key: "startSessionByPhone",
|
|
165
256
|
value: function startSessionByPhone(params) {
|
|
166
|
-
return this.
|
|
257
|
+
return this._ensureBridgeReady('startSessionByPhone', [params]);
|
|
167
258
|
}
|
|
168
259
|
}, {
|
|
169
260
|
key: "startSessionByIP",
|
|
170
261
|
value: function startSessionByIP(params) {
|
|
171
|
-
return this.
|
|
262
|
+
return this._ensureBridgeReady('startSessionByIP', [params]);
|
|
172
263
|
}
|
|
173
264
|
}, {
|
|
174
265
|
key: "stopSession",
|
|
175
266
|
value: function stopSession(sessionId) {
|
|
176
|
-
return this.
|
|
267
|
+
return this._ensureBridgeReady('stopSession', [sessionId]);
|
|
268
|
+
}
|
|
269
|
+
}, {
|
|
270
|
+
key: "active",
|
|
271
|
+
value: function active() {
|
|
272
|
+
return this._ensureBridgeReady('active');
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: "inactive",
|
|
276
|
+
value: function inactive() {
|
|
277
|
+
return this._ensureBridgeReady('inactive');
|
|
278
|
+
}
|
|
279
|
+
}, {
|
|
280
|
+
key: "getActivity",
|
|
281
|
+
value: function getActivity() {
|
|
282
|
+
return this._ensureBridgeReady('getActivity');
|
|
177
283
|
}
|
|
178
284
|
}, {
|
|
179
285
|
key: "addObserver",
|
|
180
|
-
value: function
|
|
181
|
-
// @trace
|
|
182
|
-
addObserver(observer) {
|
|
286
|
+
value: function addObserver(observer) {
|
|
183
287
|
this._observable.addObserver(observer);
|
|
184
288
|
}
|
|
185
289
|
}, {
|
|
186
290
|
key: "removeObserver",
|
|
187
|
-
value: function
|
|
188
|
-
// @trace
|
|
189
|
-
removeObserver(observer) {
|
|
291
|
+
value: function removeObserver(observer) {
|
|
190
292
|
this._observable.removeObserver(observer);
|
|
191
293
|
}
|
|
192
294
|
}, {
|
|
193
295
|
key: "_handlePostMessage",
|
|
194
296
|
value: function _handlePostMessage(event) {
|
|
195
297
|
if (event.data) {
|
|
196
|
-
var
|
|
197
|
-
|
|
298
|
+
var _event$data = event.data,
|
|
299
|
+
payload = _event$data.payload,
|
|
300
|
+
type = _event$data.type;
|
|
301
|
+
if (!payload) return;
|
|
302
|
+
var isFcrJSBridge = typeof window.postMessageToFcrJSBridge === 'function' && window.postMessageToFcrJSBridge !== null;
|
|
303
|
+
if (type !== _type.FcrJSBridgeMessageEvent && isFcrJSBridge) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (payload.action === _type.FcrUIWidgetSDKActionEnum.API_RESPONSE) {
|
|
198
307
|
this.logger.debug('handlePostMessage apiResponse: ', event.data);
|
|
199
|
-
var
|
|
200
|
-
callId =
|
|
201
|
-
returnValue =
|
|
308
|
+
var _ref2 = payload,
|
|
309
|
+
callId = _ref2.callId,
|
|
310
|
+
returnValue = _ref2.returnValue,
|
|
311
|
+
error = _ref2.error;
|
|
202
312
|
var controllerPromiseGroup = this._requestPromises.get(callId);
|
|
203
313
|
if (controllerPromiseGroup) {
|
|
204
314
|
this.logger.info('resolve callId', callId);
|
|
205
|
-
var resolve = controllerPromiseGroup.resolve
|
|
206
|
-
|
|
315
|
+
var resolve = controllerPromiseGroup.resolve,
|
|
316
|
+
reject = controllerPromiseGroup.reject;
|
|
317
|
+
if (error) {
|
|
318
|
+
reject && reject(error);
|
|
319
|
+
} else {
|
|
320
|
+
resolve && resolve(returnValue);
|
|
321
|
+
}
|
|
207
322
|
this._requestPromises["delete"](callId);
|
|
208
323
|
}
|
|
209
|
-
} else if (action ===
|
|
324
|
+
} else if (payload.action === _type.FcrUIWidgetSDKActionEnum.CALLBACK) {
|
|
210
325
|
var _this$_observable;
|
|
211
326
|
this.logger.debug('handlePostMessage callback: ', event.data);
|
|
212
|
-
var
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
var args = Array.isArray(
|
|
327
|
+
var _payload = payload.payload,
|
|
328
|
+
method = _payload.method,
|
|
329
|
+
parameters = _payload.parameters;
|
|
330
|
+
var args = Array.isArray(parameters) ? parameters : [parameters];
|
|
216
331
|
(_this$_observable = this._observable).notifyObservers.apply(_this$_observable, [method].concat((0, _toConsumableArray2["default"])(args)));
|
|
217
332
|
}
|
|
218
333
|
}
|
|
@@ -220,7 +335,6 @@ var FcrUIWidgetSDKImpl = exports.FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
220
335
|
}]);
|
|
221
336
|
}();
|
|
222
337
|
_FcrUIWidgetSDKImpl = FcrUIWidgetSDKImpl;
|
|
223
|
-
var _applyDecs$e = _applyDecs(_FcrUIWidgetSDKImpl, [[_bound.bound, 2, "getRoomInfo"], [_bound.bound, 2, "getRoomSchedule"], [_bound.bound, 2, "getRoomState"], [_bound.bound, 2, "getLocalUser"], [_bound.bound, 2, "getUserList"], [_bound.bound, 2, "getAllUserCount"], [_bound.bound, 2, "startSessionByPhone"], [_bound.bound, 2, "startSessionByIP"], [_bound.bound, 2, "stopSession"], [_bound.bound, 2, "addObserver"], [_bound.bound, 2, "removeObserver"], [_bound.bound, 2, "_handlePostMessage"]], []).e;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
_applyDecs$e;
|
|
338
|
+
var _applyDecs$e = (0, _slicedToArray2["default"])(_applyDecs(_FcrUIWidgetSDKImpl, [[_bound.bound, 2, "getRoomInfo"], [_bound.bound, 2, "getRoomSchedule"], [_bound.bound, 2, "getRoomState"], [_bound.bound, 2, "getLocalUser"], [_bound.bound, 2, "getUserList"], [_bound.bound, 2, "getAllUserCount"], [_bound.bound, 2, "startSessionByPhone"], [_bound.bound, 2, "startSessionByIP"], [_bound.bound, 2, "stopSession"], [_bound.bound, 2, "active"], [_bound.bound, 2, "inactive"], [_bound.bound, 2, "getActivity"], [_bound.bound, 2, "addObserver"], [_bound.bound, 2, "removeObserver"], [_bound.bound, 2, "_handlePostMessage"]], []).e, 1);
|
|
339
|
+
_initProto = _applyDecs$e[0];
|
|
340
|
+
(0, _defineProperty2["default"])(FcrUIWidgetSDKImpl, "_globalCounter", 0);
|
package/lib/type.d.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import type { FcrIPConnectorSession, FcrIPConnectorSessionParams, FcrPhoneConnectorSession, FcrPhoneConnectorSessionParams, FcrRoomConnectorSessionReason, FcrRoomConnectorSessionState, FcrRoomInfo, FcrRoomSchedule, FcrRoomState, FcrUserInfo } from 'fcr-core/lib/type';
|
|
2
|
-
import type { FcrUserJoinedEvent, FcrUserLeftEvent,
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
}[keyof T];
|
|
6
|
-
export type FcrUIWebWidgetMethodName = MethodNames<FcrUIBaseWidget>;
|
|
7
|
-
export type ID = string;
|
|
8
|
-
export interface FcrPopupSize {
|
|
9
|
-
width: number;
|
|
10
|
-
height: number;
|
|
11
|
-
}
|
|
2
|
+
import type { FcrUserJoinedEvent, FcrUserLeftEvent, FcrUserUpdatedEvent } from 'fcr-core/lib/room-control/user-control/type';
|
|
3
|
+
export type FcrUIWidgetSDKMethodName = keyof FcrUIWidgetSDK;
|
|
4
|
+
export type FcrUIWidgetSDKMethodParameters = unknown[];
|
|
12
5
|
export interface FcrUIWidgetSDK {
|
|
13
6
|
/**
|
|
14
7
|
* 获取房间信息
|
|
15
8
|
*/
|
|
16
|
-
getRoomInfo(): Promise<FcrRoomInfo>;
|
|
9
|
+
getRoomInfo(): Promise<FcrRoomInfo | undefined>;
|
|
17
10
|
/**
|
|
18
11
|
* 获取房间行程信息(如开始时间、持续时长等)
|
|
19
12
|
*/
|
|
20
|
-
getRoomSchedule(): Promise<FcrRoomSchedule>;
|
|
13
|
+
getRoomSchedule(): Promise<FcrRoomSchedule | undefined>;
|
|
21
14
|
/**
|
|
22
15
|
* 获取当前房间状态
|
|
23
16
|
*/
|
|
@@ -25,11 +18,11 @@ export interface FcrUIWidgetSDK {
|
|
|
25
18
|
/**
|
|
26
19
|
* 获取本地用户信息
|
|
27
20
|
*/
|
|
28
|
-
getLocalUser(): Promise<FcrUserInfo>;
|
|
21
|
+
getLocalUser(): Promise<FcrUserInfo | undefined>;
|
|
29
22
|
/**
|
|
30
23
|
* 获取远端用户列表
|
|
31
24
|
*/
|
|
32
|
-
getUserList(): Promise<FcrUserInfo[]
|
|
25
|
+
getUserList(): Promise<Readonly<FcrUserInfo[]>>;
|
|
33
26
|
/**
|
|
34
27
|
* 获取房间内用户总数
|
|
35
28
|
*/
|
|
@@ -47,40 +40,54 @@ export interface FcrUIWidgetSDK {
|
|
|
47
40
|
* 停止会话
|
|
48
41
|
* @param sessionId 会话ID
|
|
49
42
|
*/
|
|
50
|
-
stopSession(sessionId: string): Promise<
|
|
43
|
+
stopSession(sessionId: string): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* 激活widget
|
|
46
|
+
* @param widgetId widgetId
|
|
47
|
+
*/
|
|
48
|
+
active(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* 停用widget
|
|
51
|
+
* @param widgetId widgetId
|
|
52
|
+
*/
|
|
53
|
+
inactive(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* 获取指定 widget 是否处于激活状态(scene 中 `widgets.{widgetId}.state === 1`)。
|
|
56
|
+
*/
|
|
57
|
+
getActivity(): Promise<boolean>;
|
|
51
58
|
/**
|
|
52
59
|
* 添加观察者,用来接收 Widget 事件回调
|
|
53
60
|
* @param observer 实现 FcrUIWidgetObserver 的对象
|
|
54
61
|
*/
|
|
55
|
-
addObserver(observer:
|
|
62
|
+
addObserver(observer: FcrUIWidgetSDKObserver): void;
|
|
56
63
|
/**
|
|
57
64
|
* 移除之前添加的观察者
|
|
58
65
|
* @param observer 要移除的观察者
|
|
59
66
|
*/
|
|
60
|
-
removeObserver(observer:
|
|
67
|
+
removeObserver(observer: FcrUIWidgetSDKObserver): void;
|
|
61
68
|
}
|
|
62
|
-
export interface
|
|
69
|
+
export interface FcrUIWidgetSDKObserver {
|
|
63
70
|
/**
|
|
64
71
|
* 房间状态更新回调
|
|
65
72
|
* @param state 最新的房间状态
|
|
66
73
|
* @returns
|
|
67
74
|
*/
|
|
68
|
-
onRoomStateUpdated(roomId: string, state: FcrRoomState): void;
|
|
75
|
+
onRoomStateUpdated?(roomId: string, state: FcrRoomState): void;
|
|
69
76
|
/**
|
|
70
77
|
* 远端用户加入房间回调
|
|
71
78
|
* @param events 事件数组
|
|
72
79
|
*/
|
|
73
|
-
onRemoteUsersJoined(roomId: string, events: FcrUserJoinedEvent[]): void;
|
|
80
|
+
onRemoteUsersJoined?(roomId: string, events: FcrUserJoinedEvent[]): void;
|
|
74
81
|
/**
|
|
75
82
|
* 远端用户离开房间回调
|
|
76
83
|
* @param events 事件数组
|
|
77
84
|
*/
|
|
78
|
-
onRemoteUsersLeft(roomId: string, events: FcrUserLeftEvent[]): void;
|
|
85
|
+
onRemoteUsersLeft?(roomId: string, events: FcrUserLeftEvent[]): void;
|
|
79
86
|
/**
|
|
80
87
|
* Callback to receive the user updated event.
|
|
81
88
|
* @param event
|
|
82
89
|
*/
|
|
83
|
-
onUserInfoUpdated(roomId: string, event: FcrUserUpdatedEvent): void;
|
|
90
|
+
onUserInfoUpdated?(roomId: string, event: FcrUserUpdatedEvent): void;
|
|
84
91
|
/**
|
|
85
92
|
* 房间内所有用户总数更新回调
|
|
86
93
|
* @param count 当前的用户数量
|
|
@@ -101,106 +108,54 @@ export interface FcrUIWidgetObserver {
|
|
|
101
108
|
*/
|
|
102
109
|
onIPConnectorSessionStateUpdated?(session: FcrIPConnectorSession, state: FcrRoomConnectorSessionState, reason: FcrRoomConnectorSessionReason): void;
|
|
103
110
|
}
|
|
104
|
-
export
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 获取房间行程信息(如开始时间、持续时长等)
|
|
111
|
-
*/
|
|
112
|
-
getRoomSchedule(): FcrRoomSchedule | undefined;
|
|
113
|
-
/**
|
|
114
|
-
* 获取当前房间状态
|
|
115
|
-
*/
|
|
116
|
-
getRoomState(): FcrRoomState;
|
|
117
|
-
/**
|
|
118
|
-
* 获取本地用户信息
|
|
119
|
-
*/
|
|
120
|
-
getLocalUser(): FcrUserInfo;
|
|
121
|
-
/**
|
|
122
|
-
* 获取远端用户列表
|
|
123
|
-
*/
|
|
124
|
-
getUserList(): Readonly<FcrUserInfo[]>;
|
|
125
|
-
/**
|
|
126
|
-
* 获取房间内用户总数
|
|
127
|
-
*/
|
|
128
|
-
getAllUserCount(): number;
|
|
129
|
-
/**
|
|
130
|
-
* 开始电话会话
|
|
131
|
-
* @param params 会话参数
|
|
132
|
-
*/
|
|
133
|
-
startSessionByPhone(params: FcrPhoneConnectorSessionParams): Promise<string>;
|
|
134
|
-
/**
|
|
135
|
-
* 开始IP会话
|
|
136
|
-
*/
|
|
137
|
-
startSessionByIP(params: FcrIPConnectorSessionParams): Promise<string>;
|
|
138
|
-
/**
|
|
139
|
-
* 停止会话
|
|
140
|
-
* @param sessionId 会话ID
|
|
141
|
-
*/
|
|
142
|
-
stopSession(sessionId: string): Promise<void>;
|
|
143
|
-
/**
|
|
144
|
-
* Fetches the list of users.
|
|
145
|
-
* @param params
|
|
146
|
-
*/
|
|
147
|
-
fetchUserList(params: FcrUserPageParams): Promise<FcrUserPageResponse>;
|
|
148
|
-
/**
|
|
149
|
-
* 添加观察者,用来接收 Widget 事件回调
|
|
150
|
-
* @param observer 实现 FcrUIWidgetObserver 的对象
|
|
151
|
-
*/
|
|
152
|
-
addObserver(observer: FcrUIWidgetObserver): void;
|
|
153
|
-
/**
|
|
154
|
-
* 移除之前添加的观察者
|
|
155
|
-
* @param observer 要移除的观察者
|
|
156
|
-
*/
|
|
157
|
-
removeObserver(observer: FcrUIWidgetObserver): void;
|
|
158
|
-
}
|
|
159
|
-
export interface FcrUIWebWidget extends FcrUIBaseWidget {
|
|
160
|
-
/**
|
|
161
|
-
* 实例化widget
|
|
162
|
-
* 创建webview并注入FcrUIBaseWidget中的方法或者回调,命名空间FcrJSBridge
|
|
163
|
-
* webview加载FcrUIWebWidgetConfig.url
|
|
164
|
-
* @param webview 承载内嵌iframe的window引用
|
|
165
|
-
* @param dialogWindow 承载widgetDialog的window引用
|
|
166
|
-
*/
|
|
167
|
-
init(webview: Window, dialogWindow: Window): void;
|
|
168
|
-
/**
|
|
169
|
-
* 刷新webview
|
|
170
|
-
*/
|
|
171
|
-
reload(): void;
|
|
172
|
-
/**
|
|
173
|
-
*销毁widget
|
|
174
|
-
*/
|
|
175
|
-
release(): void;
|
|
176
|
-
}
|
|
177
|
-
export type ApiRequest = {
|
|
178
|
-
action: 'apiRequest';
|
|
179
|
-
callId: number;
|
|
180
|
-
method: string;
|
|
181
|
-
parameters: [];
|
|
111
|
+
export type FcrUIWidgetSDKApiRequest = {
|
|
112
|
+
action: FcrUIWidgetSDKActionEnum.API_REQUEST;
|
|
113
|
+
callId: string;
|
|
114
|
+
method: FcrUIWidgetSDKMethodName;
|
|
115
|
+
parameters: FcrUIWidgetSDKMethodParameters;
|
|
182
116
|
};
|
|
183
|
-
export type
|
|
184
|
-
action:
|
|
185
|
-
callId:
|
|
186
|
-
method:
|
|
187
|
-
returnValue
|
|
117
|
+
export type FcrUIWidgetSDKApiResponse = {
|
|
118
|
+
action: FcrUIWidgetSDKActionEnum.API_RESPONSE;
|
|
119
|
+
callId: string;
|
|
120
|
+
method: FcrUIWidgetSDKMethodName;
|
|
121
|
+
returnValue?: unknown;
|
|
122
|
+
error?: {
|
|
123
|
+
code: number;
|
|
124
|
+
message: string;
|
|
125
|
+
};
|
|
188
126
|
};
|
|
189
|
-
export type
|
|
190
|
-
|
|
191
|
-
|
|
127
|
+
export type FcrUIWidgetSDKCallbacName = keyof FcrUIWidgetSDKObserver;
|
|
128
|
+
export type FcrUIWidgetSDKCallback = {
|
|
129
|
+
action: FcrUIWidgetSDKActionEnum.CALLBACK;
|
|
130
|
+
payload: {
|
|
131
|
+
method: FcrUIWidgetSDKCallbacName;
|
|
132
|
+
parameters: unknown[];
|
|
133
|
+
};
|
|
192
134
|
};
|
|
193
|
-
export type
|
|
135
|
+
export type FcrUIWidgetSDKControlledPromise<T> = {
|
|
194
136
|
promise: Promise<T>;
|
|
195
137
|
resolve?: (value: T | PromiseLike<T>) => void;
|
|
196
138
|
reject?: (reason?: any) => void;
|
|
197
139
|
};
|
|
198
|
-
export
|
|
199
|
-
|
|
200
|
-
|
|
140
|
+
export type FcrUIWidgetSDKPendingRequest = {
|
|
141
|
+
funcName: FcrUIWidgetSDKMethodName;
|
|
142
|
+
parameters?: FcrUIWidgetSDKMethodParameters;
|
|
143
|
+
resolve: (value: any) => void;
|
|
144
|
+
reject: (error?: any) => void;
|
|
145
|
+
};
|
|
201
146
|
declare global {
|
|
202
147
|
interface Window {
|
|
203
|
-
|
|
148
|
+
/** 宿主注入:JS Bridge 是否已就绪 */
|
|
149
|
+
__fcrJSBridgeReady__?: boolean;
|
|
150
|
+
__onFcrJSBridgeReady__?: () => void;
|
|
151
|
+
postMessageToFcrJSBridge?: (params: Record<string, any>) => void;
|
|
204
152
|
}
|
|
205
153
|
}
|
|
206
|
-
export
|
|
154
|
+
export declare const FcrJSBridgeMessageEvent = "fcr-js-bridge";
|
|
155
|
+
export declare enum FcrUIWidgetSDKActionEnum {
|
|
156
|
+
API_REQUEST = "apiRequest",
|
|
157
|
+
API_RESPONSE = "apiResponse",
|
|
158
|
+
CALLBACK = "callback",
|
|
159
|
+
/** 宿主跨域 iframe 无法用 __onFcrJSBridgeReady__ 回调时,通过 postMessage 通知桥接就绪 */
|
|
160
|
+
BRIDGE_READY = "bridgeReady"
|
|
161
|
+
}
|
package/lib/type.js
CHANGED
|
@@ -3,4 +3,18 @@
|
|
|
3
3
|
require("core-js/modules/es.object.define-property.js");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
|
-
});
|
|
6
|
+
});
|
|
7
|
+
exports.FcrUIWidgetSDKActionEnum = exports.FcrJSBridgeMessageEvent = void 0;
|
|
8
|
+
// export interface JsBridge {
|
|
9
|
+
// [funcName: string]: (params: Record<string, any>) => void;
|
|
10
|
+
// }
|
|
11
|
+
|
|
12
|
+
var FcrJSBridgeMessageEvent = exports.FcrJSBridgeMessageEvent = 'fcr-js-bridge';
|
|
13
|
+
var FcrUIWidgetSDKActionEnum = exports.FcrUIWidgetSDKActionEnum = /*#__PURE__*/function (FcrUIWidgetSDKActionEnum) {
|
|
14
|
+
FcrUIWidgetSDKActionEnum["API_REQUEST"] = "apiRequest";
|
|
15
|
+
FcrUIWidgetSDKActionEnum["API_RESPONSE"] = "apiResponse";
|
|
16
|
+
FcrUIWidgetSDKActionEnum["CALLBACK"] = "callback";
|
|
17
|
+
/** 宿主跨域 iframe 无法用 __onFcrJSBridgeReady__ 回调时,通过 postMessage 通知桥接就绪 */
|
|
18
|
+
FcrUIWidgetSDKActionEnum["BRIDGE_READY"] = "bridgeReady";
|
|
19
|
+
return FcrUIWidgetSDKActionEnum;
|
|
20
|
+
}({});
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const createControlledPromise: <T>() =>
|
|
1
|
+
import { FcrUIWidgetSDKControlledPromise } from './type';
|
|
2
|
+
export declare const createControlledPromise: <T>() => FcrUIWidgetSDKControlledPromise<T>;
|
|
3
|
+
export declare const isNativePlatform: () => boolean;
|
package/lib/utils.js
CHANGED
|
@@ -4,9 +4,11 @@ require("core-js/modules/es.object.define-property.js");
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.createControlledPromise = void 0;
|
|
7
|
+
exports.isNativePlatform = exports.createControlledPromise = void 0;
|
|
8
8
|
require("core-js/modules/es.object.to-string.js");
|
|
9
9
|
require("core-js/modules/es.promise.js");
|
|
10
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
11
|
+
require("core-js/modules/es.regexp.test.js");
|
|
10
12
|
var createControlledPromise = exports.createControlledPromise = function createControlledPromise() {
|
|
11
13
|
var resolve = function resolve() {};
|
|
12
14
|
var reject = function reject() {};
|
|
@@ -19,4 +21,9 @@ var createControlledPromise = exports.createControlledPromise = function createC
|
|
|
19
21
|
resolve: resolve,
|
|
20
22
|
reject: reject
|
|
21
23
|
};
|
|
24
|
+
};
|
|
25
|
+
var isNativePlatform = exports.isNativePlatform = function isNativePlatform() {
|
|
26
|
+
var ua = navigator.userAgent.toLowerCase();
|
|
27
|
+
var hasWebViewUA = /wv|webview/.test(ua) || /; wv\)/.test(ua);
|
|
28
|
+
return hasWebViewUA;
|
|
22
29
|
};
|
package/lib-es/sdk.js
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "core-js/modules/es.symbol.description.js";
|
|
3
|
-
import "core-js/modules/es.symbol.to-primitive.js";
|
|
4
|
-
import "core-js/modules/es.error.cause.js";
|
|
5
|
-
import "core-js/modules/es.error.to-string.js";
|
|
6
|
-
import "core-js/modules/es.array.push.js";
|
|
7
|
-
import "core-js/modules/es.date.to-primitive.js";
|
|
8
|
-
import "core-js/modules/es.function.bind.js";
|
|
9
|
-
import "core-js/modules/es.function.name.js";
|
|
10
|
-
import "core-js/modules/es.object.create.js";
|
|
11
|
-
import "core-js/modules/es.object.define-property.js";
|
|
12
|
-
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
13
|
-
import "core-js/modules/esnext.function.metadata.js";
|
|
14
|
-
import "core-js/modules/esnext.symbol.metadata.js";
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
15
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
16
3
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
17
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
|
18
4
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
19
5
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
20
6
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
21
7
|
var _FcrUIWidgetSDKImpl;
|
|
22
8
|
var _initProto;
|
|
9
|
+
import "core-js/modules/es.symbol.js";
|
|
10
|
+
import "core-js/modules/es.symbol.description.js";
|
|
11
|
+
import "core-js/modules/es.symbol.to-primitive.js";
|
|
12
|
+
import "core-js/modules/es.error.cause.js";
|
|
13
|
+
import "core-js/modules/es.error.to-string.js";
|
|
23
14
|
import "core-js/modules/es.array.concat.js";
|
|
15
|
+
import "core-js/modules/es.array.for-each.js";
|
|
16
|
+
import "core-js/modules/es.array.index-of.js";
|
|
24
17
|
import "core-js/modules/es.array.is-array.js";
|
|
25
18
|
import "core-js/modules/es.array.iterator.js";
|
|
26
|
-
import "core-js/modules/es.
|
|
19
|
+
import "core-js/modules/es.array.push.js";
|
|
20
|
+
import "core-js/modules/es.array.slice.js";
|
|
21
|
+
import "core-js/modules/es.array.splice.js";
|
|
22
|
+
import "core-js/modules/es.date.now.js";
|
|
23
|
+
import "core-js/modules/es.date.to-primitive.js";
|
|
24
|
+
import "core-js/modules/es.function.bind.js";
|
|
25
|
+
import "core-js/modules/es.function.name.js";
|
|
27
26
|
import "core-js/modules/es.map.js";
|
|
28
27
|
import "core-js/modules/es.number.constructor.js";
|
|
28
|
+
import "core-js/modules/es.object.create.js";
|
|
29
|
+
import "core-js/modules/es.object.define-property.js";
|
|
30
|
+
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
29
31
|
import "core-js/modules/es.object.to-string.js";
|
|
32
|
+
import "core-js/modules/es.promise.js";
|
|
30
33
|
import "core-js/modules/es.string.iterator.js";
|
|
34
|
+
import "core-js/modules/esnext.function.metadata.js";
|
|
35
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
36
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
31
37
|
import "core-js/modules/esnext.map.delete-all.js";
|
|
32
38
|
import "core-js/modules/esnext.map.emplace.js";
|
|
33
39
|
import "core-js/modules/esnext.map.every.js";
|
|
@@ -42,7 +48,10 @@ import "core-js/modules/esnext.map.merge.js";
|
|
|
42
48
|
import "core-js/modules/esnext.map.reduce.js";
|
|
43
49
|
import "core-js/modules/esnext.map.some.js";
|
|
44
50
|
import "core-js/modules/esnext.map.update.js";
|
|
51
|
+
import "core-js/modules/esnext.symbol.metadata.js";
|
|
52
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
45
53
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
54
|
+
import "core-js/modules/web.timers.js";
|
|
46
55
|
function _applyDecs(e, t, r, n, o, a) { function i(e, t, r) { return function (n, o) { return r && r(n), e[t].call(n, o); }; } function c(e, t) { for (var r = 0; r < e.length; r++) e[r].call(t); return t; } function s(e, t, r, n) { if ("function" != typeof e && (n || void 0 !== e)) throw new TypeError(t + " must " + (r || "be") + " a function" + (n ? "" : " or undefined")); return e; } function applyDec(e, t, r, n, o, a, c, u, l, f, p, d, h) { function m(e) { if (!h(e)) throw new TypeError("Attempted to access private element on non-instance"); } var y, v = t[0], g = t[3], b = !u; if (!b) { r || Array.isArray(v) || (v = [v]); var w = {}, S = [], A = 3 === o ? "get" : 4 === o || d ? "set" : "value"; f ? (p || d ? w = { get: _setFunctionName(function () { return g(this); }, n, "get"), set: function set(e) { t[4](this, e); } } : w[A] = g, p || _setFunctionName(w[A], n, 2 === o ? "" : A)) : p || (w = Object.getOwnPropertyDescriptor(e, n)); } for (var P = e, j = v.length - 1; j >= 0; j -= r ? 2 : 1) { var D = v[j], E = r ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o], name: n, metadata: a, addInitializer: function (e, t) { if (e.v) throw Error("attempted to call addInitializer after decoration was finished"); s(t, "An initializer", "be", !0), c.push(t); }.bind(null, I) }; try { if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);else { var k, F; O["static"] = l, O["private"] = f, f ? 2 === o ? k = function k(e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function k(e) { return e[n]; }, (o < 2 || 4 === o) && (F = function F(e, t) { e[n] = t; })); var N = O.access = { has: f ? h.bind() : function (e) { return n in e; } }; if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) { if ("object" == _typeof(P) && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); } else s(P, (p ? "field" : "method") + " decorators", "return") && (p ? S.push(P) : w[A] = P); } } finally { I.v = !0; } } return (p || d) && u.push(function (e, t) { for (var r = S.length - 1; r >= 0; r--) t = S[r].call(e, t); return t; }), p || b || (f ? d ? u.push(i(w, "get"), i(w, "set")) : u.push(2 === o ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e, n, w)), P; } function u(e, t) { return Object.defineProperty(e, Symbol.metadata || Symbol["for"]("Symbol.metadata"), { configurable: !0, enumerable: !0, value: t }); } if (arguments.length >= 6) var l = a[Symbol.metadata || Symbol["for"]("Symbol.metadata")]; var f = Object.create(null == l ? null : l), p = function (e, t, r, n) { var o, a, i = [], s = function s(t) { return _checkInRHS(t) === e; }, u = new Map(); function l(e) { e && i.push(c.bind(null, e)); } for (var f = 0; f < t.length; f++) { var p = t[f]; if (Array.isArray(p)) { var d = p[1], h = p[2], m = p.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v; if (!g && !m) { var w = u.get(b); if (!0 === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h); u.set(b, !(d > 2) || d); } applyDec(v ? e : e.prototype, p, y, m ? "#" + h : _toPropertyKey(h), d, n, v ? a = a || [] : o = o || [], i, v, m, g, 1 === d, v && m ? s : r); } } return l(o), l(a), i; }(e, t, o, f); return r.length || u(e, f), { e: p, get c() { var t = []; return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t), f), c.bind(null, t, e)]; } }; }
|
|
47
56
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
48
57
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
@@ -50,10 +59,12 @@ function _setFunctionName(e, t, n) { "symbol" == _typeof(t) && (t = (t = t.descr
|
|
|
50
59
|
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? _typeof(e) : "null")); return e; }
|
|
51
60
|
import { bound } from 'agora-foundation/lib/decorator/bound';
|
|
52
61
|
import { AgoraObservable } from 'agora-foundation/lib/utilities/observable';
|
|
62
|
+
import { FcrJSBridgeMessageEvent, FcrUIWidgetSDKActionEnum } from './type';
|
|
53
63
|
import { createLogger, generateLogObserver } from './logger';
|
|
54
|
-
import { createControlledPromise } from './utils';
|
|
64
|
+
import { createControlledPromise, isNativePlatform } from './utils';
|
|
55
65
|
export var FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
56
66
|
function FcrUIWidgetSDKImpl() {
|
|
67
|
+
var _this = this;
|
|
57
68
|
_classCallCheck(this, FcrUIWidgetSDKImpl);
|
|
58
69
|
_defineProperty(this, "logger", (_initProto(this), createLogger({
|
|
59
70
|
prefix: 'FcrUIWidgetSDK',
|
|
@@ -61,18 +72,59 @@ export var FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
61
72
|
})));
|
|
62
73
|
_defineProperty(this, "_observable", new AgoraObservable());
|
|
63
74
|
_defineProperty(this, "_requestPromises", new Map());
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
_defineProperty(this, "_bridgeReady", false);
|
|
76
|
+
/** 避免 __onFcrJSBridgeReady__ / BRIDGE_READY postMessage 重复执行初始化 */
|
|
77
|
+
_defineProperty(this, "_onBridgeReadyRan", false);
|
|
78
|
+
_defineProperty(this, "_pendingRequests", []);
|
|
79
|
+
_defineProperty(this, "_handleBridgeReadyMessage", function (event) {
|
|
80
|
+
var _data$payload;
|
|
81
|
+
var data = event.data;
|
|
82
|
+
if ((data === null || data === void 0 ? void 0 : data.type) === FcrJSBridgeMessageEvent && ((_data$payload = data.payload) === null || _data$payload === void 0 ? void 0 : _data$payload.action) === FcrUIWidgetSDKActionEnum.BRIDGE_READY) {
|
|
83
|
+
_this._onBridgeReady();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
_defineProperty(this, "_onBridgeReady", function () {
|
|
87
|
+
if (_this._onBridgeReadyRan) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
_this._onBridgeReadyRan = true;
|
|
91
|
+
_this._bridgeReady = true;
|
|
92
|
+
window.removeEventListener('message', _this._handleBridgeReadyMessage);
|
|
93
|
+
window.addEventListener('message', _this._handlePostMessage);
|
|
94
|
+
_this._addLogObserver();
|
|
95
|
+
_this.logger.debug('init sdk onBridgeReady');
|
|
96
|
+
// flush pending requests
|
|
97
|
+
var requests = _this._pendingRequests.slice();
|
|
98
|
+
_this._pendingRequests = [];
|
|
99
|
+
requests.forEach(function (_ref) {
|
|
100
|
+
var funcName = _ref.funcName,
|
|
101
|
+
parameters = _ref.parameters,
|
|
102
|
+
resolve = _ref.resolve,
|
|
103
|
+
reject = _ref.reject;
|
|
104
|
+
_this._sendRequest(funcName, parameters).then(resolve)["catch"](reject);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
this._bridgeReady = typeof window.__fcrJSBridgeReady__ === 'boolean' ? window.__fcrJSBridgeReady__ : false;
|
|
108
|
+
window.addEventListener('message', this._handleBridgeReadyMessage);
|
|
109
|
+
if (window.__fcrJSBridgeReady__) {
|
|
110
|
+
this._onBridgeReady();
|
|
111
|
+
} else {
|
|
112
|
+
window.__onFcrJSBridgeReady__ = this._onBridgeReady;
|
|
113
|
+
}
|
|
66
114
|
}
|
|
67
115
|
return _createClass(FcrUIWidgetSDKImpl, [{
|
|
68
116
|
key: "_addLogObserver",
|
|
69
117
|
value: function _addLogObserver() {
|
|
70
118
|
this.addObserver(generateLogObserver(this.logger, ['onRoomStateUpdated', 'onRemoteUsersJoined', 'onRemoteUsersLeft', 'onUserInfoUpdated', 'onAllUserCountUpdated']));
|
|
71
119
|
}
|
|
120
|
+
|
|
121
|
+
// private _createCallId(prefix: string) {
|
|
122
|
+
// return `${prefix}-${++this._callIdCounter}-${Date.now()}`;
|
|
123
|
+
// }
|
|
72
124
|
}, {
|
|
73
125
|
key: "_createCallId",
|
|
74
126
|
value: function _createCallId(prefix) {
|
|
75
|
-
return "".concat(prefix, "-").concat(
|
|
127
|
+
return "".concat(prefix, "-").concat(++FcrUIWidgetSDKImpl._globalCounter, "-").concat(Date.now());
|
|
76
128
|
}
|
|
77
129
|
}, {
|
|
78
130
|
key: "_createRequestParams",
|
|
@@ -80,7 +132,7 @@ export var FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
80
132
|
var callId = this._createCallId(funcName);
|
|
81
133
|
var finalParameters = parameters !== null && parameters !== void 0 ? parameters : [];
|
|
82
134
|
return {
|
|
83
|
-
action:
|
|
135
|
+
action: FcrUIWidgetSDKActionEnum.API_REQUEST,
|
|
84
136
|
callId: callId,
|
|
85
137
|
method: funcName,
|
|
86
138
|
parameters: finalParameters
|
|
@@ -93,118 +145,182 @@ export var FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
93
145
|
var p = createControlledPromise();
|
|
94
146
|
this._requestPromises.set(params.callId, p);
|
|
95
147
|
try {
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
func(params);
|
|
100
|
-
this.logger.debug('sendRequest + JsBridge: ', params);
|
|
101
|
-
}
|
|
148
|
+
if (typeof window.postMessageToFcrJSBridge === 'function' && window.postMessageToFcrJSBridge !== null) {
|
|
149
|
+
window.postMessageToFcrJSBridge(params);
|
|
150
|
+
this.logger.debug('sendRequest + postMessageToFcrJSBridge: ', params);
|
|
102
151
|
} else {
|
|
103
|
-
|
|
104
|
-
|
|
152
|
+
if (isNativePlatform()) {
|
|
153
|
+
this.logger.warn('sendRequest + postMessageToFcrJSBridge is not supported in native platform');
|
|
154
|
+
var reject = p.reject;
|
|
155
|
+
reject && reject(new Error('postMessageToFcrJSBridge is not available on native platform'));
|
|
156
|
+
} else {
|
|
157
|
+
this.logger.debug('sendRequest + postMessage: ', params);
|
|
158
|
+
window.parent.postMessage(params, '*');
|
|
159
|
+
}
|
|
105
160
|
}
|
|
106
161
|
} catch (error) {
|
|
107
162
|
this.logger.error('Error sending request:', error);
|
|
108
|
-
var
|
|
109
|
-
|
|
163
|
+
var _reject = p.reject;
|
|
164
|
+
_reject && _reject(error);
|
|
110
165
|
}
|
|
111
166
|
return p.promise;
|
|
112
167
|
}
|
|
168
|
+
}, {
|
|
169
|
+
key: "_ensureBridgeReady",
|
|
170
|
+
value:
|
|
171
|
+
/**
|
|
172
|
+
* 等待 bridge 就绪后再发起请求。桥接没准备好时先缓存请求,待bridge ready之后批量发送。
|
|
173
|
+
* - 已就绪则直接走_sendRequest
|
|
174
|
+
* - 未就绪则放入_pendingRequests,超时10s自动reject
|
|
175
|
+
*/
|
|
176
|
+
function _ensureBridgeReady(funcName, parameters) {
|
|
177
|
+
var _this2 = this;
|
|
178
|
+
if (this._bridgeReady) {
|
|
179
|
+
// bridge已就绪,直接请求
|
|
180
|
+
return this._sendRequest(funcName, parameters);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// bridge未就绪,请求进入pending队列
|
|
184
|
+
return new Promise(function (resolve, reject) {
|
|
185
|
+
var timeoutId;
|
|
186
|
+
|
|
187
|
+
// 同步清理timeout
|
|
188
|
+
var wrappedResolve = function wrappedResolve(value) {
|
|
189
|
+
clearTimeout(timeoutId);
|
|
190
|
+
resolve(value);
|
|
191
|
+
};
|
|
192
|
+
var wrappedReject = function wrappedReject(reason) {
|
|
193
|
+
clearTimeout(timeoutId);
|
|
194
|
+
reject(reason);
|
|
195
|
+
};
|
|
196
|
+
var pendingRequest = {
|
|
197
|
+
funcName: funcName,
|
|
198
|
+
parameters: parameters,
|
|
199
|
+
resolve: wrappedResolve,
|
|
200
|
+
reject: wrappedReject
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// 添加到pending队列
|
|
204
|
+
_this2._pendingRequests.push(pendingRequest);
|
|
205
|
+
|
|
206
|
+
// 设定10s超时,超时未ready自动失败并移除
|
|
207
|
+
timeoutId = setTimeout(function () {
|
|
208
|
+
// 找到并移除pendingRequest
|
|
209
|
+
var idx = _this2._pendingRequests.indexOf(pendingRequest);
|
|
210
|
+
if (idx > -1) {
|
|
211
|
+
_this2._pendingRequests.splice(idx, 1);
|
|
212
|
+
}
|
|
213
|
+
reject(new Error('Bridge ready timeout'));
|
|
214
|
+
}, 10000);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
113
217
|
}, {
|
|
114
218
|
key: "getRoomInfo",
|
|
115
|
-
value: function
|
|
116
|
-
|
|
117
|
-
getRoomInfo() {
|
|
118
|
-
return this._sendRequest('getRoomInfo');
|
|
219
|
+
value: function getRoomInfo() {
|
|
220
|
+
return this._ensureBridgeReady('getRoomInfo');
|
|
119
221
|
}
|
|
120
222
|
}, {
|
|
121
223
|
key: "getRoomSchedule",
|
|
122
|
-
value: function
|
|
123
|
-
|
|
124
|
-
getRoomSchedule() {
|
|
125
|
-
return this._sendRequest('getRoomSchedule');
|
|
224
|
+
value: function getRoomSchedule() {
|
|
225
|
+
return this._ensureBridgeReady('getRoomSchedule');
|
|
126
226
|
}
|
|
127
227
|
}, {
|
|
128
228
|
key: "getRoomState",
|
|
129
|
-
value: function
|
|
130
|
-
|
|
131
|
-
getRoomState() {
|
|
132
|
-
return this._sendRequest('getRoomState');
|
|
229
|
+
value: function getRoomState() {
|
|
230
|
+
return this._ensureBridgeReady('getRoomState');
|
|
133
231
|
}
|
|
134
232
|
}, {
|
|
135
233
|
key: "getLocalUser",
|
|
136
|
-
value: function
|
|
137
|
-
|
|
138
|
-
getLocalUser() {
|
|
139
|
-
return this._sendRequest('getLocalUser');
|
|
234
|
+
value: function getLocalUser() {
|
|
235
|
+
return this._ensureBridgeReady('getLocalUser');
|
|
140
236
|
}
|
|
141
237
|
}, {
|
|
142
238
|
key: "getUserList",
|
|
143
|
-
value: function
|
|
144
|
-
|
|
145
|
-
getUserList() {
|
|
146
|
-
return this._sendRequest('getUserList');
|
|
239
|
+
value: function getUserList() {
|
|
240
|
+
return this._ensureBridgeReady('getUserList');
|
|
147
241
|
}
|
|
148
242
|
}, {
|
|
149
243
|
key: "getAllUserCount",
|
|
150
|
-
value: function
|
|
151
|
-
|
|
152
|
-
getAllUserCount() {
|
|
153
|
-
return this._sendRequest('getAllUserCount');
|
|
244
|
+
value: function getAllUserCount() {
|
|
245
|
+
return this._ensureBridgeReady('getAllUserCount');
|
|
154
246
|
}
|
|
155
247
|
}, {
|
|
156
248
|
key: "startSessionByPhone",
|
|
157
249
|
value: function startSessionByPhone(params) {
|
|
158
|
-
return this.
|
|
250
|
+
return this._ensureBridgeReady('startSessionByPhone', [params]);
|
|
159
251
|
}
|
|
160
252
|
}, {
|
|
161
253
|
key: "startSessionByIP",
|
|
162
254
|
value: function startSessionByIP(params) {
|
|
163
|
-
return this.
|
|
255
|
+
return this._ensureBridgeReady('startSessionByIP', [params]);
|
|
164
256
|
}
|
|
165
257
|
}, {
|
|
166
258
|
key: "stopSession",
|
|
167
259
|
value: function stopSession(sessionId) {
|
|
168
|
-
return this.
|
|
260
|
+
return this._ensureBridgeReady('stopSession', [sessionId]);
|
|
261
|
+
}
|
|
262
|
+
}, {
|
|
263
|
+
key: "active",
|
|
264
|
+
value: function active() {
|
|
265
|
+
return this._ensureBridgeReady('active');
|
|
266
|
+
}
|
|
267
|
+
}, {
|
|
268
|
+
key: "inactive",
|
|
269
|
+
value: function inactive() {
|
|
270
|
+
return this._ensureBridgeReady('inactive');
|
|
271
|
+
}
|
|
272
|
+
}, {
|
|
273
|
+
key: "getActivity",
|
|
274
|
+
value: function getActivity() {
|
|
275
|
+
return this._ensureBridgeReady('getActivity');
|
|
169
276
|
}
|
|
170
277
|
}, {
|
|
171
278
|
key: "addObserver",
|
|
172
|
-
value: function
|
|
173
|
-
// @trace
|
|
174
|
-
addObserver(observer) {
|
|
279
|
+
value: function addObserver(observer) {
|
|
175
280
|
this._observable.addObserver(observer);
|
|
176
281
|
}
|
|
177
282
|
}, {
|
|
178
283
|
key: "removeObserver",
|
|
179
|
-
value: function
|
|
180
|
-
// @trace
|
|
181
|
-
removeObserver(observer) {
|
|
284
|
+
value: function removeObserver(observer) {
|
|
182
285
|
this._observable.removeObserver(observer);
|
|
183
286
|
}
|
|
184
287
|
}, {
|
|
185
288
|
key: "_handlePostMessage",
|
|
186
289
|
value: function _handlePostMessage(event) {
|
|
187
290
|
if (event.data) {
|
|
188
|
-
var
|
|
189
|
-
|
|
291
|
+
var _event$data = event.data,
|
|
292
|
+
payload = _event$data.payload,
|
|
293
|
+
type = _event$data.type;
|
|
294
|
+
if (!payload) return;
|
|
295
|
+
var isFcrJSBridge = typeof window.postMessageToFcrJSBridge === 'function' && window.postMessageToFcrJSBridge !== null;
|
|
296
|
+
if (type !== FcrJSBridgeMessageEvent && isFcrJSBridge) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (payload.action === FcrUIWidgetSDKActionEnum.API_RESPONSE) {
|
|
190
300
|
this.logger.debug('handlePostMessage apiResponse: ', event.data);
|
|
191
|
-
var
|
|
192
|
-
callId =
|
|
193
|
-
returnValue =
|
|
301
|
+
var _ref2 = payload,
|
|
302
|
+
callId = _ref2.callId,
|
|
303
|
+
returnValue = _ref2.returnValue,
|
|
304
|
+
error = _ref2.error;
|
|
194
305
|
var controllerPromiseGroup = this._requestPromises.get(callId);
|
|
195
306
|
if (controllerPromiseGroup) {
|
|
196
307
|
this.logger.info('resolve callId', callId);
|
|
197
|
-
var resolve = controllerPromiseGroup.resolve
|
|
198
|
-
|
|
308
|
+
var resolve = controllerPromiseGroup.resolve,
|
|
309
|
+
reject = controllerPromiseGroup.reject;
|
|
310
|
+
if (error) {
|
|
311
|
+
reject && reject(error);
|
|
312
|
+
} else {
|
|
313
|
+
resolve && resolve(returnValue);
|
|
314
|
+
}
|
|
199
315
|
this._requestPromises["delete"](callId);
|
|
200
316
|
}
|
|
201
|
-
} else if (action ===
|
|
317
|
+
} else if (payload.action === FcrUIWidgetSDKActionEnum.CALLBACK) {
|
|
202
318
|
var _this$_observable;
|
|
203
319
|
this.logger.debug('handlePostMessage callback: ', event.data);
|
|
204
|
-
var
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var args = Array.isArray(
|
|
320
|
+
var _payload = payload.payload,
|
|
321
|
+
method = _payload.method,
|
|
322
|
+
parameters = _payload.parameters;
|
|
323
|
+
var args = Array.isArray(parameters) ? parameters : [parameters];
|
|
208
324
|
(_this$_observable = this._observable).notifyObservers.apply(_this$_observable, [method].concat(_toConsumableArray(args)));
|
|
209
325
|
}
|
|
210
326
|
}
|
|
@@ -212,7 +328,6 @@ export var FcrUIWidgetSDKImpl = /*#__PURE__*/function () {
|
|
|
212
328
|
}]);
|
|
213
329
|
}();
|
|
214
330
|
_FcrUIWidgetSDKImpl = FcrUIWidgetSDKImpl;
|
|
215
|
-
var _applyDecs$e = _applyDecs(_FcrUIWidgetSDKImpl, [[bound, 2, "getRoomInfo"], [bound, 2, "getRoomSchedule"], [bound, 2, "getRoomState"], [bound, 2, "getLocalUser"], [bound, 2, "getUserList"], [bound, 2, "getAllUserCount"], [bound, 2, "startSessionByPhone"], [bound, 2, "startSessionByIP"], [bound, 2, "stopSession"], [bound, 2, "addObserver"], [bound, 2, "removeObserver"], [bound, 2, "_handlePostMessage"]], []).e;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
_applyDecs$e;
|
|
331
|
+
var _applyDecs$e = _slicedToArray(_applyDecs(_FcrUIWidgetSDKImpl, [[bound, 2, "getRoomInfo"], [bound, 2, "getRoomSchedule"], [bound, 2, "getRoomState"], [bound, 2, "getLocalUser"], [bound, 2, "getUserList"], [bound, 2, "getAllUserCount"], [bound, 2, "startSessionByPhone"], [bound, 2, "startSessionByIP"], [bound, 2, "stopSession"], [bound, 2, "active"], [bound, 2, "inactive"], [bound, 2, "getActivity"], [bound, 2, "addObserver"], [bound, 2, "removeObserver"], [bound, 2, "_handlePostMessage"]], []).e, 1);
|
|
332
|
+
_initProto = _applyDecs$e[0];
|
|
333
|
+
_defineProperty(FcrUIWidgetSDKImpl, "_globalCounter", 0);
|
package/lib-es/type.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
export {
|
|
1
|
+
// export interface JsBridge {
|
|
2
|
+
// [funcName: string]: (params: Record<string, any>) => void;
|
|
3
|
+
// }
|
|
4
|
+
|
|
5
|
+
export var FcrJSBridgeMessageEvent = 'fcr-js-bridge';
|
|
6
|
+
export var FcrUIWidgetSDKActionEnum = /*#__PURE__*/function (FcrUIWidgetSDKActionEnum) {
|
|
7
|
+
FcrUIWidgetSDKActionEnum["API_REQUEST"] = "apiRequest";
|
|
8
|
+
FcrUIWidgetSDKActionEnum["API_RESPONSE"] = "apiResponse";
|
|
9
|
+
FcrUIWidgetSDKActionEnum["CALLBACK"] = "callback";
|
|
10
|
+
/** 宿主跨域 iframe 无法用 __onFcrJSBridgeReady__ 回调时,通过 postMessage 通知桥接就绪 */
|
|
11
|
+
FcrUIWidgetSDKActionEnum["BRIDGE_READY"] = "bridgeReady";
|
|
12
|
+
return FcrUIWidgetSDKActionEnum;
|
|
13
|
+
}({});
|
package/lib-es/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import "core-js/modules/es.object.to-string.js";
|
|
2
2
|
import "core-js/modules/es.promise.js";
|
|
3
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
4
|
+
import "core-js/modules/es.regexp.test.js";
|
|
3
5
|
export var createControlledPromise = function createControlledPromise() {
|
|
4
6
|
var resolve = function resolve() {};
|
|
5
7
|
var reject = function reject() {};
|
|
@@ -12,4 +14,9 @@ export var createControlledPromise = function createControlledPromise() {
|
|
|
12
14
|
resolve: resolve,
|
|
13
15
|
reject: reject
|
|
14
16
|
};
|
|
17
|
+
};
|
|
18
|
+
export var isNativePlatform = function isNativePlatform() {
|
|
19
|
+
var ua = navigator.userAgent.toLowerCase();
|
|
20
|
+
var hasWebViewUA = /wv|webview/.test(ua) || /; wv\)/.test(ua);
|
|
21
|
+
return hasWebViewUA;
|
|
15
22
|
};
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "fcr-ui-widget-sdk",
|
|
3
|
-
"version": "3.10.
|
|
4
|
-
"main": "lib/index.js",
|
|
5
|
-
"types": "lib/index.d.ts",
|
|
6
|
-
"repository": "ssh://git@git.agoralab.co/aduc/fcr-ui-scene-desktop.git",
|
|
7
|
-
"author": "agora.io",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"files": [
|
|
10
|
-
"lib",
|
|
11
|
-
"lib-es"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "agora-tc-transpile --esm",
|
|
15
|
-
"build-widget": "node scripts/build-widget.js",
|
|
16
|
-
"test": "agora-tc-test-karma-browser"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"agora-foundation": "3.10.
|
|
20
|
-
"fcr-core": "3.10.
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@babel/core": "^7.23.5",
|
|
24
|
-
"@babel/preset-env": "^7.23.5",
|
|
25
|
-
"@babel/preset-react": "^7.24.1",
|
|
26
|
-
"@babel/preset-typescript": "^7.23.3",
|
|
27
|
-
"agora-toolchain": "3.10.
|
|
28
|
-
"tslib": "^2.6.2"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "fcr-ui-widget-sdk",
|
|
3
|
+
"version": "3.10.1",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"types": "lib/index.d.ts",
|
|
6
|
+
"repository": "ssh://git@git.agoralab.co/aduc/fcr-ui-scene-desktop.git",
|
|
7
|
+
"author": "agora.io",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"lib",
|
|
11
|
+
"lib-es"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "agora-tc-transpile --esm",
|
|
15
|
+
"build-widget": "node scripts/build-widget.js",
|
|
16
|
+
"test": "agora-tc-test-karma-browser"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"agora-foundation": "3.10.1",
|
|
20
|
+
"fcr-core": "3.10.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/core": "^7.23.5",
|
|
24
|
+
"@babel/preset-env": "^7.23.5",
|
|
25
|
+
"@babel/preset-react": "^7.24.1",
|
|
26
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
27
|
+
"agora-toolchain": "3.10.1",
|
|
28
|
+
"tslib": "^2.6.2"
|
|
29
|
+
}
|
|
30
|
+
}
|