fcr-core 3.8.2 → 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 (159) 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/{chat-connection → 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/{chat-connection → chat-connector}/type.js +1 -1
  96. package/lib-es/engine/index.js +46 -56
  97. package/lib-es/engine/type.js +1 -0
  98. package/lib-es/imports.js +5 -3
  99. package/lib-es/index.js +2 -1
  100. package/lib-es/media-control/desktop.js +12 -12
  101. package/lib-es/media-control/mobile.js +4 -0
  102. package/lib-es/monitor-control/index.js +3 -3
  103. package/lib-es/peer-session/index.js +16 -15
  104. package/lib-es/plugins/chat/chatroom.js +409 -0
  105. package/lib-es/{chat-connection → plugins/chat}/config.js +2 -1
  106. package/lib-es/{chat-connection/index.js → plugins/chat/connector.js} +178 -58
  107. package/lib-es/room-control/ability-control/index.js +5 -4
  108. package/lib-es/room-control/ability-control/type.js +4 -0
  109. package/lib-es/room-control/group-control/index.js +11 -10
  110. package/lib-es/room-control/index.js +40 -26
  111. package/lib-es/room-control/interpreter-control/index.js +10 -5
  112. package/lib-es/room-control/interpreter-control/room.js +3 -3
  113. package/lib-es/room-control/join-before-host-waitingroom-control/index.js +4 -3
  114. package/lib-es/room-control/mainroom-control/index.js +16 -17
  115. package/lib-es/room-control/privilege-control/index.js +43 -29
  116. package/lib-es/room-control/room-connector-control/index.js +9 -6
  117. package/lib-es/room-control/room-control-factory.js +6 -6
  118. package/lib-es/room-control/room-session/index.js +21 -22
  119. package/lib-es/room-control/sharing-control/index.js +13 -7
  120. package/lib-es/room-control/stream-control/index.js +21 -18
  121. package/lib-es/room-control/stt-control/index.js +23 -15
  122. package/lib-es/room-control/user-control/index.js +23 -23
  123. package/lib-es/room-control/waitingroom-control/index.js +10 -9
  124. package/lib-es/room-control/whiteboard-control-v1/board-window.js +27 -8
  125. package/lib-es/room-control/whiteboard-control-v1/factory.js +1 -1
  126. package/lib-es/room-control/whiteboard-control-v1/index.js +26 -17
  127. package/lib-es/room-control/whiteboard-control-v1/type.js +1 -0
  128. package/lib-es/room-control/whiteboard-control-v2/annotation-control/control.js +39 -5
  129. package/lib-es/room-control/whiteboard-control-v2/annotation-control/factory.js +7 -6
  130. package/lib-es/room-control/whiteboard-control-v2/base/index.js +86 -42
  131. package/lib-es/room-control/whiteboard-control-v2/base/main-window.js +23 -4
  132. package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/control.js +60 -13
  133. package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/factory.js +10 -10
  134. package/lib-es/room-router/index.js +10 -6
  135. package/lib-es/schema.js +1 -2
  136. package/lib-es/service/api.js +17 -12
  137. package/lib-es/type.js +70 -18
  138. package/lib-es/utilities/abortable-retry.js +54 -0
  139. package/lib-es/utilities/dual-video-stream-config.js +19 -0
  140. package/lib-es/utilities/error-helpers.js +13 -12
  141. package/lib-es/utilities/error.js +9 -75
  142. package/lib-es/utilities/join-helper.js +4 -3
  143. package/lib-es/utilities/logger.js +7 -23
  144. package/lib-es/utilities/package-info.js +4 -6
  145. package/lib-es/utilities/parameters.js +88 -15
  146. package/lib-es/utilities/validate-params.js +3 -2
  147. package/lib-es/utilities/video-encoder-config.js +103 -0
  148. package/package.json +7 -7
  149. package/lib/chat-connection/index.d.ts +0 -24
  150. package/lib/chat-connection/type.d.ts +0 -17
  151. package/lib/plugins/chatroom.js +0 -454
  152. package/lib/room-control/chatroom-control/config.d.ts +0 -51
  153. package/lib/room-control/chatroom-control/config.js +0 -105
  154. package/lib/utilities/storage.d.ts +0 -8
  155. package/lib/utilities/storage.js +0 -33
  156. package/lib-es/plugins/chatroom.js +0 -446
  157. package/lib-es/room-control/chatroom-control/config.js +0 -100
  158. package/lib-es/utilities/storage.js +0 -27
  159. /package/lib/plugins/{chatroom.d.ts → chat/chatroom.d.ts} +0 -0
@@ -15,27 +15,32 @@ import "core-js/modules/esnext.map.reduce.js";
15
15
  import "core-js/modules/esnext.map.some.js";
16
16
  import "core-js/modules/esnext.map.update.js";
17
17
  import "core-js/modules/esnext.symbol.metadata.js";
18
- let _initProto;
18
+ let _initProto, _setOperationPrivilegeDecs;
19
19
  import "core-js/modules/es.json.stringify.js";
20
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
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
22
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
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
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 { Room } from '@netless/forge-room';
25
26
  import { RTMProvider_2_2 } from '@netless/forge-rtm';
27
+ import { WhiteboardApplication } from '@netless/forge-whiteboard';
28
+ import { DetailErrorCode, ErrorModuleCode } from '../../../imports';
26
29
  import { AgoraObservable, AgoraScheduler, jsonstring, retryAttempt, to, trace } from '../../../imports';
27
- import { BOARD_RETRY_MAX, INIT_CONFIG_FETCH_INTERVAL, WHITEBOARD_APP_ID } from '../constant';
28
- import { Room } from '@netless/forge-room';
29
- import { createLogger, generateLogObserver } from '../../../utilities/logger';
30
- import { WhiteboardApplication, WhiteboardPermissionFlag } from '@netless/forge-whiteboard';
30
+ import { FcrConnectionState, FcrReturnCode } from '../../../type';
31
31
  import { generateFcrCoreClientError, FcrErrorModuleCode, FcrErrorCode } from '../../../utilities/error';
32
+ import { createLogger, generateLogObserver } from '../../../utilities/logger';
33
+ import { INIT_CONFIG_FETCH_INTERVAL, WHITEBOARD_APP_ID } from '../constant';
32
34
  import { FcrBoardMainWindowImpl } from './main-window';
33
- import { FcrConnectionState } from '../../../type';
35
+
36
+ /** @param isNeedLaunch 是否需要调用白板 luanch 函数 */
37
+
38
+ const WHITEBOARD_ROOM_JOIN_TIMEOUT = 20000;
34
39
  export class FcrBaseWhiteboardControlImpl {
35
40
  static {
36
- [_initProto] = _applyDecs(this, [[trace, 2, "setOperationPrivilege"], [trace, 2, "open"], [trace, 2, "close"], [trace, 2, "getConnectionState"], [trace, 2, "getMainWindow"]], []).e;
41
+ [_initProto] = _applyDecs(this, [[_setOperationPrivilegeDecs, 2, "setOperationPrivilege"], [trace, 2, "open"], [trace, 2, "close"], [trace, 2, "getConnectionState"], [trace, 2, "getMainWindow"]], []).e;
37
42
  }
38
- logger = (_initProto(this), createLogger({
43
+ [(_setOperationPrivilegeDecs = trace(['hasOperationPrivilege']), "logger")] = (_initProto(this), createLogger({
39
44
  prefix: 'FcrBaseWhiteboardControl'
40
45
  }));
41
46
  observable = new AgoraObservable();
@@ -49,7 +54,10 @@ export class FcrBaseWhiteboardControlImpl {
49
54
  _waitPromiseResolve = null;
50
55
  _waitPromiseReject = null;
51
56
  _openAbortController = null;
52
- _isOpen = false;
57
+ _openState = {
58
+ isOpen: false,
59
+ isNeedLaunch: undefined
60
+ };
53
61
  constructor(rtmClient, config, hasOperationPrivilege, forgeInitConfigFetcher) {
54
62
  this.rtmClient = rtmClient;
55
63
  this.config = config;
@@ -59,8 +67,8 @@ export class FcrBaseWhiteboardControlImpl {
59
67
  this.forgeInitConfig = forgeInitConfig;
60
68
  this.logger.info(`fetch forge init config success, config: ${jsonstring(forgeInitConfig)}`);
61
69
  this.forgeInitConfigTask.stop();
62
- if (this._isOpen) {
63
- this.connect();
70
+ if (this._openState.isOpen) {
71
+ this.connect(this._openState.isNeedLaunch);
64
72
  }
65
73
  }, INIT_CONFIG_FETCH_INTERVAL);
66
74
  this.addLogObserver();
@@ -68,17 +76,17 @@ export class FcrBaseWhiteboardControlImpl {
68
76
  setOperationPrivilege(hasOperationPrivilege) {
69
77
  if (this.hasOperationPrivilege !== hasOperationPrivilege) {
70
78
  this.hasOperationPrivilege = hasOperationPrivilege;
71
- const whiteboard = this.whiteboard;
79
+ const boardRoom = this.boardRoom;
72
80
  const boardView = this.boardView;
73
- if (whiteboard) {
81
+ if (boardRoom) {
74
82
  if (hasOperationPrivilege) {
75
- whiteboard.permissions.addPermission(WhiteboardPermissionFlag.all);
83
+ boardRoom.setWritable(true);
76
84
  if (boardView) {
77
85
  // @ts-expect-error
78
86
  boardView._observable.notifyObservers('onWritable', true);
79
87
  }
80
88
  } else {
81
- whiteboard.permissions.removePermission(WhiteboardPermissionFlag.all);
89
+ boardRoom.setWritable(false);
82
90
  if (boardView) {
83
91
  // @ts-expect-error
84
92
  boardView._observable.notifyObservers('onWritable', false);
@@ -86,24 +94,17 @@ export class FcrBaseWhiteboardControlImpl {
86
94
  }
87
95
  }
88
96
  }
97
+ return FcrReturnCode.SUCCESS;
89
98
  }
90
99
  async open() {
91
- this._isOpen = true;
92
- const isReadyToConnect = this._checkForConnect();
93
- if (isReadyToConnect) {
94
- return this.connect();
95
- }
96
- if (!this._waitPromise) {
97
- this._waitPromise = new Promise((resolve, reject) => {
98
- this._waitPromiseResolve = resolve;
99
- this._waitPromiseReject = reject;
100
- this.logger.info('waiting for forge config to be ready');
101
- });
102
- }
103
- return this._waitPromise;
100
+ this.logger.error('subclass must implement open method, not call base class method');
101
+ throw generateFcrCoreClientError(FcrErrorModuleCode.FCR_ROOM_WHITEBOARD, FcrErrorCode.UNDEFINED_ERROR, 'subclass must implement open method, not call base class method', new Error('subclass must implement open method, not call base class method'));
104
102
  }
105
103
  async close() {
106
- this._isOpen = false;
104
+ this._openState = {
105
+ isOpen: false,
106
+ isNeedLaunch: undefined
107
+ };
107
108
  if (!this.forgeInitConfigTask.isStopped) {
108
109
  this.forgeInitConfigTask.stop();
109
110
  }
@@ -122,7 +123,6 @@ export class FcrBaseWhiteboardControlImpl {
122
123
  this.whiteboard = null;
123
124
  if (boardRoom) {
124
125
  boardRoom.applicationManager.removeAllListeners();
125
- boardRoom.applicationManager.terminateApplication(this.getApplicationId());
126
126
  await boardRoom.leaveRoom();
127
127
  }
128
128
  } catch (e) {
@@ -130,6 +130,7 @@ export class FcrBaseWhiteboardControlImpl {
130
130
  } finally {
131
131
  this.updateConnectionState(FcrConnectionState.DISCONNECTED);
132
132
  }
133
+ return FcrReturnCode.SUCCESS;
133
134
  }
134
135
  getConnectionState() {
135
136
  return this.connectState;
@@ -143,6 +144,24 @@ export class FcrBaseWhiteboardControlImpl {
143
144
  removeObserver(observer) {
144
145
  this.observable.removeObserver(observer);
145
146
  }
147
+ internalOpen(isNeedLaunch) {
148
+ this._openState = {
149
+ isOpen: true,
150
+ isNeedLaunch: isNeedLaunch
151
+ };
152
+ const isReadyToConnect = this._checkForConnect();
153
+ if (isReadyToConnect) {
154
+ return this.connect(isNeedLaunch);
155
+ }
156
+ if (!this._waitPromise) {
157
+ this._waitPromise = new Promise((resolve, reject) => {
158
+ this._waitPromiseResolve = resolve;
159
+ this._waitPromiseReject = reject;
160
+ this.logger.info('waiting for forge config to be ready');
161
+ });
162
+ }
163
+ return this._waitPromise;
164
+ }
146
165
  updateConnectionState(state) {
147
166
  if (this.connectState === state) {
148
167
  return;
@@ -152,7 +171,7 @@ export class FcrBaseWhiteboardControlImpl {
152
171
  this.logger.info(`Connection state updated: ${FcrConnectionState[oldState]} -> ${FcrConnectionState[state]}`);
153
172
  this.observable.notifyObservers('onConnectionStateUpdated', state);
154
173
  }
155
- async connect() {
174
+ async connect(isNeedLaunch) {
156
175
  if (this.boardView) {
157
176
  this.logger.info('board already connected, returning existing board view');
158
177
  return this.boardView;
@@ -175,13 +194,13 @@ export class FcrBaseWhiteboardControlImpl {
175
194
  boardToken
176
195
  } = this.forgeInitConfig || {};
177
196
  if (!boardAppId) {
178
- throw generateFcrCoreClientError(FcrErrorModuleCode.ROOM_WHITEBOARD, FcrErrorCode.UNDEFINED_ERROR, 'boardAppId is required', new Error('boardAppId is required'));
197
+ throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM_WHITEBOARD, DetailErrorCode.UNDEFINED_ERROR, 'boardAppId is required', new Error('boardAppId is required'));
179
198
  }
180
199
  if (!boardId) {
181
- throw generateFcrCoreClientError(FcrErrorModuleCode.ROOM_WHITEBOARD, FcrErrorCode.UNDEFINED_ERROR, 'boardId is required', new Error('boardId is required'));
200
+ throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM_WHITEBOARD, DetailErrorCode.UNDEFINED_ERROR, 'boardId is required', new Error('boardId is required'));
182
201
  }
183
202
  if (!boardToken) {
184
- throw generateFcrCoreClientError(FcrErrorModuleCode.ROOM_WHITEBOARD, FcrErrorCode.UNDEFINED_ERROR, 'boardToken is required', new Error('boardToken is required'));
203
+ throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM_WHITEBOARD, DetailErrorCode.UNDEFINED_ERROR, 'boardToken is required', new Error('boardToken is required'));
185
204
  }
186
205
  const whiteboardOption = this.getWhiteboardOption();
187
206
  let width = whiteboardOption.width;
@@ -194,7 +213,7 @@ export class FcrBaseWhiteboardControlImpl {
194
213
  this.logger.warn(`board height is a invalid value: ${height}, using default value 600`);
195
214
  whiteboardOption.height = 600;
196
215
  }
197
- this.logger.info(`open board with boardId: ${boardId}, boardToken: ${boardToken}, region: ${boardRegion}, whiteboardOption: ${jsonstring(whiteboardOption)}`);
216
+ this.logger.info(`open board with boardId: ${boardId}, boardToken: ${boardToken}, region: ${boardRegion}, appIdentifier: ${boardAppId} whiteboardOption: ${jsonstring(whiteboardOption)}`);
198
217
  const rtmProvider = new RTMProvider_2_2(this.rtmClient);
199
218
  const wbRoom = new Room(boardId, rtmProvider);
200
219
  wbRoom.applicationManager.registerApplication(WhiteboardApplication);
@@ -205,6 +224,23 @@ export class FcrBaseWhiteboardControlImpl {
205
224
  let whiteboard = null;
206
225
  let boardRoom = wbRoom;
207
226
  const appId = this.getApplicationId();
227
+ let getWhiteboard;
228
+
229
+ // 第一个开启白板的人需要调用 launch 方法, 其他人监听 launch 事件获取白板实例
230
+ if (isNeedLaunch) {
231
+ getWhiteboard = () => {
232
+ return wbRoom.applicationManager.launchApplication(WhiteboardApplication, whiteboardOption, appId);
233
+ };
234
+ } else {
235
+ const launchPromise = new Promise((launchPromseResolve, launchPromseReject) => {
236
+ wbRoom.applicationManager.once('launch', (appId, app) => {
237
+ launchPromseResolve(app);
238
+ });
239
+ });
240
+ getWhiteboard = () => {
241
+ return launchPromise;
242
+ };
243
+ }
208
244
  [error] = await to(retryAttempt(async () => {
209
245
  const joinRoomParams = {
210
246
  userId,
@@ -213,15 +249,23 @@ export class FcrBaseWhiteboardControlImpl {
213
249
  sdkConfig: {
214
250
  region: boardRegion,
215
251
  appIdentifier: boardAppId
216
- }
252
+ },
253
+ writable: true
217
254
  // verboseLog: true,
218
255
  };
219
256
  this.logger.info(`join params: ${jsonstring(joinRoomParams)}`);
220
- await wbRoom.joinRoom(joinRoomParams);
257
+
258
+ // 20 秒超时
259
+ await wbRoom.joinRoom(joinRoomParams, WHITEBOARD_ROOM_JOIN_TIMEOUT);
221
260
  boardRoom = wbRoom;
222
- whiteboard = await wbRoom.applicationManager.launchApplication(WhiteboardApplication, whiteboardOption, appId);
261
+ whiteboard = await getWhiteboard();
262
+ if (isNeedLaunch) {
263
+ // 在同一个房间内只有第一次调用 launchApplication 时传入的宽高参数会生效, 后续的调用不会生效, 所以需要在这里更新宽高
264
+ // 只有 launch 的用户需要更新宽、高, 白板会自动同步给后加入的用户
265
+ whiteboard.updateViewport(width, height);
266
+ }
223
267
  }, [], {
224
- retriesMax: BOARD_RETRY_MAX
268
+ retriesMax: 0
225
269
  }).fail(async ({
226
270
  error,
227
271
  timeFn,
@@ -250,9 +294,9 @@ export class FcrBaseWhiteboardControlImpl {
250
294
  this.boardView = boardView;
251
295
  this.boardRoom = boardRoom;
252
296
  if (this.hasOperationPrivilege) {
253
- whiteboard.permissions.addPermission(WhiteboardPermissionFlag.all);
297
+ this.boardRoom.setWritable(true);
254
298
  } else {
255
- whiteboard.permissions.removePermission(WhiteboardPermissionFlag.all);
299
+ this.boardRoom.setWritable(false);
256
300
  }
257
301
  this.updateConnectionState(FcrConnectionState.CONNECTED);
258
302
  resolve(boardView);
@@ -290,7 +334,7 @@ export class FcrBaseWhiteboardControlImpl {
290
334
  return 'rgba(0, 0, 0, 0)';
291
335
  }
292
336
  addLogObserver() {
293
- this.addObserver(generateLogObserver(this.logger, ['onConnectionStateUpdated']));
337
+ this.addObserver(generateLogObserver(this.logger, [['onConnectionStateUpdated', ['state']]]));
294
338
  }
295
339
  _checkForConnect() {
296
340
  return !!this.forgeInitConfig;
@@ -15,7 +15,7 @@ import "core-js/modules/esnext.map.reduce.js";
15
15
  import "core-js/modules/esnext.map.some.js";
16
16
  import "core-js/modules/esnext.map.update.js";
17
17
  import "core-js/modules/esnext.symbol.metadata.js";
18
- let _initProto, _setBackgroundColorDecs, _setToolTypeDecs, _setStrokeWidthDecs, _setStrokeColorDecs, _setTextColorDecs, _setTextSizeDecs, _insertImageDecs, _setContainerSizeRatioDecs, _setBoardTransparentDecs, _updateWindowSizeDecs, _setAutoCancelDrawDecs;
18
+ let _initProto, _setBackgroundColorDecs, _setToolTypeDecs, _setStrokeWidthDecs, _setStrokeColorDecs, _setTextColorDecs, _setTextSizeDecs, _insertImageDecs, _setContainerSizeRatioDecs, _setBoardTransparentDecs, _updateWindowSizeDecs, _setAutoCancelDrawDecs, _handleApplicationLaunchDecs, _handleApplicationTerminalDecs, _enableAutoCancelDecs;
19
19
  import "core-js/modules/esnext.iterator.constructor.js";
20
20
  import "core-js/modules/esnext.iterator.some.js";
21
21
  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)]; } }; }
@@ -32,11 +32,12 @@ import { stringSchema } from 'agora-foundation/lib/utilities/schema';
32
32
  import validateParams from '../../../utilities/validate-params';
33
33
  import { booleanSchema, colorSchema, fcrBoardToolTypeSchema, fcrSizeSchema, numberSchema, z } from '../../../schema';
34
34
  import { bound } from 'agora-foundation/lib/decorator';
35
+ import { FcrReturnCode } from '../../../type';
35
36
  export class FcrBoardMainWindowImpl {
36
37
  static {
37
- [_initProto] = _applyDecs(this, [[trace, 2, "addPage"], [trace, 2, "removePage"], [trace, 2, "undo"], [trace, 2, "redo"], [trace, 2, "clean"], [trace, 2, "getSnapshotImage"], [_setBackgroundColorDecs, 2, "setBackgroundColor"], [trace, 2, "getPageInfo"], [trace, 2, "prevPage"], [trace, 2, "nextPage"], [_setToolTypeDecs, 2, "setToolType"], [_setStrokeWidthDecs, 2, "setStrokeWidth"], [_setStrokeColorDecs, 2, "setStrokeColor"], [_setTextColorDecs, 2, "setTextColor"], [_setTextSizeDecs, 2, "setTextSize"], [_insertImageDecs, 2, "insertImage"], [trace, 2, "getContentView"], [_setContainerSizeRatioDecs, 2, "setContainerSizeRatio"], [_setBoardTransparentDecs, 2, "setBoardTransparent"], [_updateWindowSizeDecs, 2, "updateWindowSize"], [_setAutoCancelDrawDecs, 2, "setAutoCancelDraw"], [trace, 2, "getWritable"], [[bound, trace], 2, "_handleApplicationLaunch"], [[bound, trace], 2, "_handleApplicationTerminal"], [trace, 2, "_enableAutoCancel"]], []).e;
38
+ [_initProto] = _applyDecs(this, [[trace, 2, "addPage"], [trace, 2, "removePage"], [trace, 2, "undo"], [trace, 2, "redo"], [trace, 2, "clean"], [trace, 2, "getSnapshotImage"], [_setBackgroundColorDecs, 2, "setBackgroundColor"], [trace, 2, "getPageInfo"], [trace, 2, "prevPage"], [trace, 2, "nextPage"], [_setToolTypeDecs, 2, "setToolType"], [_setStrokeWidthDecs, 2, "setStrokeWidth"], [_setStrokeColorDecs, 2, "setStrokeColor"], [_setTextColorDecs, 2, "setTextColor"], [_setTextSizeDecs, 2, "setTextSize"], [_insertImageDecs, 2, "insertImage"], [trace, 2, "getContentView"], [_setContainerSizeRatioDecs, 2, "setContainerSizeRatio"], [_setBoardTransparentDecs, 2, "setBoardTransparent"], [_updateWindowSizeDecs, 2, "updateWindowSize"], [_setAutoCancelDrawDecs, 2, "setAutoCancelDraw"], [trace, 2, "getWritable"], [_handleApplicationLaunchDecs, 2, "_handleApplicationLaunch"], [_handleApplicationTerminalDecs, 2, "_handleApplicationTerminal"], [_enableAutoCancelDecs, 2, "_enableAutoCancel"]], []).e;
38
39
  }
39
- [(_setBackgroundColorDecs = [trace, validateParams(stringSchema)], _setToolTypeDecs = [trace, validateParams(fcrBoardToolTypeSchema)], _setStrokeWidthDecs = [trace, validateParams(numberSchema)], _setStrokeColorDecs = [trace, validateParams(z.union([colorSchema, stringSchema]))], _setTextColorDecs = [trace, validateParams(colorSchema)], _setTextSizeDecs = [trace, validateParams(numberSchema)], _insertImageDecs = [trace, validateParams(stringSchema, numberSchema, numberSchema, numberSchema, numberSchema)], _setContainerSizeRatioDecs = [trace, validateParams(numberSchema)], _setBoardTransparentDecs = [trace, validateParams(booleanSchema)], _updateWindowSizeDecs = [trace, validateParams(fcrSizeSchema)], _setAutoCancelDrawDecs = [trace, validateParams(booleanSchema)], "logger")] = (_initProto(this), createLogger({
40
+ [(_setBackgroundColorDecs = [trace(['color']), validateParams(stringSchema)], _setToolTypeDecs = [trace(['type']), validateParams(fcrBoardToolTypeSchema)], _setStrokeWidthDecs = [trace(['strokeWidth']), validateParams(numberSchema)], _setStrokeColorDecs = [trace(['color']), validateParams(z.union([colorSchema, stringSchema]))], _setTextColorDecs = [trace(['color']), validateParams(colorSchema)], _setTextSizeDecs = [trace(['textSize']), validateParams(numberSchema)], _insertImageDecs = [trace(['resourceUrl', 'x', 'y', 'width', 'height']), validateParams(stringSchema, numberSchema, numberSchema, numberSchema, numberSchema)], _setContainerSizeRatioDecs = [trace(['ratio']), validateParams(numberSchema)], _setBoardTransparentDecs = [trace(['isTransparent']), validateParams(booleanSchema)], _updateWindowSizeDecs = [trace(['size']), validateParams(fcrSizeSchema)], _setAutoCancelDrawDecs = [trace(['enable']), validateParams(booleanSchema)], _handleApplicationLaunchDecs = [bound, trace(['appId', 'app'])], _handleApplicationTerminalDecs = [bound, trace(['appId', 'app'])], _enableAutoCancelDecs = trace(['enable']), "logger")] = (_initProto(this), createLogger({
40
41
  prefix: 'FcrBoardMainWindowImpl'
41
42
  }));
42
43
  _observable = new AgoraObservable();
@@ -62,18 +63,23 @@ export class FcrBoardMainWindowImpl {
62
63
  }
63
64
  async addPage() {
64
65
  this._whiteboard.addPage('next');
66
+ return FcrReturnCode.SUCCESS;
65
67
  }
66
68
  async removePage() {
67
69
  this._whiteboard.deletePage('current');
70
+ return FcrReturnCode.SUCCESS;
68
71
  }
69
72
  async undo() {
70
73
  this._whiteboard.undo();
74
+ return FcrReturnCode.SUCCESS;
71
75
  }
72
76
  async redo() {
73
77
  this._whiteboard.redo();
78
+ return FcrReturnCode.SUCCESS;
74
79
  }
75
80
  async clean() {
76
81
  this._whiteboard.clearPage();
82
+ return FcrReturnCode.SUCCESS;
77
83
  }
78
84
  async getSnapshotImage() {
79
85
  if (this._whiteboard) {
@@ -107,6 +113,7 @@ export class FcrBoardMainWindowImpl {
107
113
  this._background = color;
108
114
  this.logger.info(`set canvas background color: ${this._background}`);
109
115
  this._whiteboard.setCanvasBackgroundColor(color);
116
+ return FcrReturnCode.SUCCESS;
110
117
  }
111
118
  getPageInfo() {
112
119
  return {
@@ -116,9 +123,11 @@ export class FcrBoardMainWindowImpl {
116
123
  }
117
124
  async prevPage() {
118
125
  this._whiteboard.indexedNavigation.prevPage();
126
+ return FcrReturnCode.SUCCESS;
119
127
  }
120
128
  async nextPage() {
121
129
  this._whiteboard.indexedNavigation.nextPage();
130
+ return FcrReturnCode.SUCCESS;
122
131
  }
123
132
  async setToolType(type) {
124
133
  if (this._whiteboard) {
@@ -127,6 +136,7 @@ export class FcrBoardMainWindowImpl {
127
136
  } else {
128
137
  throw new Error('Whiteboard is not initialized');
129
138
  }
139
+ return FcrReturnCode.SUCCESS;
130
140
  }
131
141
  async setStrokeWidth(strokeWidth) {
132
142
  if (this._whiteboard) {
@@ -134,6 +144,7 @@ export class FcrBoardMainWindowImpl {
134
144
  } else {
135
145
  throw new Error('Whiteboard is not initialized');
136
146
  }
147
+ return FcrReturnCode.SUCCESS;
137
148
  }
138
149
  async setStrokeColor(color) {
139
150
  const c = typeof color === 'string' ? color : `rgb(${color.r},${color.g},${color.b})`;
@@ -142,6 +153,7 @@ export class FcrBoardMainWindowImpl {
142
153
  } else {
143
154
  throw new Error('Whiteboard is not initialized');
144
155
  }
156
+ return FcrReturnCode.SUCCESS;
145
157
  }
146
158
  async setTextColor(color) {
147
159
  const c = typeof color === 'string' ? color : `rgb(${color.r},${color.g},${color.b})`;
@@ -150,6 +162,7 @@ export class FcrBoardMainWindowImpl {
150
162
  } else {
151
163
  throw new Error('Whiteboard is not initialized');
152
164
  }
165
+ return FcrReturnCode.SUCCESS;
153
166
  }
154
167
  async setTextSize(textSize) {
155
168
  if (this._whiteboard) {
@@ -157,6 +170,7 @@ export class FcrBoardMainWindowImpl {
157
170
  } else {
158
171
  throw new Error('Whiteboard is not initialized');
159
172
  }
173
+ return FcrReturnCode.SUCCESS;
160
174
  }
161
175
  async insertImage(resourceUrl, x, y, width, height) {}
162
176
  getContentView() {
@@ -166,10 +180,12 @@ export class FcrBoardMainWindowImpl {
166
180
  async setBoardTransparent(isTransparent) {}
167
181
  updateWindowSize(size) {
168
182
  size && this._whiteboard.updateViewport(size.width, size.height);
183
+ return FcrReturnCode.SUCCESS;
169
184
  }
170
185
  setAutoCancelDraw(enable) {
171
186
  this._isAutoCancelEnabled = enable;
172
187
  this._enableAutoCancel(enable);
188
+ return FcrReturnCode.SUCCESS;
173
189
  }
174
190
  getWritable() {
175
191
  return this._whiteboard.permissions.getPermissionFlags().some(flag => {
@@ -220,6 +236,7 @@ export class FcrBoardMainWindowImpl {
220
236
  }
221
237
  this._boardView.setAttribute('data-app-id', appId);
222
238
  this._boardView.appendChild(app.view);
239
+ return FcrReturnCode.SUCCESS;
223
240
  }
224
241
  _handleApplicationTerminal(appId, app) {
225
242
  try {
@@ -232,6 +249,7 @@ export class FcrBoardMainWindowImpl {
232
249
  } catch (e) {
233
250
  this.logger.error(`failed to handle terminal: ${appId}`, e);
234
251
  }
252
+ return FcrReturnCode.SUCCESS;
235
253
  }
236
254
  _setBoardViewStyle(view) {
237
255
  view.style.height = `100%`;
@@ -243,8 +261,9 @@ export class FcrBoardMainWindowImpl {
243
261
  this._whiteboard.__setMainCanvasVisible(!enable);
244
262
  // @ts-ignore
245
263
  this._whiteboard.__delayTranslateOut = enable ? 4000 : -1;
264
+ return FcrReturnCode.SUCCESS;
246
265
  }
247
266
  _addLogObserver() {
248
- this.addObserver(generateLogObserver(this.logger, ['onWritable', 'onPageInfoUpdated', 'onUndoStateUpdated', 'onRedoStateUpdated']));
267
+ this.addObserver(generateLogObserver(this.logger, [['onWritable', ['isWritable']], ['onPageInfoUpdated', ['info']], ['onUndoStateUpdated', ['enable']], ['onRedoStateUpdated', ['enable']]]));
249
268
  }
250
269
  }
@@ -15,35 +15,38 @@ import "core-js/modules/esnext.map.reduce.js";
15
15
  import "core-js/modules/esnext.map.some.js";
16
16
  import "core-js/modules/esnext.map.update.js";
17
17
  import "core-js/modules/esnext.symbol.metadata.js";
18
- var _ref;
19
- let _initProto, _setBackgroundColorDecs;
18
+ var _ref, _ref2;
19
+ let _initProto, _setBackgroundColorDecs, _initProto2;
20
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
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
22
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
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
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 { ErrorModuleCode } from '../../../imports';
25
26
  import { bound, get, trace } from '../../../imports';
26
- import { convertRteUserToFcrUser } from '../../../utilities/user';
27
- import { FcrErrorModuleCode, handleRequestError } from '../../../utilities/error';
28
27
  import { stringSchema } from '../../../schema';
28
+ import { FcrReturnCode } from '../../../type';
29
+ import { handleRequestError } from '../../../utilities/error';
30
+ import { createLogger, generateLogObserver } from '../../../utilities/logger';
29
31
  import { getDependenciesInfo } from '../../../utilities/package-info';
32
+ import { convertRteUserToFcrUser } from '../../../utilities/user';
30
33
  import validateParams from '../../../utilities/validate-params';
34
+ import { FcrSharePermissionState } from '../../sharing-control/type';
35
+ import { FcrBoardPropertiesState } from '../../whiteboard-control/type';
31
36
  import { FcrBaseWhiteboardControlImpl } from '../base';
32
37
  import { WHITEBOARD_APP_ID } from '../constant';
33
- import { FcrBoardPropertiesState } from '../../whiteboard-control/type';
34
- import { FcrSharePermissionState } from '../../sharing-control/type';
35
- import { createLogger, generateLogObserver } from '../../../utilities/logger';
36
38
  import { WHITEBOARD_HEIGHT, WHITEBOARD_WIDTH } from '../utils';
37
39
  export class FcrWhiteboardControlImpl extends (_ref = FcrBaseWhiteboardControlImpl) {
38
40
  static {
39
- [_initProto] = _applyDecs(this, [[trace, 2, "active"], [trace, 2, "inactive"], [_setBackgroundColorDecs, 2, "setBackgroundColor"], [trace, 2, "getBackgroundColor"], [trace, 2, "getActivity"], [trace, 2, "getOwnerId"], [bound, 2, "_onScenePropertiesUpdated"]], [], 0, void 0, _ref).e;
41
+ [_initProto] = _applyDecs(this, [[trace, 2, "open"], [trace, 2, "close"], [trace, 2, "active"], [trace, 2, "inactive"], [_setBackgroundColorDecs, 2, "setBackgroundColor"], [trace, 2, "getBackgroundColor"], [trace, 2, "getActivity"], [trace, 2, "getOwnerId"], [bound, 2, "_onScenePropertiesUpdated"]], [], 0, void 0, _ref).e;
40
42
  }
41
- [(_setBackgroundColorDecs = [trace, validateParams(stringSchema)], "logger")] = (_initProto(this), createLogger({
43
+ [(_setBackgroundColorDecs = [trace(['backgroundColor']), validateParams(stringSchema)], "logger")] = (_initProto(this), createLogger({
42
44
  prefix: 'FcrWhiteboardControlImpl'
43
45
  }));
44
46
  _backgroundColor = '#ffffff';
45
47
  _isActive = false;
46
48
  _ownerId = null;
49
+ _preloadLock = false;
47
50
  _notifyObservers = {
48
51
  onScenePropertiesUpdated: this._onScenePropertiesUpdated
49
52
  };
@@ -65,11 +68,41 @@ export class FcrWhiteboardControlImpl extends (_ref = FcrBaseWhiteboardControlIm
65
68
  }
66
69
  this.logger.info(`initialized, hasOperationPrivilege: ${hasOperationPrivilege}`);
67
70
  }
71
+ async open() {
72
+ const boardActiveInfo = this.getBoardActiveInfo();
73
+ if (!boardActiveInfo.isActive) {
74
+ await handleRequestError(() => this._api.toggleWhiteboardPreloadState(this.config.roomId, FcrSharePermissionState.ON), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'lock failed when open whiteboard');
75
+
76
+ // 标记白板锁状态, 关闭白板时判断是否需要解锁
77
+ this._preloadLock = true;
78
+ try {
79
+ this._isActive = true;
80
+ return await super.internalOpen(true);
81
+ } catch (error) {
82
+ // 开启失败, 释放锁
83
+ this._preloadLock = false;
84
+ this._isActive = false;
85
+ await handleRequestError(() => this._api.toggleWhiteboardPreloadState(this.config.roomId, FcrSharePermissionState.OFF), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'unlock failed when open whiteboard');
86
+ throw error;
87
+ }
88
+ } else {
89
+ return await super.internalOpen(false);
90
+ }
91
+ }
92
+ async close() {
93
+ const result = await super.close();
94
+ if (this._preloadLock) {
95
+ // 释放白板锁
96
+ await handleRequestError(() => this._api.toggleWhiteboardPreloadState(this.config.roomId, FcrSharePermissionState.OFF), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'unlock failed when close whiteboard');
97
+ this._preloadLock = false;
98
+ }
99
+ return result;
100
+ }
68
101
  async active() {
69
- return handleRequestError(() => this._api.toggleWhiteboardActivityState(this.config.roomId, FcrSharePermissionState.ON), FcrErrorModuleCode.ROOM_WHITEBOARD, 'active failed');
102
+ return handleRequestError(() => this._api.toggleWhiteboardActivityState(this.config.roomId, FcrSharePermissionState.ON), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'active failed');
70
103
  }
71
104
  async inactive() {
72
- return handleRequestError(() => this._api.toggleWhiteboardActivityState(this.config.roomId, FcrSharePermissionState.OFF), FcrErrorModuleCode.ROOM_WHITEBOARD, 'inactive failed');
105
+ return handleRequestError(() => this._api.toggleWhiteboardActivityState(this.config.roomId, FcrSharePermissionState.OFF), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'inactive failed');
73
106
  }
74
107
  getBoardActiveInfo() {
75
108
  const {
@@ -97,6 +130,7 @@ export class FcrWhiteboardControlImpl extends (_ref = FcrBaseWhiteboardControlIm
97
130
  if (this.boardView) {
98
131
  this.boardView.setBackgroundColor(backgroundColor);
99
132
  }
133
+ return FcrReturnCode.SUCCESS;
100
134
  }
101
135
  getBackgroundColor() {
102
136
  return this._backgroundColor;
@@ -107,6 +141,9 @@ export class FcrWhiteboardControlImpl extends (_ref = FcrBaseWhiteboardControlIm
107
141
  getOwnerId() {
108
142
  return this._ownerId;
109
143
  }
144
+ getApplicationId() {
145
+ return WHITEBOARD_APP_ID;
146
+ }
110
147
  _onScenePropertiesUpdated(sceneId, event) {
111
148
  const operatorUser = convertRteUserToFcrUser(event.operatorUser, this._roomCache);
112
149
  const getByKeyPath = value => this._scene.getScenePropertiesByKeyPath(value);
@@ -140,10 +177,20 @@ export class FcrWhiteboardControlImpl extends (_ref = FcrBaseWhiteboardControlIm
140
177
  };
141
178
  }
142
179
  addLogObserver() {
143
- this.addObserver(generateLogObserver(this.logger, ['onConnectionStateUpdated', 'onActive', 'onInactive', 'onBackgroundColorUpdated']));
180
+ this.addObserver(generateLogObserver(this.logger, [['onConnectionStateUpdated', ['state']], ['onActive', ['ownerId', 'operatorUser']], ['onInactive', ['reason', 'operatorUser']], ['onBackgroundColorUpdated', ['color', 'operatorUser']]]));
144
181
  }
145
182
  }
146
- export class FcrStandaloneWhiteboardControlImpl extends FcrBaseWhiteboardControlImpl {
183
+ export class FcrStandaloneWhiteboardControlImpl extends (_ref2 = FcrBaseWhiteboardControlImpl) {
184
+ static {
185
+ [_initProto2] = _applyDecs(this, [[trace, 2, "open"]], [], 0, void 0, _ref2).e;
186
+ }
187
+ constructor(...args) {
188
+ super(...args);
189
+ _initProto2(this);
190
+ }
191
+ async open() {
192
+ return await super.internalOpen(false);
193
+ }
147
194
  getApplicationId() {
148
195
  return WHITEBOARD_APP_ID;
149
196
  }
@@ -15,30 +15,30 @@ import "core-js/modules/esnext.map.reduce.js";
15
15
  import "core-js/modules/esnext.map.some.js";
16
16
  import "core-js/modules/esnext.map.update.js";
17
17
  import "core-js/modules/esnext.symbol.metadata.js";
18
- let _initProto;
18
+ let _initProto, _createForSubProcessDecs, _createForMainProcessDecs;
19
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
20
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
21
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
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
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 { createLogger } from '../../../utilities/logger';
25
- import { FcrErrorCode, FcrErrorModuleCode, generateFcrCoreClientError, handleRequestError } from '../../../utilities/error';
26
24
  import { trace } from 'agora-foundation/lib/decorator/log';
27
- import { FcrBaseWhiteboardControlImpl } from '../base';
28
- import { FcrWhiteboardControlImpl } from './control';
25
+ import { DetailErrorCode, ErrorModuleCode } from 'agora-foundation/lib/utilities/error/error-code';
26
+ import { generateFcrCoreClientError, handleRequestError } from '../../../utilities/error';
27
+ import { createLogger } from '../../../utilities/logger';
29
28
  import { getWhiteboardOptions } from '../../../utilities/shared-storage';
29
+ import { FcrStandaloneWhiteboardControlImpl, FcrWhiteboardControlImpl } from './control';
30
30
  export class FcrWhiteboardControlFactoryImpl {
31
31
  static {
32
- [_initProto] = _applyDecs(this, [[trace, 2, "createForSubProcess"], [trace, 2, "createForMainProcess"]], []).e;
32
+ [_initProto] = _applyDecs(this, [[_createForSubProcessDecs, 2, "createForSubProcess"], [_createForMainProcessDecs, 2, "createForMainProcess"]], []).e;
33
33
  }
34
- logger = (_initProto(this), createLogger({
34
+ [(_createForSubProcessDecs = trace(['rtmClient', 'hasOperationPrivilege', 'boardConfig']), _createForMainProcessDecs = trace(['rtmClient', 'hasOperationPrivilege', 'boardConfig', 'scene', 'api', 'sharedCache']), "logger")] = (_initProto(this), createLogger({
35
35
  prefix: 'FcrWhiteboardControlFactory'
36
36
  }));
37
37
  createForSubProcess(rtmClient, hasOperationPrivilege, boardConfig) {
38
- return new FcrBaseWhiteboardControlImpl(rtmClient, boardConfig, hasOperationPrivilege, () => {
38
+ return new FcrStandaloneWhiteboardControlImpl(rtmClient, boardConfig, hasOperationPrivilege, () => {
39
39
  const forgeInitConfig = getWhiteboardOptions();
40
40
  if (!forgeInitConfig) {
41
- throw generateFcrCoreClientError(FcrErrorModuleCode.ROOM_WHITEBOARD, FcrErrorCode.UNDEFINED_ERROR, `whiteboard init config is not exist`, new Error(`whiteboard init config is not exist`));
41
+ throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM_WHITEBOARD, DetailErrorCode.UNDEFINED_ERROR, `whiteboard init config is not exist`, new Error(`whiteboard init config is not exist`));
42
42
  }
43
43
  return Promise.resolve(forgeInitConfig);
44
44
  });
@@ -51,7 +51,7 @@ export class FcrWhiteboardControlFactoryImpl {
51
51
  return await handleRequestError(() => api.getWhiteboardToken({
52
52
  roomId,
53
53
  userId
54
- }), FcrErrorModuleCode.ROOM_WHITEBOARD, 'get whiteboard token failed');
54
+ }), ErrorModuleCode.FCR_ROOM_WHITEBOARD, 'get whiteboard token failed');
55
55
  };
56
56
  return async () => {
57
57
  const response = await getObjectInitConfig(roomId, userId);