fcr-core 3.8.1 → 3.9.0-alpha

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.
Files changed (199) hide show
  1. package/lib/chat-connector/type.d.ts +40 -0
  2. package/lib/{chat-connection → chat-connector}/type.js +1 -1
  3. package/lib/engine/index.d.ts +10 -11
  4. package/lib/engine/index.js +63 -72
  5. package/lib/engine/type.d.ts +96 -0
  6. package/lib/engine/type.js +5 -0
  7. package/lib/imports.d.ts +7 -4
  8. package/lib/imports.js +30 -4
  9. package/lib/index.d.ts +3 -2
  10. package/lib/index.js +21 -2
  11. package/lib/media-control/desktop.js +12 -12
  12. package/lib/media-control/mobile.js +4 -0
  13. package/lib/media-control/type.d.ts +32 -33
  14. package/lib/monitor-control/index.js +3 -3
  15. package/lib/peer-session/index.js +14 -14
  16. package/lib/peer-session/type.d.ts +1 -1
  17. package/lib/plugins/chat/chatroom.js +417 -0
  18. package/lib/{chat-connection → plugins/chat}/config.d.ts +1 -0
  19. package/lib/{room-control/chatroom-control → plugins/chat}/config.js +2 -1
  20. package/lib/plugins/chat/connector.d.ts +38 -0
  21. package/lib/{chat-connection/index.js → plugins/chat/connector.js} +181 -61
  22. package/lib/room-control/ability-control/index.js +5 -4
  23. package/lib/room-control/ability-control/type.d.ts +5 -1
  24. package/lib/room-control/ability-control/type.js +4 -0
  25. package/lib/room-control/chatroom-control/type.d.ts +44 -35
  26. package/lib/room-control/group-control/index.js +9 -9
  27. package/lib/room-control/index.js +37 -22
  28. package/lib/room-control/interpreter-control/index.js +7 -4
  29. package/lib/room-control/interpreter-control/room.js +3 -3
  30. package/lib/room-control/interpreter-control/types.d.ts +2 -2
  31. package/lib/room-control/join-before-host-waitingroom-control/index.js +3 -3
  32. package/lib/room-control/mainroom-control/index.js +15 -13
  33. package/lib/room-control/privilege-control/index.js +39 -24
  34. package/lib/room-control/privilege-control/type.d.ts +15 -15
  35. package/lib/room-control/room-connector-control/index.js +7 -5
  36. package/lib/room-control/room-connector-control/type.d.ts +1 -1
  37. package/lib/room-control/room-control-factory.d.ts +3 -3
  38. package/lib/room-control/room-control-factory.js +7 -7
  39. package/lib/room-control/room-session/index.js +17 -15
  40. package/lib/room-control/room-session/type.d.ts +3 -3
  41. package/lib/room-control/sharing-control/index.js +13 -7
  42. package/lib/room-control/stream-control/index.js +18 -16
  43. package/lib/room-control/stream-control/type.d.ts +5 -5
  44. package/lib/room-control/stt-control/index.js +38 -31
  45. package/lib/room-control/type.d.ts +19 -19
  46. package/lib/room-control/user-control/index.js +20 -22
  47. package/lib/room-control/user-control/type.d.ts +1 -1
  48. package/lib/room-control/waitingroom-control/index.js +11 -11
  49. package/lib/room-control/whiteboard-control-v1/board-window.d.ts +21 -20
  50. package/lib/room-control/whiteboard-control-v1/board-window.js +27 -8
  51. package/lib/room-control/whiteboard-control-v1/factory.js +1 -1
  52. package/lib/room-control/whiteboard-control-v1/index.js +26 -18
  53. package/lib/room-control/whiteboard-control-v1/type.d.ts +26 -25
  54. package/lib/room-control/whiteboard-control-v1/type.js +1 -0
  55. package/lib/room-control/whiteboard-control-v2/annotation-control/control.d.ts +15 -6
  56. package/lib/room-control/whiteboard-control-v2/annotation-control/control.js +39 -5
  57. package/lib/room-control/whiteboard-control-v2/annotation-control/factory.d.ts +4 -5
  58. package/lib/room-control/whiteboard-control-v2/annotation-control/factory.js +6 -5
  59. package/lib/room-control/whiteboard-control-v2/annotation-control/type.d.ts +7 -1
  60. package/lib/room-control/whiteboard-control-v2/base/index.d.ts +9 -8
  61. package/lib/room-control/whiteboard-control-v2/base/index.js +84 -42
  62. package/lib/room-control/whiteboard-control-v2/base/main-window.d.ts +16 -15
  63. package/lib/room-control/whiteboard-control-v2/base/main-window.js +23 -4
  64. package/lib/room-control/whiteboard-control-v2/type.d.ts +17 -17
  65. package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.d.ts +12 -6
  66. package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.js +64 -18
  67. package/lib/room-control/whiteboard-control-v2/whiteboard-control/factory.d.ts +2 -2
  68. package/lib/room-control/whiteboard-control-v2/whiteboard-control/factory.js +10 -10
  69. package/lib/room-control/whiteboard-control-v2/whiteboard-control/type.d.ts +1 -1
  70. package/lib/room-router/index.js +10 -7
  71. package/lib/room-router/type.d.ts +1 -1
  72. package/lib/schema.d.ts +24 -46
  73. package/lib/schema.js +1 -2
  74. package/lib/service/api.d.ts +5 -3
  75. package/lib/service/api.js +17 -12
  76. package/lib/type.d.ts +64 -45
  77. package/lib/type.js +76 -11
  78. package/lib/utilities/abortable-retry.d.ts +38 -0
  79. package/lib/utilities/abortable-retry.js +61 -0
  80. package/lib/utilities/dual-video-stream-config.d.ts +6 -0
  81. package/lib/utilities/dual-video-stream-config.js +25 -0
  82. package/lib/utilities/error-helpers.d.ts +10 -9
  83. package/lib/utilities/error-helpers.js +12 -11
  84. package/lib/utilities/error.d.ts +4 -40
  85. package/lib/utilities/error.js +20 -77
  86. package/lib/utilities/join-helper.js +2 -2
  87. package/lib/utilities/logger.d.ts +2 -2
  88. package/lib/utilities/logger.js +6 -25
  89. package/lib/utilities/package-info.d.ts +1 -2
  90. package/lib/utilities/package-info.js +4 -8
  91. package/lib/utilities/parameters.js +88 -15
  92. package/lib/utilities/validate-params.js +1 -1
  93. package/lib/utilities/video-encoder-config.d.ts +9 -0
  94. package/lib/utilities/video-encoder-config.js +109 -0
  95. package/lib-es/base-session.js +1 -0
  96. package/lib-es/chat-connector/type.js +6 -0
  97. package/lib-es/engine/index.js +412 -0
  98. package/lib-es/engine/type.js +1 -0
  99. package/lib-es/imports.js +59 -0
  100. package/lib-es/index.js +8 -0
  101. package/lib-es/media-control/desktop.js +172 -0
  102. package/lib-es/media-control/mobile.js +198 -0
  103. package/lib-es/media-control/type.js +6 -0
  104. package/lib-es/monitor-control/index.js +46 -0
  105. package/lib-es/monitor-control/type.js +1 -0
  106. package/lib-es/peer-session/index.js +279 -0
  107. package/lib-es/peer-session/type.js +1 -0
  108. package/lib-es/plugins/chat/chatroom.js +409 -0
  109. package/{lib/chat-connection → lib-es/plugins/chat}/config.js +5 -9
  110. package/lib-es/plugins/chat/connector.js +269 -0
  111. package/lib-es/plugins/electron-rtc-plugin.js +1 -0
  112. package/lib-es/plugins/rtm-plugin.js +1 -0
  113. package/lib-es/plugins/web-rtc-plugin.js +1 -0
  114. package/lib-es/room-control/ability-control/index.js +58 -0
  115. package/lib-es/room-control/ability-control/type.js +15 -0
  116. package/lib-es/room-control/chatroom-control/type.js +12 -0
  117. package/lib-es/room-control/group-control/index.js +256 -0
  118. package/lib-es/room-control/helpers/constants.js +92 -0
  119. package/lib-es/room-control/helpers/index.js +20 -0
  120. package/lib-es/room-control/helpers/validation-helper.js +46 -0
  121. package/lib-es/room-control/index.js +623 -0
  122. package/lib-es/room-control/interpreter-control/index.js +172 -0
  123. package/lib-es/room-control/interpreter-control/room.js +28 -0
  124. package/lib-es/room-control/interpreter-control/types.js +26 -0
  125. package/lib-es/room-control/join-before-host-waitingroom-control/index.js +29 -0
  126. package/lib-es/room-control/mainroom-control/index.js +248 -0
  127. package/lib-es/room-control/privilege-control/helper.js +97 -0
  128. package/lib-es/room-control/privilege-control/index.js +339 -0
  129. package/lib-es/room-control/privilege-control/type.js +159 -0
  130. package/lib-es/room-control/room-connector-control/index.js +182 -0
  131. package/lib-es/room-control/room-connector-control/type.js +28 -0
  132. package/lib-es/room-control/room-control-factory.js +77 -0
  133. package/lib-es/room-control/room-session/index.js +292 -0
  134. package/lib-es/room-control/room-session/type.js +1 -0
  135. package/lib-es/room-control/shared-cache.js +47 -0
  136. package/lib-es/room-control/sharing-control/index.js +307 -0
  137. package/lib-es/room-control/sharing-control/type.js +16 -0
  138. package/lib-es/room-control/stream-control/index.js +536 -0
  139. package/lib-es/room-control/stream-control/type.js +1 -0
  140. package/lib-es/room-control/stt-control/de-compress-gzip.js +33 -0
  141. package/lib-es/room-control/stt-control/index.js +350 -0
  142. package/lib-es/room-control/stt-control/type.js +10 -0
  143. package/lib-es/room-control/type.js +30 -0
  144. package/lib-es/room-control/user-control/index.js +344 -0
  145. package/lib-es/room-control/user-control/type.js +21 -0
  146. package/lib-es/room-control/waitingroom-control/index.js +68 -0
  147. package/lib-es/room-control/whiteboard-control/enum.js +18 -0
  148. package/lib-es/room-control/whiteboard-control/type.js +10 -0
  149. package/lib-es/room-control/whiteboard-control/utils.js +13 -0
  150. package/lib-es/room-control/whiteboard-control-v1/board-subwindow.js +18 -0
  151. package/lib-es/room-control/whiteboard-control-v1/board-window.js +573 -0
  152. package/lib-es/room-control/whiteboard-control-v1/enum.js +157 -0
  153. package/lib-es/room-control/whiteboard-control-v1/factory.js +12 -0
  154. package/lib-es/room-control/whiteboard-control-v1/index.js +427 -0
  155. package/lib-es/room-control/whiteboard-control-v1/mount-manager.js +6 -0
  156. package/lib-es/room-control/whiteboard-control-v1/type.js +8 -0
  157. package/lib-es/room-control/whiteboard-control-v1/utils.js +273 -0
  158. package/lib-es/room-control/whiteboard-control-v2/annotation-control/control.js +76 -0
  159. package/lib-es/room-control/whiteboard-control-v2/annotation-control/factory.js +37 -0
  160. package/lib-es/room-control/whiteboard-control-v2/annotation-control/type.js +1 -0
  161. package/lib-es/room-control/whiteboard-control-v2/base/index.js +347 -0
  162. package/lib-es/room-control/whiteboard-control-v2/base/main-window.js +269 -0
  163. package/lib-es/room-control/whiteboard-control-v2/constant.js +9 -0
  164. package/lib-es/room-control/whiteboard-control-v2/enum.js +28 -0
  165. package/lib-es/room-control/whiteboard-control-v2/type.js +1 -0
  166. package/lib-es/room-control/whiteboard-control-v2/utils.js +92 -0
  167. package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/control.js +204 -0
  168. package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/factory.js +61 -0
  169. package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/type.js +1 -0
  170. package/lib-es/room-router/index.js +263 -0
  171. package/lib-es/room-router/type.js +5 -0
  172. package/lib-es/schema.js +231 -0
  173. package/lib-es/service/api.js +1211 -0
  174. package/lib-es/service/type.js +1 -0
  175. package/lib-es/type.js +222 -0
  176. package/lib-es/utilities/abortable-retry.js +54 -0
  177. package/lib-es/utilities/cmd.js +1 -0
  178. package/lib-es/utilities/collection.js +64 -0
  179. package/lib-es/utilities/dual-video-stream-config.js +19 -0
  180. package/lib-es/utilities/error-helpers.js +224 -0
  181. package/lib-es/utilities/error.js +43 -0
  182. package/lib-es/utilities/join-helper.js +219 -0
  183. package/lib-es/utilities/logger.js +7 -0
  184. package/lib-es/utilities/package-info.js +5 -0
  185. package/lib-es/utilities/parameters.js +106 -0
  186. package/lib-es/utilities/retry-helpers.js +66 -0
  187. package/lib-es/utilities/shared-storage.js +31 -0
  188. package/lib-es/utilities/stream.js +18 -0
  189. package/lib-es/utilities/user.js +30 -0
  190. package/lib-es/utilities/validate-params.js +8 -0
  191. package/lib-es/utilities/video-encoder-config.js +103 -0
  192. package/package.json +11 -10
  193. package/lib/chat-connection/index.d.ts +0 -24
  194. package/lib/chat-connection/type.d.ts +0 -17
  195. package/lib/plugins/chatroom.js +0 -454
  196. package/lib/room-control/chatroom-control/config.d.ts +0 -51
  197. package/lib/utilities/storage.d.ts +0 -8
  198. package/lib/utilities/storage.js +0 -33
  199. /package/lib/plugins/{chatroom.d.ts → chat/chatroom.d.ts} +0 -0
@@ -0,0 +1,269 @@
1
+ import "core-js/modules/es.array.push.js";
2
+ import "core-js/modules/esnext.function.metadata.js";
3
+ import "core-js/modules/esnext.map.delete-all.js";
4
+ import "core-js/modules/esnext.map.emplace.js";
5
+ import "core-js/modules/esnext.map.every.js";
6
+ import "core-js/modules/esnext.map.filter.js";
7
+ import "core-js/modules/esnext.map.find.js";
8
+ import "core-js/modules/esnext.map.find-key.js";
9
+ import "core-js/modules/esnext.map.includes.js";
10
+ import "core-js/modules/esnext.map.key-of.js";
11
+ import "core-js/modules/esnext.map.map-keys.js";
12
+ import "core-js/modules/esnext.map.map-values.js";
13
+ import "core-js/modules/esnext.map.merge.js";
14
+ import "core-js/modules/esnext.map.reduce.js";
15
+ import "core-js/modules/esnext.map.some.js";
16
+ import "core-js/modules/esnext.map.update.js";
17
+ import "core-js/modules/esnext.symbol.metadata.js";
18
+ let _initProto;
19
+ import "core-js/modules/es.json.stringify.js";
20
+ 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 (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 (e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function (e) { return e[n]; }, (o < 2 || 4 === o) && (F = function (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 (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)]; } }; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
22
+ 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); }
23
+ 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; }
24
+ 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; }
25
+ import { AgoraObservable, AgoraScheduler, EasemobChatSDK, trace } from '../../imports';
26
+ import { FcrReturnCode } from '../../type';
27
+ import { abortableRetry } from '../../utilities/abortable-retry';
28
+ import { createLogger, generateLogObserver } from '../../utilities/logger';
29
+ import { getDependenciesInfo } from '../../utilities/package-info';
30
+ import { agoraChatConfig } from './config';
31
+ import { FcrChatConnectionState } from '../../chat-connector/type';
32
+ export class FcrChatConnectorImpl {
33
+ static {
34
+ [_initProto] = _applyDecs(this, [[trace, 2, "login"], [trace, 2, "logout"]], []).e;
35
+ }
36
+ logger = (_initProto(this), createLogger({
37
+ prefix: 'FcrChatConnectorImpl'
38
+ }));
39
+ _observable = new AgoraObservable();
40
+ _loginPromise = null;
41
+ _logoutPromise = null;
42
+ _isLogoutRequested = false;
43
+ _abortLogin = null;
44
+ _conn = null;
45
+ _connectionState = FcrChatConnectionState.DISCONNECTED;
46
+ _reconnectionTimer = null;
47
+ _reconnectPromise = null;
48
+ constructor(_userId, _api, _chatIpList, _restIpList) {
49
+ this._userId = _userId;
50
+ this._api = _api;
51
+ this._chatIpList = _chatIpList;
52
+ this._restIpList = _restIpList;
53
+ this.logger.info(`Chat Version: easemob-websdk@${getDependenciesInfo('easemob-websdk')}`);
54
+ this._addLogObserver();
55
+ }
56
+ async login() {
57
+ if (this._logoutPromise) {
58
+ await this._logoutPromise;
59
+ }
60
+ if (this._connectionState === FcrChatConnectionState.CONNECTED) {
61
+ return;
62
+ }
63
+ if (this._loginPromise) {
64
+ return this._loginPromise;
65
+ }
66
+ this._isLogoutRequested = false;
67
+ this._setConnectionState(FcrChatConnectionState.CONNECTING);
68
+ this._loginPromise = this._performLogin();
69
+ try {
70
+ await this._loginPromise;
71
+ } finally {
72
+ this._loginPromise = null;
73
+ }
74
+ }
75
+ logout() {
76
+ if (this._logoutPromise) {
77
+ return FcrReturnCode.SUCCESS;
78
+ }
79
+ this._isLogoutRequested = true;
80
+ this._logoutPromise = this._performLogout();
81
+ return FcrReturnCode.SUCCESS;
82
+ }
83
+ getConnectionState() {
84
+ return this._connectionState;
85
+ }
86
+ getConnectionInstance() {
87
+ return this._conn;
88
+ }
89
+ addObserver(observer) {
90
+ this._observable.addObserver(observer);
91
+ }
92
+ removeObserver(observer) {
93
+ this._observable.removeObserver(observer);
94
+ }
95
+ async _performLogin() {
96
+ const privateConfig = this._getPrivateConfig();
97
+ if (privateConfig) {
98
+ this.logger.info('use private config:', JSON.stringify(privateConfig));
99
+ }
100
+ const [abort, promise] = abortableRetry(async signal => {
101
+ const tokenResult = await this._api.getUserToken(this._userId);
102
+ signal.throwIfAborted();
103
+ this._initConfig = tokenResult;
104
+ const appKey = tokenResult.appKey;
105
+ const connParams = {
106
+ ...agoraChatConfig,
107
+ ...privateConfig,
108
+ appKey
109
+ };
110
+ EasemobChatSDK.logger.setConsoleLogVisibility(false);
111
+ this._conn = new EasemobChatSDK.connection(connParams);
112
+ this._addEventListeners(this._conn);
113
+ await this._conn.open({
114
+ accessToken: this._initConfig.token,
115
+ user: this._userId
116
+ });
117
+ this.logger.info(`login success, token: ${this._initConfig.token}, userId: ${this._userId}`);
118
+ }, {
119
+ retriesMax: Infinity
120
+ });
121
+ this._abortLogin = abort;
122
+ const [error] = await promise;
123
+ this._abortLogin = null;
124
+ if (error) {
125
+ await this._closeConnection();
126
+ if (error.name === 'AbortError' && this._isLogoutRequested) {
127
+ return;
128
+ }
129
+ throw error;
130
+ }
131
+ if (this._isLogoutRequested) {
132
+ await this._closeConnection();
133
+ }
134
+ }
135
+ _addEventListeners(conn) {
136
+ conn.addEventHandler('connectionListener', {
137
+ onError: e => {
138
+ this.logger.error('onError', e.message);
139
+ },
140
+ onConnected: () => {
141
+ this.logger.info('onConnected');
142
+ this._handleConnected();
143
+ },
144
+ onOnline: () => {
145
+ this.logger.info('onOnline');
146
+ this._handleConnected();
147
+ },
148
+ onOffline: () => {
149
+ this.logger.info('onOffline');
150
+ this._handleDisconnected();
151
+ },
152
+ onDisconnected: () => {
153
+ this.logger.info('onDisconnected');
154
+ this._handleDisconnected();
155
+ }
156
+ });
157
+ }
158
+ async _performLogout() {
159
+ try {
160
+ if (this._reconnectionTimer) {
161
+ clearTimeout(this._reconnectionTimer);
162
+ this._reconnectionTimer = null;
163
+ }
164
+ if (this._abortLogin) {
165
+ this._abortLogin();
166
+ this._abortLogin = null;
167
+ }
168
+ await this._waitForLoginComplete();
169
+ await this._closeConnection();
170
+ } catch (error) {
171
+ this.logger.error('logout error', error.message);
172
+ } finally {
173
+ this._logoutPromise = null;
174
+ this._isLogoutRequested = false;
175
+ }
176
+ }
177
+ async _waitForLoginComplete() {
178
+ if (!this._loginPromise) {
179
+ return;
180
+ }
181
+ try {
182
+ await this._loginPromise;
183
+ } catch (error) {
184
+ this.logger.error('login error during logout', error.message);
185
+ }
186
+ }
187
+ async _closeConnection() {
188
+ const conn = this._conn;
189
+ this._conn = null;
190
+ if (conn) {
191
+ try {
192
+ conn.removeEventHandler('connectionListener');
193
+ await Promise.resolve(conn.close?.());
194
+ } catch (error) {
195
+ this.logger.error('close connection error', error.message);
196
+ }
197
+ }
198
+ this._setConnectionState(FcrChatConnectionState.DISCONNECTED);
199
+ }
200
+ _setConnectionState(state) {
201
+ if (this._connectionState === state) {
202
+ return;
203
+ }
204
+ this._connectionState = state;
205
+ this._observable.notifyObservers('onConnectionStateUpdated', state);
206
+ }
207
+ _getPrivateConfig() {
208
+ if (this._chatIpList?.length || this._restIpList?.length) {
209
+ const privateConfig = {
210
+ isHttpDNS: false
211
+ };
212
+ if (this._chatIpList?.length) {
213
+ privateConfig.url = this._chatIpList[0];
214
+ }
215
+ if (this._restIpList?.length) {
216
+ privateConfig.apiUrl = this._restIpList[0];
217
+ }
218
+ return privateConfig;
219
+ }
220
+ }
221
+ _handleConnected() {
222
+ if (this._isLogoutRequested) {
223
+ return;
224
+ }
225
+ if (this._connectionState !== FcrChatConnectionState.CONNECTED) {
226
+ this._setConnectionState(FcrChatConnectionState.CONNECTED);
227
+ } else {
228
+ // notify again in case of reconnection
229
+ this._observable.notifyObservers('onConnectionStateUpdated', FcrChatConnectionState.CONNECTED);
230
+ }
231
+ }
232
+ _handleDisconnected() {
233
+ if (this._connectionState !== FcrChatConnectionState.DISCONNECTED) {
234
+ this._setConnectionState(FcrChatConnectionState.DISCONNECTED);
235
+ }
236
+ if (this._isLogoutRequested) {
237
+ return;
238
+ }
239
+ this._reconnect();
240
+ }
241
+ async _reconnect() {
242
+ if (this._loginPromise || this._reconnectPromise) {
243
+ return;
244
+ }
245
+ const doReconnect = async () => {
246
+ await this._closeConnection();
247
+
248
+ // add a short delay to avoid tight reconnect loops
249
+ await new Promise(resolve => {
250
+ this._reconnectionTimer = setTimeout(resolve, AgoraScheduler.Duration.second(1));
251
+ });
252
+ this._reconnectionTimer = null;
253
+ if (this._isLogoutRequested) {
254
+ return;
255
+ }
256
+ try {
257
+ await this.login();
258
+ } catch (error) {
259
+ this.logger.error('reconnect error', error.message);
260
+ }
261
+ };
262
+ this._reconnectPromise = doReconnect().finally(() => {
263
+ this._reconnectPromise = null;
264
+ });
265
+ }
266
+ _addLogObserver() {
267
+ this.addObserver(generateLogObserver(this.logger, [['onConnectionStateUpdated', ['state']]]));
268
+ }
269
+ }
@@ -0,0 +1 @@
1
+ export { default as ElectronRtcPlugin } from 'agora-rte-sdk/lib/plugin/rtc/electron';
@@ -0,0 +1 @@
1
+ export { default as RtmPlugin } from 'agora-rte-sdk/lib/plugin/rtm';
@@ -0,0 +1 @@
1
+ export { default as WebRtcPlugin } from 'agora-rte-sdk/lib/plugin/rtc/web';
@@ -0,0 +1,58 @@
1
+ import "core-js/modules/es.array.push.js";
2
+ import "core-js/modules/esnext.function.metadata.js";
3
+ import "core-js/modules/esnext.map.delete-all.js";
4
+ import "core-js/modules/esnext.map.emplace.js";
5
+ import "core-js/modules/esnext.map.every.js";
6
+ import "core-js/modules/esnext.map.filter.js";
7
+ import "core-js/modules/esnext.map.find.js";
8
+ import "core-js/modules/esnext.map.find-key.js";
9
+ import "core-js/modules/esnext.map.includes.js";
10
+ import "core-js/modules/esnext.map.key-of.js";
11
+ import "core-js/modules/esnext.map.map-keys.js";
12
+ import "core-js/modules/esnext.map.map-values.js";
13
+ import "core-js/modules/esnext.map.merge.js";
14
+ import "core-js/modules/esnext.map.reduce.js";
15
+ import "core-js/modules/esnext.map.some.js";
16
+ import "core-js/modules/esnext.map.update.js";
17
+ import "core-js/modules/esnext.symbol.metadata.js";
18
+ let _initProto, _isPlatformAbilitySupportedDecs;
19
+ 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 (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 (e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function (e) { return e[n]; }, (o < 2 || 4 === o) && (F = function (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 (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)]; } }; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
21
+ 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); }
22
+ 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; }
23
+ 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; }
24
+ import { getPlatform, trace } from '../../imports';
25
+ import { FcrPlatform } from '../../type';
26
+ import { createLogger } from '../../utilities/logger';
27
+ /**
28
+ * 平台能力控制的实现类
29
+ * @internal
30
+ */
31
+ export class FcrAbilityControlImpl {
32
+ static {
33
+ [_initProto] = _applyDecs(this, [[_isPlatformAbilitySupportedDecs, 2, "isPlatformAbilitySupported"]], []).e;
34
+ }
35
+ //@internal
36
+ [(_isPlatformAbilitySupportedDecs = trace(['platform', 'ability']), "logger")] = (_initProto(this), createLogger({
37
+ prefix: 'FcrAbilityControlImpl'
38
+ }));
39
+ constructor(_scene) {
40
+ this._scene = _scene;
41
+ }
42
+ getPlatformAbility(ability) {
43
+ const platforms = this._scene.getScenePropertiesByKeyPath(`setting.ability.${ability}`);
44
+ if (!Array.isArray(platforms)) {
45
+ return [FcrPlatform.WEB_DESKTOP, FcrPlatform.MACOS, FcrPlatform.WINDOWS, FcrPlatform.IOS, FcrPlatform.ANDROID, FcrPlatform.WEB_MOBILE, FcrPlatform.HARMONY, FcrPlatform.CONNECTOR_PSTN, FcrPlatform.CONNECTOR_SIP, FcrPlatform.CONNECTOR_H323];
46
+ }
47
+ return platforms;
48
+ }
49
+ isAbilitySupported(ability) {
50
+ const platforms = this.getPlatformAbility(ability);
51
+ const currentPlatform = getPlatform();
52
+ return platforms.includes(currentPlatform);
53
+ }
54
+ isPlatformAbilitySupported(platform, ability) {
55
+ const platforms = this.getPlatformAbility(ability);
56
+ return platforms.includes(platform);
57
+ }
58
+ }
@@ -0,0 +1,15 @@
1
+ export let FcrAbility = /*#__PURE__*/function (FcrAbility) {
2
+ FcrAbility["RoleHost"] = "role:host";
3
+ FcrAbility["RoomDetail"] = "room:detail";
4
+ FcrAbility["Live"] = "live";
5
+ FcrAbility["Interpreter"] = "interpreter";
6
+ FcrAbility["Annotation"] = "annotation";
7
+ FcrAbility["Caption"] = "caption";
8
+ FcrAbility["Transcribe"] = "transcribe";
9
+ FcrAbility["Recording"] = "recording";
10
+ FcrAbility["Board"] = "board";
11
+ FcrAbility["SettingVirtualBackground"] = "setting:virtualBackground";
12
+ FcrAbility["SettingBeautyMode"] = "setting:beautyMode";
13
+ FcrAbility["PstnCallOut"] = "pstn:callOut";
14
+ return FcrAbility;
15
+ }({});
@@ -0,0 +1,12 @@
1
+ export let FcrChatRoomConnectionState = /*#__PURE__*/function (FcrChatRoomConnectionState) {
2
+ FcrChatRoomConnectionState[FcrChatRoomConnectionState["Disconnected"] = 0] = "Disconnected";
3
+ FcrChatRoomConnectionState[FcrChatRoomConnectionState["Connecting"] = 1] = "Connecting";
4
+ FcrChatRoomConnectionState[FcrChatRoomConnectionState["Connected"] = 2] = "Connected";
5
+ return FcrChatRoomConnectionState;
6
+ }({});
7
+ export let FcrChatRoomMessageType = /*#__PURE__*/function (FcrChatRoomMessageType) {
8
+ FcrChatRoomMessageType["Text"] = "text";
9
+ FcrChatRoomMessageType["Image"] = "image";
10
+ FcrChatRoomMessageType["Custom"] = "custom";
11
+ return FcrChatRoomMessageType;
12
+ }({});
@@ -0,0 +1,256 @@
1
+ import "core-js/modules/esnext.function.metadata.js";
2
+ import "core-js/modules/esnext.symbol.metadata.js";
3
+ let _initProto, _getGroupUserListDecs, _addGroupsDecs, _updateGroupsDecs, _deleteGroupsDecs, _addUsersDecs, _removeUsersDecs, _moveUsersDecs;
4
+ import "core-js/modules/es.array.push.js";
5
+ import "core-js/modules/esnext.iterator.constructor.js";
6
+ import "core-js/modules/esnext.iterator.for-each.js";
7
+ import "core-js/modules/esnext.iterator.map.js";
8
+ import "core-js/modules/esnext.map.delete-all.js";
9
+ import "core-js/modules/esnext.map.emplace.js";
10
+ import "core-js/modules/esnext.map.every.js";
11
+ import "core-js/modules/esnext.map.filter.js";
12
+ import "core-js/modules/esnext.map.find.js";
13
+ import "core-js/modules/esnext.map.find-key.js";
14
+ import "core-js/modules/esnext.map.includes.js";
15
+ import "core-js/modules/esnext.map.key-of.js";
16
+ import "core-js/modules/esnext.map.map-keys.js";
17
+ import "core-js/modules/esnext.map.map-values.js";
18
+ import "core-js/modules/esnext.map.merge.js";
19
+ import "core-js/modules/esnext.map.reduce.js";
20
+ import "core-js/modules/esnext.map.some.js";
21
+ import "core-js/modules/esnext.map.update.js";
22
+ 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 (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 (e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function (e) { return e[n]; }, (o < 2 || 4 === o) && (F = function (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 (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)]; } }; }
23
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
24
+ 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); }
25
+ 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; }
26
+ 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; }
27
+ import { trace } from '../../imports';
28
+ import { AgoraObservable } from '../../imports';
29
+ import { convertRteUserToFcrUser } from '../../utilities/user';
30
+ import { createLogger, generateLogObserver } from '../../utilities/logger';
31
+ import { handleRequestError } from '../../utilities/error';
32
+ import validateParams from '../../utilities/validate-params';
33
+ import { fcrGroupUpdateOptionsArraySchema, fcrGroupCreateConfigArraySchema, stringArraySchema, stringSchema } from '../../schema';
34
+ import { ErrorModuleCode } from '../../imports';
35
+ export class FcrGroupControl {
36
+ static {
37
+ [_initProto] = _applyDecs(this, [[trace, 2, "getGroupList"], [_getGroupUserListDecs, 2, "getGroupUserList"], [_addGroupsDecs, 2, "addGroups"], [_updateGroupsDecs, 2, "updateGroups"], [_deleteGroupsDecs, 2, "deleteGroups"], [trace, 2, "deleteAllGroups"], [_addUsersDecs, 2, "addUsers"], [_removeUsersDecs, 2, "removeUsers"], [_moveUsersDecs, 2, "moveUsers"]], []).e;
38
+ }
39
+ //@internal
40
+ [(_getGroupUserListDecs = [trace(['groupId']), validateParams(stringSchema)], _addGroupsDecs = [trace(['groups']), validateParams(fcrGroupCreateConfigArraySchema)], _updateGroupsDecs = [trace(['groups']), validateParams(fcrGroupUpdateOptionsArraySchema)], _deleteGroupsDecs = [trace(['groupIds']), validateParams(stringArraySchema)], _addUsersDecs = [trace(['userList', 'groupId']), validateParams(stringArraySchema, stringSchema)], _removeUsersDecs = [trace(['userList', 'groupId']), validateParams(stringArraySchema, stringSchema)], _moveUsersDecs = [trace(['userList', 'fromGroupId', 'toGroupId']), validateParams(stringArraySchema, stringSchema, stringSchema)], "logger")] = (_initProto(this), createLogger({
41
+ prefix: 'FcrGroupControl'
42
+ }));
43
+ //@internal
44
+
45
+ _observable = new AgoraObservable();
46
+ constructor(_engine, _scene, _api, _sharedCache) {
47
+ this._engine = _engine;
48
+ this._scene = _scene;
49
+ this._api = _api;
50
+ this._sharedCache = _sharedCache;
51
+ this._roomCache = _sharedCache.getRoomCache(this._scene.sceneId);
52
+ this._addLogObserver();
53
+ this._addSceneObserver();
54
+ }
55
+ _addSceneObserver() {
56
+ const observer = {
57
+ onScenePropertiesUpdated: (sceneId, event) => {
58
+ if (event.cause?.cmd === 11) {
59
+ const data = event.cause.data;
60
+ const changedProperties = event.changedProperties;
61
+ const groupDetails = changedProperties.groups.details;
62
+ const groupEvents = Object.keys(groupDetails).map(groupId => {
63
+ let operatorUser;
64
+ if (event.operatorUser) {
65
+ operatorUser = convertRteUserToFcrUser(event.operatorUser, this._roomCache);
66
+ }
67
+ return {
68
+ info: {
69
+ groupId,
70
+ groupName: groupDetails[groupId].groupName
71
+ },
72
+ operatorUser
73
+ };
74
+ });
75
+ if (data.actionType === 2) {
76
+ if (data.removeGroupUuids) {
77
+ this._observable.notifyObservers('onGroupsRemoved', groupEvents);
78
+ } else {
79
+ this._observable.notifyObservers('onGroupsAdded', groupEvents);
80
+ }
81
+ }
82
+ if (data.actionType === 3) {
83
+ this._observable.notifyObservers('onGroupsUpdated', groupEvents);
84
+ }
85
+ if (data.actionType === 4) {
86
+ data.changeGroups?.forEach(group => {
87
+ const {
88
+ removeUsers,
89
+ groupUuid
90
+ } = group;
91
+ if (removeUsers) {
92
+ this._observable.notifyObservers('onUserListRemovedFromGroup', removeUsers.map(user => {
93
+ let operatorUser;
94
+ if (event.operatorUser) {
95
+ operatorUser = convertRteUserToFcrUser(event.operatorUser, this._roomCache);
96
+ }
97
+ return {
98
+ groupId: groupUuid,
99
+ userId: user.userUuid,
100
+ reason: user.reason,
101
+ operatorUser
102
+ };
103
+ }));
104
+ }
105
+ });
106
+ const toGroupMap = new Map();
107
+ data.changeGroups?.forEach(group => {
108
+ const {
109
+ removeUsers
110
+ } = group;
111
+ if (removeUsers) {
112
+ removeUsers.forEach(user => {
113
+ if (user.toGroupUuid) {
114
+ const toGroup = toGroupMap.get(user.toGroupUuid);
115
+ if (toGroup) {
116
+ toGroup.userList.push({
117
+ userUuid: user.userUuid,
118
+ reason: user.reason,
119
+ toGroupUuid: user.toGroupUuid
120
+ });
121
+ } else {
122
+ toGroupMap.set(user.toGroupUuid, {
123
+ fromGroupId: group.groupUuid,
124
+ userList: [{
125
+ userUuid: user.userUuid,
126
+ reason: user.reason,
127
+ toGroupUuid: user.toGroupUuid
128
+ }]
129
+ });
130
+ }
131
+ }
132
+ });
133
+ }
134
+ });
135
+ toGroupMap.forEach((toGroupInfo, toGroupUuid) => {
136
+ this._observable.notifyObservers('onUserListMoveToGroup', toGroupInfo.userList.map(user => {
137
+ let operatorUser;
138
+ if (event.operatorUser) {
139
+ operatorUser = convertRteUserToFcrUser(event.operatorUser, this._roomCache);
140
+ }
141
+ return {
142
+ fromGroupId: toGroupInfo.fromGroupId,
143
+ toGroupId: toGroupUuid,
144
+ userId: user.userUuid,
145
+ reason: user.reason,
146
+ operatorUser
147
+ };
148
+ }));
149
+ });
150
+ data.changeGroups?.forEach(group => {
151
+ const {
152
+ addUsers,
153
+ groupUuid
154
+ } = group;
155
+ if (addUsers) {
156
+ this._observable.notifyObservers('onUserListAddedToGroup', addUsers.map(user => {
157
+ let operatorUser;
158
+ if (event.operatorUser) {
159
+ operatorUser = convertRteUserToFcrUser(event.operatorUser, this._roomCache);
160
+ }
161
+ return {
162
+ groupId: groupUuid,
163
+ userId: user.userUuid,
164
+ operatorUser
165
+ };
166
+ }));
167
+ }
168
+ });
169
+ }
170
+ }
171
+ }
172
+ };
173
+ this._scene.addObserver(observer);
174
+ }
175
+ _getGroupDetails() {
176
+ return this._scene.getScenePropertiesByKeyPath('groups.details');
177
+ }
178
+ getGroupList() {
179
+ const groupDetails = this._getGroupDetails();
180
+ const list = [];
181
+ Object.keys(groupDetails).forEach(groupId => {
182
+ const {
183
+ groupName
184
+ } = groupDetails[groupId];
185
+ list.push({
186
+ groupId,
187
+ groupName
188
+ });
189
+ });
190
+ return list;
191
+ }
192
+ getGroupUserList(groupId) {
193
+ const groupDetails = this._getGroupDetails();
194
+ const groupInfo = groupDetails[groupId];
195
+ if (groupInfo) {
196
+ return groupInfo.users.map(user => user.userUuid);
197
+ } else {
198
+ this.logger.warn('group not found', groupId);
199
+ return [];
200
+ }
201
+ }
202
+ addGroups(groups) {
203
+ return handleRequestError(() => this._api.addGroups(groups, {
204
+ roomId: this._scene.sceneId,
205
+ startTime: Date.now()
206
+ }), ErrorModuleCode.FCR_ROOM_GROUP, 'add groups failed');
207
+ }
208
+ updateGroups(groups) {
209
+ return handleRequestError(() => this._api.updateGroups(groups, {
210
+ roomId: this._scene.sceneId
211
+ }), ErrorModuleCode.FCR_ROOM_GROUP, 'update groups failed');
212
+ }
213
+ deleteGroups(groupIds) {
214
+ return handleRequestError(() => this._api.deleteGroups(groupIds, {
215
+ roomId: this._scene.sceneId
216
+ }), ErrorModuleCode.FCR_ROOM_GROUP, 'delete groups failed');
217
+ }
218
+ deleteAllGroups() {
219
+ return handleRequestError(() => this._api.deleteAllGroups({
220
+ roomId: this._scene.sceneId
221
+ }), ErrorModuleCode.FCR_ROOM_GROUP, 'delete all groups failed');
222
+ }
223
+ addUsers(userList, groupId) {
224
+ return handleRequestError(() => this._api.addUsers(userList, groupId, {
225
+ roomId: this._scene.sceneId
226
+ }), ErrorModuleCode.FCR_ROOM_GROUP, 'add users failed');
227
+ }
228
+ removeUsers(userList, groupId) {
229
+ return handleRequestError(() => this._api.removeUsers(userList, groupId, {
230
+ roomId: this._scene.sceneId
231
+ }), ErrorModuleCode.FCR_ROOM_GROUP, 'remove users failed');
232
+ }
233
+ moveUsers(userList, fromGroupId, toGroupId) {
234
+ return handleRequestError(() => this._api.moveUsers(userList, fromGroupId, toGroupId, {
235
+ roomId: this._scene.sceneId
236
+ }), ErrorModuleCode.FCR_ROOM_GROUP, 'move users failed');
237
+ }
238
+ // createSubRoomControl(groupId: string) {
239
+ // return new FcrSubRoomControlImpl(
240
+ // this._engine,
241
+ // this._engine.createScene({ sceneId: groupId }),
242
+ // this._api,
243
+ // this._config,
244
+ // 101
245
+ // );
246
+ // }
247
+ addObserver(observer) {
248
+ this._observable.addObserver(observer);
249
+ }
250
+ removeObserver(observer) {
251
+ this._observable.removeObserver(observer);
252
+ }
253
+ _addLogObserver() {
254
+ this.addObserver(generateLogObserver(this.logger, [['onGroupsAdded', ['events']], ['onGroupsUpdated', ['events']], ['onGroupsRemoved', ['events']], ['onUserListAddedToGroup', ['events']], ['onUserListRemovedFromGroup', ['events']], ['onUserListMoveToGroup', ['events']]]));
255
+ }
256
+ }