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