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
@@ -1,454 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.array.push.js");
4
- require("core-js/modules/esnext.function.metadata.js");
5
- require("core-js/modules/esnext.map.delete-all.js");
6
- require("core-js/modules/esnext.map.emplace.js");
7
- require("core-js/modules/esnext.map.every.js");
8
- require("core-js/modules/esnext.map.filter.js");
9
- require("core-js/modules/esnext.map.find.js");
10
- require("core-js/modules/esnext.map.find-key.js");
11
- require("core-js/modules/esnext.map.includes.js");
12
- require("core-js/modules/esnext.map.key-of.js");
13
- require("core-js/modules/esnext.map.map-keys.js");
14
- require("core-js/modules/esnext.map.map-values.js");
15
- require("core-js/modules/esnext.map.merge.js");
16
- require("core-js/modules/esnext.map.reduce.js");
17
- require("core-js/modules/esnext.map.some.js");
18
- require("core-js/modules/esnext.map.update.js");
19
- require("core-js/modules/esnext.symbol.metadata.js");
20
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
21
- Object.defineProperty(exports, "__esModule", {
22
- value: true
23
- });
24
- exports.FcrChatRoomControlImpl = void 0;
25
- require("core-js/modules/esnext.iterator.constructor.js");
26
- require("core-js/modules/esnext.iterator.map.js");
27
- var _imports = require("../imports");
28
- var _observable = require("agora-foundation/lib/utilities/observable");
29
- var _easemobWebsdk = _interopRequireDefault(require("easemob-websdk"));
30
- var _user = require("../utilities/user");
31
- var _error = require("../utilities/error");
32
- var _type = require("../room-control/chatroom-control/type");
33
- var _type2 = require("../chat-connection/type");
34
- var _logger = require("../utilities/logger");
35
- var _validateParams = _interopRequireDefault(require("../utilities/validate-params"));
36
- var _schema = require("../schema");
37
- let _initProto, _sendMessageDecs;
38
- 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)]; } }; }
39
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
40
- 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); }
41
- 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; }
42
- 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; }
43
- /**
44
- * @internal
45
- */
46
- class FcrChatRoomControlImpl {
47
- static {
48
- [_initProto] = _applyDecs(this, [[_imports.trace, 2, "join"], [_imports.trace, 2, "getConnectionState"], [_imports.trace, 2, "leave"], [_sendMessageDecs, 2, "sendMessage"], [_imports.trace, 2, "addObserver"], [_imports.trace, 2, "removeObserver"]], []).e;
49
- }
50
- [(_sendMessageDecs = [_imports.trace, (0, _validateParams.default)(_schema.messageSchema, _schema.progressSchema.optional())], "logger")] = (_initProto(this), (0, _logger.createLogger)({
51
- prefix: 'FcrChatRoomControlImpl'
52
- }));
53
- _observable = new _observable.AgoraObservable();
54
- _connectionState = _type.FcrChatRoomConnectionState.Disconnected;
55
- _sceneObserver = {
56
- onJoinSceneSuccess: () => this._handleJoinSceneSuccess(),
57
- onJoinSceneFailure: () => this._handleJoinSceneFailure()
58
- };
59
- _chatConnectionObserver = {
60
- onConnectionStateUpdated: async state => {
61
- // im reconnect
62
- this.logger.info(`onConnectionStateUpdated, chatConnectionState: ${state}, chatControlState: ${this.getConnectionState()}`);
63
- if (state === _type2.FcrChatConnectionState.DISCONNECTED && this.getConnectionState() === _type.FcrChatRoomConnectionState.Connected) {
64
- this._setConnectionState(_type.FcrChatRoomConnectionState.Disconnected);
65
- } else if (state === _type2.FcrChatConnectionState.CONNECTED && this.getConnectionState() !== _type.FcrChatRoomConnectionState.Connected) {
66
- this._removeEventListener();
67
- this._addEventListener();
68
- await this._joinChatRoom(state);
69
- }
70
- },
71
- onConnectionLoginSuccess: () => {
72
- this._addEventListener();
73
- }
74
- };
75
- get conn() {
76
- if (!this._chatConnection.getConnectionInstance()) {
77
- throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'chat room connection not initialized, please get chat room token first', new Error('chat room connection not initialized, please get chat room token first'));
78
- }
79
- return this._chatConnection.getConnectionInstance();
80
- }
81
- get chatRoomId() {
82
- if (!this._joinSceneSuccess) {
83
- return '';
84
- }
85
- return this._scene.getScenePropertiesByKeyPath('widgets.easemobIM.extra.chatRoomId');
86
- }
87
- constructor(_scene, _chatConnection, sharedCache, joinSceneSuccess) {
88
- this._scene = _scene;
89
- this._chatConnection = _chatConnection;
90
- this._roomCache = sharedCache.getRoomCache(_scene.sceneId);
91
- this._joinSceneSuccess = joinSceneSuccess;
92
- this._addLogObserver();
93
- this._chatConnection.addObserver(this._chatConnectionObserver);
94
- if (this._chatConnection.getConnectionInstance()) {
95
- this._addEventListener();
96
- }
97
- }
98
- async join() {
99
- await this._joinChatRoom(this._chatConnection.getConnectionState());
100
- }
101
- getConnectionState() {
102
- return this._connectionState;
103
- }
104
- async leave() {
105
- if (!this._chatConnection.getConnectionInstance()) {
106
- return;
107
- }
108
- this._chatConnection.removeObserver(this._chatConnectionObserver);
109
- await new Promise(async (resolve, reject) => {
110
- this._removeEventListener();
111
- try {
112
- await this.conn.leaveChatRoom({
113
- roomId: this.chatRoomId,
114
- success: () => {
115
- resolve(undefined);
116
- },
117
- error: e => {
118
- reject((0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'leave chat room failed', e));
119
- }
120
- });
121
- } catch (e) {
122
- resolve(undefined);
123
- }
124
- });
125
- }
126
- _joinChatRoom = async state => {
127
- this.logger.info(`joinChatRoom, chatConnectionState: ${state}, chatControlState: ${this.getConnectionState()}`);
128
- if (state === _type2.FcrChatConnectionState.CONNECTED && this.getConnectionState() === _type.FcrChatRoomConnectionState.Disconnected && this.chatRoomId) {
129
- this._setConnectionState(_type.FcrChatRoomConnectionState.Connecting);
130
- this.logger.info(`start join chat room, room id: ${this.chatRoomId}, scene id: ${this._scene.sceneId}`);
131
- let error = null;
132
- [error] = await (0, _imports.to)((0, _imports.retryAttempt)(async () => {
133
- await this.conn.joinChatRoom({
134
- roomId: this.chatRoomId
135
- });
136
- }, [], {
137
- retriesMax: 4
138
- }).fail(async ({
139
- error,
140
- timeFn,
141
- currentRetry
142
- }) => {
143
- this.logger.error(`retry to join chat room, ${error.message}, retry ${currentRetry} times`);
144
- await timeFn();
145
- return true;
146
- }).exec());
147
- if (error) {
148
- this._setConnectionState(_type.FcrChatRoomConnectionState.Disconnected);
149
- throw error;
150
- }
151
- this._setConnectionState(_type.FcrChatRoomConnectionState.Connected);
152
- }
153
- };
154
- _removeEventListener() {
155
- this._scene.removeObserver(this._sceneObserver);
156
- this.conn.removeEventHandler(`chatroom${this._scene.sceneId}`);
157
- }
158
- _addEventListener() {
159
- this._removeEventListener();
160
- this._scene.addObserver(this._sceneObserver);
161
- this.conn.addEventHandler(`chatroom${this._scene.sceneId}`, {
162
- onTextMessage: msg => {
163
- if (msg.to !== this.chatRoomId) {
164
- return;
165
- }
166
- const message = this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(msg);
167
- this._observable.notifyObservers('onTextMessageReceived', this._scene.sceneId, message);
168
- }
169
- });
170
- this.conn.onPictureMessage = msg => {
171
- if (msg.to !== this.chatRoomId) {
172
- return;
173
- }
174
- // 这里的数据结构和 onTextMessage 不一样,实际上contentsType是img ,type是chatroom,
175
- // 但是因为在onPictureMessage的回调中,所以这里直接用type: 'img',后续可以考虑优化
176
- const message = this._convertAgoraChatMessageToFcrChatRoomReceiveMessage({
177
- ...msg,
178
- type: 'img'
179
- });
180
- this._observable.notifyObservers('onImageMessageReceived', this._scene.sceneId, message);
181
- };
182
-
183
- // TODO: 3.x
184
- // this.conn.onCmdMessage = (msg) => {
185
- // if (msg.to !== this.initConfig.chatRoomId) {
186
- // return;
187
- // }
188
- // const message: FcrChatRoomReceiveCustomMessage =
189
- // this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(msg);
190
- // this._observable.notifyObservers('onCustomMessageReceived', this._scene.sceneId, message);
191
- // };
192
-
193
- // TODO: 3.x
194
- // this.conn.onChatroomEvent = (eventData: EasemobChat.ChatroomEvent) => {
195
- // if (eventData.operation === 'updateAnnouncement') {
196
- // this._observable.notifyObservers(
197
- // 'onAnnouncementUpdated',
198
- // this._scene.sceneId,
199
- // // TODO: 应该用什么字段传递?
200
- // (eventData.attributes as { [key: string]: string })?.announcement,
201
- // );
202
- // } else if (eventData.operation === 'deleteAnnouncement') {
203
- // this._observable.notifyObservers('onAnnouncementDeleted', this._scene.sceneId);
204
- // }
205
- // };
206
- }
207
- _convertAgoraChatMessageToFcrChatRoomReceiveMessage = msg => {
208
- // TODO: 没看到有 contentsType 字段
209
- //@ts-ignore
210
- switch (msg.type) {
211
- case 'txt':
212
- {
213
- const message = {
214
- id: msg.id,
215
- //@ts-ignore
216
- from: msg.ext.sender,
217
- type: _type.FcrChatRoomMessageType.Text,
218
- //@ts-ignore
219
- timestamp: parseInt(msg.time),
220
- //@ts-ignore
221
- content: msg.msg,
222
- isPrivate: msg.ext?.isPrivate,
223
- properties: msg.ext?.properties
224
- };
225
- return message;
226
- }
227
- case 'img':
228
- {
229
- const message = {
230
- id: msg.id,
231
- from: msg.ext?.sender,
232
- type: _type.FcrChatRoomMessageType.Image,
233
- //@ts-ignore
234
- timestamp: parseInt(msg.time),
235
- url: msg.url || '',
236
- isPrivate: msg.ext?.isPrivate,
237
- properties: msg.ext?.properties
238
- };
239
- return message;
240
- }
241
- }
242
- throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type', new Error('unknown remote message type'));
243
- };
244
- _convertAgoraChatHistoryMessageToFcrChatRoomReceiveMessage = msg => {
245
- // TODO: 没看到有 contentsType 字段
246
- //@ts-ignore
247
- switch (msg.contentsType) {
248
- case 'TEXT':
249
- {
250
- const message = {
251
- id: msg.id,
252
- //@ts-ignore
253
- from: msg.ext.sender,
254
- type: _type.FcrChatRoomMessageType.Text,
255
- //@ts-ignore
256
- timestamp: parseInt(msg.time),
257
- //@ts-ignore
258
- content: msg.data,
259
- //@ts-ignore
260
- isPrivate: msg.ext.isPrivate,
261
- //@ts-ignore
262
- properties: msg.ext?.properties
263
- };
264
- return message;
265
- }
266
- case 'IMAGE':
267
- {
268
- const message = {
269
- id: msg.id,
270
- //@ts-ignore
271
- from: msg.ext?.sender,
272
- type: _type.FcrChatRoomMessageType.Image,
273
- //@ts-ignore
274
- timestamp: parseInt(msg.time),
275
- //@ts-ignore
276
- url: msg.url || '',
277
- //@ts-ignore
278
- isPrivate: msg.ext?.isPrivate,
279
- //@ts-ignore
280
- properties: msg.ext?.properties
281
- };
282
- return message;
283
- }
284
- }
285
- throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type', new Error('unknown remote message type'));
286
- };
287
- _convertFcrChatRoomSendBaseMessageToAgoraChatMessage = (msg, progress) => {
288
- switch (msg.type) {
289
- case _type.FcrChatRoomMessageType.Text:
290
- {
291
- const message = msg;
292
- const isPrivate = !!message.to?.length;
293
- const localUserId = this._scene.getLocalUser().getLocalUserId();
294
- const localUserInfo = this._scene.getUser(localUserId);
295
- return _easemobWebsdk.default.message.create({
296
- to: this.chatRoomId,
297
- msg: message.content,
298
- type: 'txt',
299
- chatType: 'chatRoom',
300
- ext: {
301
- sender: (0, _user.convertRteUserToFcrUser)(localUserInfo, this._roomCache),
302
- roomUuid: this._scene.sceneId,
303
- isPrivate,
304
- properties: msg.properties
305
- },
306
- receiverList: message.to
307
- });
308
- }
309
- case _type.FcrChatRoomMessageType.Image:
310
- {
311
- const imageMessage = msg;
312
- const isPrivateImage = !!imageMessage.to?.length;
313
- const localUser = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
314
- return _easemobWebsdk.default.message.create({
315
- to: this.chatRoomId,
316
- type: 'img',
317
- chatType: 'chatRoom',
318
- url: imageMessage.file.filePath,
319
- file: {
320
- filename: imageMessage.file.fileName,
321
- filetype: imageMessage.file.fileType,
322
- data: imageMessage.file.data,
323
- url: ''
324
- },
325
- ext: {
326
- sender: (0, _user.convertRteUserToFcrUser)(localUser, this._roomCache),
327
- roomUuid: this._scene.sceneId,
328
- isPrivate: isPrivateImage,
329
- properties: msg.properties
330
- },
331
- receiverList: imageMessage.to,
332
- onFileUploadProgress: e => {
333
- progress?.(Math.round(e.loaded / e.total * 100));
334
- }
335
- });
336
- }
337
- }
338
- throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown local message type', new Error('unknown local message type'));
339
- };
340
- async sendMessage(message, progress) {
341
- const msg = this._convertFcrChatRoomSendBaseMessageToAgoraChatMessage(message, progress);
342
- const sendMsgRes = await this.conn.send(msg);
343
- const localUserInfo = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
344
- const res = {
345
- ...(message.type === _type.FcrChatRoomMessageType.Text ? {
346
- content: message.content
347
- } :
348
- // @ts-ignore
349
- {
350
- url: sendMsgRes.message.url
351
- }),
352
- from: (0, _user.convertRteUserToFcrUser)(localUserInfo, this._roomCache),
353
- id: sendMsgRes.serverMsgId,
354
- type: message.type,
355
- properties: message.properties,
356
- timestamp: Date.now(),
357
- isPrivate: !!message.to?.length
358
- };
359
- return res;
360
- }
361
- addObserver(observer) {
362
- this._observable.addObserver(observer);
363
- }
364
- removeObserver(observer) {
365
- this._observable.removeObserver(observer);
366
- }
367
- _setConnectionState(state) {
368
- this._connectionState = state;
369
- this._observable.notifyObservers('onConnectionStateUpdated', this._scene.sceneId, state);
370
- }
371
- _addLogObserver() {
372
- this.addObserver((0, _logger.generateLogObserver)(this.logger, ['onConnectionStateUpdated', 'onErrorOccurred'
373
- // 'onTextMessageReceived'
374
- ]));
375
- }
376
- async getHistoryMessageList(pageSize, startedMessageId) {
377
- if (pageSize > 50) {
378
- throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'pageSize should be less than 50', new Error('pageSize should be less than 50'));
379
- }
380
- const assembleRet = await this.conn.fetchHistoryMessages({
381
- queue: this.chatRoomId,
382
- count: pageSize,
383
- start: startedMessageId,
384
- isGroup: true,
385
- fail(error) {
386
- throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, error.message, new Error('get history message list failed'));
387
- }
388
- });
389
- const ret = assembleRet.map(msgBody => {
390
- return this._convertAgoraChatHistoryMessageToFcrChatRoomReceiveMessage(msgBody);
391
- });
392
- return ret;
393
- }
394
- _handleJoinSceneSuccess = () => {
395
- this._joinSceneSuccess = true;
396
- this._joinChatRoom(this._chatConnection.getConnectionState());
397
- };
398
- _handleJoinSceneFailure = () => {
399
- this._joinSceneSuccess = false;
400
- };
401
-
402
- // TODO: 3.x
403
- // async getAnnouncement(): Promise<string> {
404
- // const announcement = await this.conn.fetchChatRoomAnnouncement({
405
- // roomId: this.initConfig.chatRoomId,
406
- // error: (e) => {
407
- // throw generateFcrCoreClientError(
408
- // FcrErrorModuleCode.ROOM_CHATROOM,
409
- // FcrErrorCode.UNDEFINED_ERROR,
410
- // e.message,
411
- // new Error('get announcement failed'),
412
- // );
413
- // },
414
- // });
415
-
416
- // return announcement.data?.announcement || '';
417
- // }
418
-
419
- // TODO: 3.x
420
- // async setAnnouncement(announcement: string) {
421
- // await this.conn.updateChatRoomAnnouncement({
422
- // roomId: this.initConfig.chatRoomId,
423
- // announcement,
424
- // success: (_) => {},
425
- // error: (e) => {
426
- // throw generateFcrCoreClientError(
427
- // FcrErrorModuleCode.ROOM_CHATROOM,
428
- // FcrErrorCode.UNDEFINED_ERROR,
429
- // e.message,
430
- // new Error('set announcement failed'),
431
- // );
432
- // },
433
- // });
434
- // }
435
-
436
- // TODO: 3.x
437
- // async deleteAnnouncement() {
438
- // await this.conn.updateChatRoomAnnouncement({
439
- // roomId: this.initConfig.chatRoomId,
440
- // announcement: '',
441
- // success: (_) => {},
442
- // error: (e) => {
443
- // const { message } = e;
444
- // throw generateFcrCoreClientError(
445
- // FcrErrorModuleCode.ROOM_CHATROOM,
446
- // FcrErrorCode.UNDEFINED_ERROR,
447
- // message,
448
- // new Error('delete announcement failed'),
449
- // );
450
- // },
451
- // });
452
- // }
453
- }
454
- exports.FcrChatRoomControlImpl = FcrChatRoomControlImpl;
@@ -1,51 +0,0 @@
1
- /**
2
- * git do not control webim.config.js
3
- * everyone should copy webim.config.js.demo to webim.config.js
4
- * and have their own configs.
5
- * In this way , others won't be influenced by this config while git pull.
6
- */
7
- declare const agoraChatConfig: {
8
- Host: string;
9
- https: boolean;
10
- isHttpDNS: boolean;
11
- isMultiLoginSessions: boolean;
12
- /**
13
- * @parameter {Boolean} true or false
14
- */
15
- isSandBox: boolean;
16
- /**
17
- * Whether to console.log
18
- * @parameter {Boolean} true or false
19
- */
20
- isDebug: boolean;
21
- /**
22
- * will auto connect the websocket server autoReconnectNumMax times in background when client is offline.
23
- * won't auto connect if autoReconnectNumMax=0.
24
- */
25
- autoReconnectNumMax: number;
26
- /**
27
- * webrtc supports WebKit and https only
28
- */
29
- useOwnUploadFun: boolean;
30
- isAutoLogin: boolean;
31
- /**
32
- * Size of message cache for person to person
33
- */
34
- p2pMessageCacheSize: number;
35
- /**
36
- * When a message arrived, the receiver send an ack message to the
37
- * sender, in order to tell the sender the message has delivered.
38
- * See call back function onReceivedMessage
39
- */
40
- delivery: boolean;
41
- /**
42
- * Size of message cache for group chating like group, chatroom etc. For use in this demo
43
- */
44
- groupMessageCacheSize: number;
45
- /**
46
- * enable localstorage for history messages. For use in this demo
47
- */
48
- enableLocalStorage: boolean;
49
- deviceId: string;
50
- };
51
- export { agoraChatConfig };
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.agoraChatConfig = void 0;
7
- /**
8
- * git do not control webim.config.js
9
- * everyone should copy webim.config.js.demo to webim.config.js
10
- * and have their own configs.
11
- * In this way , others won't be influenced by this config while git pull.
12
- */
13
-
14
- // for react native
15
- // var location = {
16
- // protocol: "https"
17
- // }
18
-
19
- const agoraChatConfig = exports.agoraChatConfig = {
20
- /*
21
- * websocket server
22
- * im-api-v2.easemob.com/ws 线上环境
23
- * im-api-v2-hsb.easemob.com/ws 沙箱环境
24
- */
25
- // socketServer: getUrl().socketUrl, //(window.location.protocol === "https:" ? "https:" : "http:") + "//im-api-v2.easemob.com/ws",
26
- /*
27
- * Backend REST API URL
28
- * a1.easemob.com 线上环境
29
- * a1-hsb.easemob.com 沙箱环境
30
- */
31
- // restServer: getUrl().apiUrl, //(window.location.protocol === "https:" ? "https:" : "http:") + "//a1.easemob.com",
32
- /*
33
- * Application AppKey
34
- */
35
- // appkey: 'easemob-demo#cloudclass',
36
- /*
37
- * Application Host
38
- */
39
- Host: 'easemob.com',
40
- /*
41
- * Whether to use HTTPS
42
- * @parameter {Boolean} true or false
43
- */
44
- https: true,
45
- /*
46
- * 公有云配置默认为 true,
47
- * 私有云配置请设置 isHttpDNS = false , 详细文档:http://docs-im.easemob.com/im/web/other/privatedeploy
48
- */
49
- isHttpDNS: true,
50
- /*
51
- * isMultiLoginSessions
52
- * true: A visitor can sign in to multiple webpages and receive messages at all the webpages.
53
- * false: A visitor can sign in to only one webpage and receive messages at the webpage.
54
- */
55
- isMultiLoginSessions: true,
56
- /**
57
- * @parameter {Boolean} true or false
58
- */
59
- isSandBox: false,
60
- //内部测试环境,集成时设为false
61
- /**
62
- * Whether to console.log
63
- * @parameter {Boolean} true or false
64
- */
65
- isDebug: true,
66
- /**
67
- * will auto connect the websocket server autoReconnectNumMax times in background when client is offline.
68
- * won't auto connect if autoReconnectNumMax=0.
69
- */
70
- autoReconnectNumMax: 10,
71
- /**
72
- * webrtc supports WebKit and https only
73
- */
74
- // isWebRTC: window.RTCPeerConnection && /^https\:$/.test(window.location.protocol),
75
- /*
76
- * Upload pictures or file to your own server and send message with url
77
- * @parameter {Boolean} true or false
78
- * true: Using the API provided by SDK to upload file to huanxin server
79
- * false: Using your method to upload file to your own server
80
- */
81
- useOwnUploadFun: false,
82
- /*
83
- * Set to auto sign-in
84
- */
85
- isAutoLogin: false,
86
- /**
87
- * Size of message cache for person to person
88
- */
89
- p2pMessageCacheSize: 500,
90
- /**
91
- * When a message arrived, the receiver send an ack message to the
92
- * sender, in order to tell the sender the message has delivered.
93
- * See call back function onReceivedMessage
94
- */
95
- delivery: false,
96
- /**
97
- * Size of message cache for group chating like group, chatroom etc. For use in this demo
98
- */
99
- groupMessageCacheSize: 200,
100
- /**
101
- * enable localstorage for history messages. For use in this demo
102
- */
103
- enableLocalStorage: true,
104
- deviceId: 'webim'
105
- };
@@ -1,8 +0,0 @@
1
- declare class LocalStorage {
2
- set(key: string, value: string | object): void;
3
- get(key: string): string | null;
4
- remove(key: string): void;
5
- clear(): void;
6
- }
7
- export declare const storage: LocalStorage;
8
- export {};
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.storage = void 0;
7
- require("core-js/modules/es.json.stringify.js");
8
- class LocalStorage {
9
- set(key, value) {
10
- if (typeof value === 'object') {
11
- value = JSON.stringify(value);
12
- }
13
- // fix harmony build error
14
- // @ts-ignore
15
- localStorage.setItem(key, value);
16
- }
17
- get(key) {
18
- // fix harmony build error
19
- // @ts-ignore
20
- return localStorage.getItem(key);
21
- }
22
- remove(key) {
23
- // fix harmony build error
24
- // @ts-ignore
25
- localStorage.removeItem(key);
26
- }
27
- clear() {
28
- // fix harmony build error
29
- // @ts-ignore
30
- localStorage.clear();
31
- }
32
- }
33
- const storage = exports.storage = new LocalStorage();