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.
- package/lib/chat-connector/type.d.ts +40 -0
- package/lib/{chat-connection → chat-connector}/type.js +1 -1
- package/lib/engine/index.d.ts +10 -11
- package/lib/engine/index.js +63 -72
- package/lib/engine/type.d.ts +96 -0
- package/lib/engine/type.js +5 -0
- package/lib/imports.d.ts +7 -4
- package/lib/imports.js +30 -4
- package/lib/index.d.ts +3 -2
- package/lib/index.js +21 -2
- package/lib/media-control/desktop.js +12 -12
- package/lib/media-control/mobile.js +4 -0
- package/lib/media-control/type.d.ts +32 -33
- package/lib/monitor-control/index.js +3 -3
- package/lib/peer-session/index.js +14 -14
- package/lib/peer-session/type.d.ts +1 -1
- package/lib/plugins/chat/chatroom.js +417 -0
- package/lib/{chat-connection → plugins/chat}/config.d.ts +1 -0
- package/lib/{chat-connection → plugins/chat}/config.js +2 -1
- package/lib/plugins/chat/connector.d.ts +38 -0
- package/lib/{chat-connection/index.js → plugins/chat/connector.js} +181 -61
- package/lib/room-control/ability-control/index.js +5 -4
- package/lib/room-control/ability-control/type.d.ts +5 -1
- package/lib/room-control/ability-control/type.js +4 -0
- package/lib/room-control/chatroom-control/type.d.ts +44 -35
- package/lib/room-control/group-control/index.js +9 -9
- package/lib/room-control/index.js +37 -22
- package/lib/room-control/interpreter-control/index.js +7 -4
- package/lib/room-control/interpreter-control/room.js +3 -3
- package/lib/room-control/interpreter-control/types.d.ts +2 -2
- package/lib/room-control/join-before-host-waitingroom-control/index.js +3 -3
- package/lib/room-control/mainroom-control/index.js +15 -13
- package/lib/room-control/privilege-control/index.js +39 -24
- package/lib/room-control/privilege-control/type.d.ts +15 -15
- package/lib/room-control/room-connector-control/index.js +7 -5
- package/lib/room-control/room-connector-control/type.d.ts +1 -1
- package/lib/room-control/room-control-factory.d.ts +3 -3
- package/lib/room-control/room-control-factory.js +7 -7
- package/lib/room-control/room-session/index.js +17 -15
- package/lib/room-control/room-session/type.d.ts +3 -3
- package/lib/room-control/sharing-control/index.js +13 -7
- package/lib/room-control/stream-control/index.js +18 -16
- package/lib/room-control/stream-control/type.d.ts +5 -5
- package/lib/room-control/stt-control/index.js +38 -31
- package/lib/room-control/type.d.ts +19 -19
- package/lib/room-control/user-control/index.js +20 -22
- package/lib/room-control/user-control/type.d.ts +1 -1
- package/lib/room-control/waitingroom-control/index.js +11 -11
- package/lib/room-control/whiteboard-control-v1/board-window.d.ts +21 -20
- package/lib/room-control/whiteboard-control-v1/board-window.js +27 -8
- package/lib/room-control/whiteboard-control-v1/factory.js +1 -1
- package/lib/room-control/whiteboard-control-v1/index.js +26 -18
- package/lib/room-control/whiteboard-control-v1/type.d.ts +26 -25
- package/lib/room-control/whiteboard-control-v1/type.js +1 -0
- package/lib/room-control/whiteboard-control-v2/annotation-control/control.d.ts +15 -6
- package/lib/room-control/whiteboard-control-v2/annotation-control/control.js +39 -5
- package/lib/room-control/whiteboard-control-v2/annotation-control/factory.d.ts +4 -5
- package/lib/room-control/whiteboard-control-v2/annotation-control/factory.js +6 -5
- package/lib/room-control/whiteboard-control-v2/annotation-control/type.d.ts +7 -1
- package/lib/room-control/whiteboard-control-v2/base/index.d.ts +9 -8
- package/lib/room-control/whiteboard-control-v2/base/index.js +84 -42
- package/lib/room-control/whiteboard-control-v2/base/main-window.d.ts +16 -15
- package/lib/room-control/whiteboard-control-v2/base/main-window.js +23 -4
- package/lib/room-control/whiteboard-control-v2/type.d.ts +17 -17
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.d.ts +12 -6
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.js +64 -18
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/factory.d.ts +2 -2
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/factory.js +10 -10
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/type.d.ts +1 -1
- package/lib/room-router/index.js +10 -7
- package/lib/room-router/type.d.ts +1 -1
- package/lib/schema.d.ts +24 -46
- package/lib/schema.js +1 -2
- package/lib/service/api.d.ts +5 -3
- package/lib/service/api.js +17 -12
- package/lib/type.d.ts +64 -45
- package/lib/type.js +76 -11
- package/lib/utilities/abortable-retry.d.ts +38 -0
- package/lib/utilities/abortable-retry.js +61 -0
- package/lib/utilities/dual-video-stream-config.d.ts +6 -0
- package/lib/utilities/dual-video-stream-config.js +25 -0
- package/lib/utilities/error-helpers.d.ts +10 -9
- package/lib/utilities/error-helpers.js +12 -11
- package/lib/utilities/error.d.ts +4 -40
- package/lib/utilities/error.js +20 -77
- package/lib/utilities/join-helper.js +2 -2
- package/lib/utilities/logger.d.ts +2 -2
- package/lib/utilities/logger.js +6 -25
- package/lib/utilities/package-info.d.ts +1 -2
- package/lib/utilities/package-info.js +4 -8
- package/lib/utilities/parameters.js +88 -15
- package/lib/utilities/validate-params.js +1 -1
- package/lib/utilities/video-encoder-config.d.ts +9 -0
- package/lib/utilities/video-encoder-config.js +109 -0
- package/lib-es/{chat-connection → chat-connector}/type.js +1 -1
- package/lib-es/engine/index.js +46 -56
- package/lib-es/engine/type.js +1 -0
- package/lib-es/imports.js +5 -3
- package/lib-es/index.js +2 -1
- package/lib-es/media-control/desktop.js +12 -12
- package/lib-es/media-control/mobile.js +4 -0
- package/lib-es/monitor-control/index.js +3 -3
- package/lib-es/peer-session/index.js +16 -15
- package/lib-es/plugins/chat/chatroom.js +409 -0
- package/lib-es/{chat-connection → plugins/chat}/config.js +2 -1
- package/lib-es/{chat-connection/index.js → plugins/chat/connector.js} +178 -58
- package/lib-es/room-control/ability-control/index.js +5 -4
- package/lib-es/room-control/ability-control/type.js +4 -0
- package/lib-es/room-control/group-control/index.js +11 -10
- package/lib-es/room-control/index.js +40 -26
- package/lib-es/room-control/interpreter-control/index.js +10 -5
- package/lib-es/room-control/interpreter-control/room.js +3 -3
- package/lib-es/room-control/join-before-host-waitingroom-control/index.js +4 -3
- package/lib-es/room-control/mainroom-control/index.js +16 -17
- package/lib-es/room-control/privilege-control/index.js +43 -29
- package/lib-es/room-control/room-connector-control/index.js +9 -6
- package/lib-es/room-control/room-control-factory.js +6 -6
- package/lib-es/room-control/room-session/index.js +21 -22
- package/lib-es/room-control/sharing-control/index.js +13 -7
- package/lib-es/room-control/stream-control/index.js +21 -18
- package/lib-es/room-control/stt-control/index.js +23 -15
- package/lib-es/room-control/user-control/index.js +23 -23
- package/lib-es/room-control/waitingroom-control/index.js +10 -9
- package/lib-es/room-control/whiteboard-control-v1/board-window.js +27 -8
- package/lib-es/room-control/whiteboard-control-v1/factory.js +1 -1
- package/lib-es/room-control/whiteboard-control-v1/index.js +26 -17
- package/lib-es/room-control/whiteboard-control-v1/type.js +1 -0
- package/lib-es/room-control/whiteboard-control-v2/annotation-control/control.js +39 -5
- package/lib-es/room-control/whiteboard-control-v2/annotation-control/factory.js +7 -6
- package/lib-es/room-control/whiteboard-control-v2/base/index.js +86 -42
- package/lib-es/room-control/whiteboard-control-v2/base/main-window.js +23 -4
- package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/control.js +60 -13
- package/lib-es/room-control/whiteboard-control-v2/whiteboard-control/factory.js +10 -10
- package/lib-es/room-router/index.js +10 -6
- package/lib-es/schema.js +1 -2
- package/lib-es/service/api.js +17 -12
- package/lib-es/type.js +70 -18
- package/lib-es/utilities/abortable-retry.js +54 -0
- package/lib-es/utilities/dual-video-stream-config.js +19 -0
- package/lib-es/utilities/error-helpers.js +13 -12
- package/lib-es/utilities/error.js +9 -75
- package/lib-es/utilities/join-helper.js +4 -3
- package/lib-es/utilities/logger.js +7 -23
- package/lib-es/utilities/package-info.js +4 -6
- package/lib-es/utilities/parameters.js +88 -15
- package/lib-es/utilities/validate-params.js +3 -2
- package/lib-es/utilities/video-encoder-config.js +103 -0
- package/package.json +7 -7
- package/lib/chat-connection/index.d.ts +0 -24
- package/lib/chat-connection/type.d.ts +0 -17
- package/lib/plugins/chatroom.js +0 -454
- package/lib/room-control/chatroom-control/config.d.ts +0 -51
- package/lib/room-control/chatroom-control/config.js +0 -105
- package/lib/utilities/storage.d.ts +0 -8
- package/lib/utilities/storage.js +0 -33
- package/lib-es/plugins/chatroom.js +0 -446
- package/lib-es/room-control/chatroom-control/config.js +0 -100
- package/lib-es/utilities/storage.js +0 -27
- /package/lib/plugins/{chatroom.d.ts → chat/chatroom.d.ts} +0 -0
|
@@ -0,0 +1,409 @@
|
|
|
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, _addObserverDecs, _removeObserverDecs;
|
|
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 { bound, trace } from 'agora-foundation/lib/decorator';
|
|
27
|
+
import { timeout } from 'agora-foundation/lib/utilities/race-condition';
|
|
28
|
+
import { AgoraObservable } from 'agora-foundation/lib/utilities/observable';
|
|
29
|
+
import EasemobChatSDK from 'easemob-websdk';
|
|
30
|
+
import get from 'lodash/get';
|
|
31
|
+
import { FcrChatConnectionState } from '../../chat-connector/type';
|
|
32
|
+
import { DetailErrorCode, ErrorModuleCode } from '../../imports';
|
|
33
|
+
import { FcrChatRoomConnectionState, FcrChatRoomMessageType } from '../../room-control/chatroom-control/type';
|
|
34
|
+
import { messageSchema, progressSchema } from '../../schema';
|
|
35
|
+
import { FcrReturnCode } from '../../type';
|
|
36
|
+
import { abortableRetry } from '../../utilities/abortable-retry';
|
|
37
|
+
import { FcrErrorCode, FcrErrorModuleCode, generateFcrCoreClientError } from '../../utilities/error';
|
|
38
|
+
import { createLogger, generateLogObserver } from '../../utilities/logger';
|
|
39
|
+
import { convertRteUserToFcrUser } from '../../utilities/user';
|
|
40
|
+
import validateParams from '../../utilities/validate-params';
|
|
41
|
+
const CHATROOM_ID_KEY_PATH = 'widgets.easemobIM.extra.chatRoomId';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export class FcrChatRoomControlImpl {
|
|
47
|
+
static {
|
|
48
|
+
[_initProto] = _applyDecs(this, [[trace, 2, "getConnectionState"], [_sendMessageDecs, 2, "sendMessage"], [_addObserverDecs, 2, "addObserver"], [_removeObserverDecs, 2, "removeObserver"], [bound, 2, "_handleJoinSceneSuccess"], [bound, 2, "_handleJoinSceneFailure"], [trace, 2, "leave"], [trace, 2, "join"], [bound, 2, "_handleScenePropertiesUpdated"]], []).e;
|
|
49
|
+
}
|
|
50
|
+
[(_sendMessageDecs = [trace(['message', 'progress']), validateParams(messageSchema, progressSchema.optional())], _addObserverDecs = trace(['observer']), _removeObserverDecs = trace(['observer']), "logger")] = (_initProto(this), createLogger({
|
|
51
|
+
prefix: 'FcrChatRoomControlImpl'
|
|
52
|
+
}));
|
|
53
|
+
_observable = new AgoraObservable();
|
|
54
|
+
_connectionState = FcrChatRoomConnectionState.Disconnected;
|
|
55
|
+
_joinPromise = null;
|
|
56
|
+
_joinTimeoutMs = 30000;
|
|
57
|
+
_joinAttemptId = 0;
|
|
58
|
+
_abortJoinChatRoom = null;
|
|
59
|
+
_sceneObserver = {
|
|
60
|
+
onJoinSceneSuccess: this._handleJoinSceneSuccess,
|
|
61
|
+
onJoinSceneFailure: this._handleJoinSceneFailure,
|
|
62
|
+
onScenePropertiesUpdated: this._handleScenePropertiesUpdated
|
|
63
|
+
};
|
|
64
|
+
chatRoomConnectionHandler = {
|
|
65
|
+
onTextMessage: msg => {
|
|
66
|
+
if (msg.to !== this.chatRoomId) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const message = this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(msg);
|
|
70
|
+
this._observable.notifyObservers('onTextMessageReceived', this._scene.sceneId, message);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
_chatConnectionObserver = {
|
|
74
|
+
onConnectionStateUpdated: async connectorState => {
|
|
75
|
+
const chatRoomConnectionState = this.getConnectionState();
|
|
76
|
+
if (connectorState === FcrChatConnectionState.DISCONNECTED) {
|
|
77
|
+
this._setConnectionState(FcrChatRoomConnectionState.Disconnected);
|
|
78
|
+
} else if (connectorState === FcrChatConnectionState.CONNECTED && chatRoomConnectionState !== FcrChatRoomConnectionState.Connected) {
|
|
79
|
+
this.logger.info('chat connector connected, try to join chat room');
|
|
80
|
+
this._tryJoinChatRoom();
|
|
81
|
+
} else if (connectorState === FcrChatConnectionState.CONNECTED) {
|
|
82
|
+
this.logger.info('chat connector reconnected, try to rejoin chat room');
|
|
83
|
+
this._tryJoinChatRoom(true);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
get conn() {
|
|
88
|
+
if (!this._chatConnection.getConnectionInstance()) {
|
|
89
|
+
throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM_CHATROOM, DetailErrorCode.UNDEFINED_ERROR, 'chat room connection not initialized, please get chat room token first');
|
|
90
|
+
}
|
|
91
|
+
return this._chatConnection.getConnectionInstance();
|
|
92
|
+
}
|
|
93
|
+
get chatRoomId() {
|
|
94
|
+
if (!this._joinSceneSuccess) {
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
return this._scene.getScenePropertiesByKeyPath(CHATROOM_ID_KEY_PATH);
|
|
98
|
+
}
|
|
99
|
+
get connectionEventHandlerKey() {
|
|
100
|
+
return `chatroom${this._scene.sceneId}`;
|
|
101
|
+
}
|
|
102
|
+
constructor(_scene, _chatConnection, sharedCache, joinSceneSuccess) {
|
|
103
|
+
this._scene = _scene;
|
|
104
|
+
this._chatConnection = _chatConnection;
|
|
105
|
+
this._roomCache = sharedCache.getRoomCache(_scene.sceneId);
|
|
106
|
+
this._joinSceneSuccess = joinSceneSuccess;
|
|
107
|
+
this._addLogObserver();
|
|
108
|
+
this._scene.addObserver(this._sceneObserver);
|
|
109
|
+
if (this._chatConnection.getConnectionInstance() && this._chatConnection.getConnectionState() === FcrChatConnectionState.CONNECTED) {
|
|
110
|
+
this.logger.info('chat connection already connected, try to join chat room');
|
|
111
|
+
this._tryJoinChatRoom();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
getConnectionState() {
|
|
115
|
+
return this._connectionState;
|
|
116
|
+
}
|
|
117
|
+
async sendMessage(message, progress) {
|
|
118
|
+
const msg = this._convertFcrChatRoomSendBaseMessageToAgoraChatMessage(message, progress);
|
|
119
|
+
const sendMsgRes = await this.conn.send(msg);
|
|
120
|
+
const localUserInfo = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
|
|
121
|
+
const res = {
|
|
122
|
+
...(message.type === FcrChatRoomMessageType.Text ? {
|
|
123
|
+
content: message.content
|
|
124
|
+
} :
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
{
|
|
127
|
+
url: sendMsgRes.message.url
|
|
128
|
+
}),
|
|
129
|
+
from: convertRteUserToFcrUser(localUserInfo, this._roomCache),
|
|
130
|
+
id: sendMsgRes.serverMsgId,
|
|
131
|
+
type: message.type,
|
|
132
|
+
properties: message.properties,
|
|
133
|
+
timestamp: Date.now(),
|
|
134
|
+
isPrivate: !!message.to?.length
|
|
135
|
+
};
|
|
136
|
+
return res;
|
|
137
|
+
}
|
|
138
|
+
addObserver(observer) {
|
|
139
|
+
this._observable.addObserver(observer);
|
|
140
|
+
return FcrReturnCode.SUCCESS;
|
|
141
|
+
}
|
|
142
|
+
removeObserver(observer) {
|
|
143
|
+
this._observable.removeObserver(observer);
|
|
144
|
+
return FcrReturnCode.SUCCESS;
|
|
145
|
+
}
|
|
146
|
+
_setConnectionState(state) {
|
|
147
|
+
if (this._connectionState === state) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this._connectionState = state;
|
|
151
|
+
this._observable.notifyObservers('onConnectionStateUpdated', this._scene.sceneId, state);
|
|
152
|
+
}
|
|
153
|
+
_tryJoinChatRoom(force = false) {
|
|
154
|
+
if (this._chatConnection.getConnectionState() !== FcrChatConnectionState.CONNECTED) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!this.chatRoomId) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (this._joinPromise) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (!force && (this._connectionState === FcrChatRoomConnectionState.Connected || this._connectionState === FcrChatRoomConnectionState.Connecting)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.join(force);
|
|
167
|
+
}
|
|
168
|
+
_addLogObserver() {
|
|
169
|
+
this.addObserver(generateLogObserver(this.logger, [['onConnectionStateUpdated', ['roomId', 'state']], ['onErrorOccurred', ['roomId', 'error']]
|
|
170
|
+
// 'onTextMessageReceived'
|
|
171
|
+
]));
|
|
172
|
+
}
|
|
173
|
+
async getHistoryMessageList(pageSize, startedMessageId) {
|
|
174
|
+
if (pageSize > 50) {
|
|
175
|
+
throw generateFcrCoreClientError(ErrorModuleCode.FCR_ROOM_CHATROOM, DetailErrorCode.UNDEFINED_ERROR, 'pageSize should be less than 50');
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const assembleRet = await this.conn.fetchHistoryMessages({
|
|
179
|
+
queue: this.chatRoomId,
|
|
180
|
+
count: pageSize,
|
|
181
|
+
start: startedMessageId,
|
|
182
|
+
isGroup: true
|
|
183
|
+
});
|
|
184
|
+
return assembleRet.map(msgBody => this._convertAgoraChatHistoryMessageToFcrChatRoomReceiveMessage(msgBody));
|
|
185
|
+
} catch (error) {
|
|
186
|
+
throw generateFcrCoreClientError(FcrErrorModuleCode.FCR_ROOM_CHATROOM, FcrErrorCode.UNDEFINED_ERROR, error.message);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
_handleJoinSceneSuccess() {
|
|
190
|
+
this._joinSceneSuccess = true;
|
|
191
|
+
this._tryJoinChatRoom();
|
|
192
|
+
}
|
|
193
|
+
_handleJoinSceneFailure() {
|
|
194
|
+
this._joinSceneSuccess = false;
|
|
195
|
+
}
|
|
196
|
+
leave() {
|
|
197
|
+
this._chatConnection.removeObserver(this._chatConnectionObserver);
|
|
198
|
+
if (this._connectionState === FcrChatRoomConnectionState.Disconnected && !this._abortJoinChatRoom) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (this._abortJoinChatRoom) {
|
|
202
|
+
this._abortJoinChatRoom();
|
|
203
|
+
this._abortJoinChatRoom = null;
|
|
204
|
+
this._joinPromise = null;
|
|
205
|
+
}
|
|
206
|
+
if (!this._chatConnection.getConnectionInstance()) {
|
|
207
|
+
this._setConnectionState(FcrChatRoomConnectionState.Disconnected);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this._removeEventListener();
|
|
211
|
+
if (this.chatRoomId) {
|
|
212
|
+
this.conn.leaveChatRoom({
|
|
213
|
+
roomId: this.chatRoomId,
|
|
214
|
+
success: () => {
|
|
215
|
+
this.logger.info(`leave chat room success, room id: ${this.chatRoomId}, scene id: ${this._scene.sceneId}`);
|
|
216
|
+
},
|
|
217
|
+
error: e => {
|
|
218
|
+
this.logger.error('leave chat room failed', e.message);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
this._setConnectionState(FcrChatRoomConnectionState.Disconnected);
|
|
223
|
+
}
|
|
224
|
+
async join(force = false) {
|
|
225
|
+
this._chatConnection.addObserver(this._chatConnectionObserver);
|
|
226
|
+
const connectorState = this._chatConnection.getConnectionState();
|
|
227
|
+
if (connectorState !== FcrChatConnectionState.CONNECTED) {
|
|
228
|
+
return FcrReturnCode.SUCCESS;
|
|
229
|
+
}
|
|
230
|
+
if (!this.chatRoomId) {
|
|
231
|
+
this.logger.warn(`chat room id is empty, scene id: ${this._scene.sceneId}`);
|
|
232
|
+
return FcrReturnCode.SUCCESS;
|
|
233
|
+
}
|
|
234
|
+
if (!this._chatConnection.getConnectionInstance()) {
|
|
235
|
+
this.logger.warn(`chat connection instance is null, scene id: ${this._scene.sceneId}`);
|
|
236
|
+
return FcrReturnCode.SUCCESS;
|
|
237
|
+
}
|
|
238
|
+
const chatRoomId = this.chatRoomId;
|
|
239
|
+
if (this._joinPromise) {
|
|
240
|
+
return this._joinPromise;
|
|
241
|
+
}
|
|
242
|
+
const chatRoomConnectionState = this.getConnectionState();
|
|
243
|
+
if (!force && (chatRoomConnectionState === FcrChatRoomConnectionState.Connected || chatRoomConnectionState === FcrChatRoomConnectionState.Connecting)) {
|
|
244
|
+
return FcrReturnCode.SUCCESS;
|
|
245
|
+
}
|
|
246
|
+
if (force || chatRoomConnectionState === FcrChatRoomConnectionState.Disconnected) {
|
|
247
|
+
if (chatRoomConnectionState !== FcrChatRoomConnectionState.Connecting) {
|
|
248
|
+
this._setConnectionState(FcrChatRoomConnectionState.Connecting);
|
|
249
|
+
}
|
|
250
|
+
this.logger.info(`start join chat room, room id: ${chatRoomId}, scene id: ${this._scene.sceneId}`);
|
|
251
|
+
this._addEventListener();
|
|
252
|
+
const attemptId = ++this._joinAttemptId;
|
|
253
|
+
this._joinPromise = (async () => {
|
|
254
|
+
let error = null;
|
|
255
|
+
if (force && chatRoomConnectionState === FcrChatRoomConnectionState.Connected) {
|
|
256
|
+
await this._leaveChatRoomForRejoin(chatRoomId);
|
|
257
|
+
}
|
|
258
|
+
const [abort, promise] = abortableRetry(async () => {
|
|
259
|
+
await this.conn.joinChatRoom({
|
|
260
|
+
roomId: chatRoomId
|
|
261
|
+
});
|
|
262
|
+
this.logger.info(`join chat room success, room id: ${chatRoomId}, scene id: ${this._scene.sceneId}`);
|
|
263
|
+
}, {
|
|
264
|
+
retriesMax: Infinity
|
|
265
|
+
});
|
|
266
|
+
this._abortJoinChatRoom = abort;
|
|
267
|
+
try {
|
|
268
|
+
[error] = await timeout(promise, this._joinTimeoutMs);
|
|
269
|
+
} catch (joinError) {
|
|
270
|
+
if (attemptId !== this._joinAttemptId) {
|
|
271
|
+
return FcrReturnCode.SUCCESS;
|
|
272
|
+
}
|
|
273
|
+
if (this._abortJoinChatRoom) {
|
|
274
|
+
this._abortJoinChatRoom();
|
|
275
|
+
this._abortJoinChatRoom = null;
|
|
276
|
+
}
|
|
277
|
+
this.leave();
|
|
278
|
+
throw joinError;
|
|
279
|
+
}
|
|
280
|
+
this._abortJoinChatRoom = null;
|
|
281
|
+
if (attemptId !== this._joinAttemptId) {
|
|
282
|
+
if (!error && this._chatConnection.getConnectionInstance()) {
|
|
283
|
+
this.conn.leaveChatRoom({
|
|
284
|
+
roomId: chatRoomId,
|
|
285
|
+
success: () => {
|
|
286
|
+
this.logger.info(`leave stale chat room success, room id: ${chatRoomId}, scene id: ${this._scene.sceneId}`);
|
|
287
|
+
},
|
|
288
|
+
error: leaveError => {
|
|
289
|
+
this.logger.error('leave stale chat room failed', leaveError.message);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return FcrReturnCode.SUCCESS;
|
|
294
|
+
}
|
|
295
|
+
if (error) {
|
|
296
|
+
this.logger.error(`join chat room failed, room id: ${chatRoomId}, scene id: ${this._scene.sceneId}`, error.message);
|
|
297
|
+
this._setConnectionState(FcrChatRoomConnectionState.Disconnected);
|
|
298
|
+
throw generateFcrCoreClientError(FcrErrorModuleCode.FCR_ROOM_CHATROOM, FcrErrorCode.UNDEFINED_ERROR, `join chat room failed: ${error.message}`);
|
|
299
|
+
} else {
|
|
300
|
+
this._setConnectionState(FcrChatRoomConnectionState.Connected);
|
|
301
|
+
}
|
|
302
|
+
return FcrReturnCode.SUCCESS;
|
|
303
|
+
})();
|
|
304
|
+
try {
|
|
305
|
+
return await this._joinPromise;
|
|
306
|
+
} finally {
|
|
307
|
+
this._joinPromise = null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return FcrReturnCode.SUCCESS;
|
|
311
|
+
}
|
|
312
|
+
_leaveChatRoomForRejoin(chatRoomId) {
|
|
313
|
+
return new Promise(resolve => {
|
|
314
|
+
if (!this._chatConnection.getConnectionInstance()) {
|
|
315
|
+
resolve();
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
this.conn.leaveChatRoom({
|
|
319
|
+
roomId: chatRoomId,
|
|
320
|
+
success: () => resolve(),
|
|
321
|
+
error: () => resolve()
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
_removeEventListener() {
|
|
326
|
+
const connection = this._chatConnection.getConnectionInstance();
|
|
327
|
+
if (connection) {
|
|
328
|
+
this.conn.removeEventHandler(this.connectionEventHandlerKey);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
_addEventListener() {
|
|
332
|
+
this._removeEventListener();
|
|
333
|
+
this.conn.addEventHandler(this.connectionEventHandlerKey, this.chatRoomConnectionHandler);
|
|
334
|
+
}
|
|
335
|
+
_convertAgoraChatMessageToFcrChatRoomReceiveMessage = msg => {
|
|
336
|
+
switch (msg.type) {
|
|
337
|
+
case 'txt':
|
|
338
|
+
{
|
|
339
|
+
const message = {
|
|
340
|
+
id: msg.id,
|
|
341
|
+
from: msg.ext?.sender,
|
|
342
|
+
type: FcrChatRoomMessageType.Text,
|
|
343
|
+
timestamp: parseInt(`${msg.time}`),
|
|
344
|
+
content: msg.msg,
|
|
345
|
+
isPrivate: msg.ext?.isPrivate,
|
|
346
|
+
properties: msg.ext?.properties
|
|
347
|
+
};
|
|
348
|
+
return message;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
throw generateFcrCoreClientError(FcrErrorModuleCode.FCR_ROOM_CHATROOM, FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type');
|
|
352
|
+
};
|
|
353
|
+
_convertAgoraChatHistoryMessageToFcrChatRoomReceiveMessage(msg) {
|
|
354
|
+
//@ts-ignore
|
|
355
|
+
switch (msg.contentsType) {
|
|
356
|
+
case 'TEXT':
|
|
357
|
+
{
|
|
358
|
+
const message = {
|
|
359
|
+
id: msg.id,
|
|
360
|
+
//@ts-ignore
|
|
361
|
+
from: msg.ext?.sender,
|
|
362
|
+
type: FcrChatRoomMessageType.Text,
|
|
363
|
+
//@ts-ignore
|
|
364
|
+
timestamp: parseInt(`${msg.time}`),
|
|
365
|
+
//@ts-ignore
|
|
366
|
+
content: msg.data,
|
|
367
|
+
//@ts-ignore
|
|
368
|
+
isPrivate: msg.ext?.isPrivate,
|
|
369
|
+
//@ts-ignore
|
|
370
|
+
properties: msg.ext?.properties
|
|
371
|
+
};
|
|
372
|
+
return message;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
throw generateFcrCoreClientError(FcrErrorModuleCode.FCR_ROOM_CHATROOM, FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type');
|
|
376
|
+
}
|
|
377
|
+
_convertFcrChatRoomSendBaseMessageToAgoraChatMessage(msg, progress) {
|
|
378
|
+
switch (msg.type) {
|
|
379
|
+
case FcrChatRoomMessageType.Text:
|
|
380
|
+
{
|
|
381
|
+
const message = msg;
|
|
382
|
+
const isPrivate = !!message.to?.length;
|
|
383
|
+
const localUserId = this._scene.getLocalUser().getLocalUserId();
|
|
384
|
+
const localUserInfo = this._scene.getUser(localUserId);
|
|
385
|
+
return EasemobChatSDK.message.create({
|
|
386
|
+
to: this.chatRoomId,
|
|
387
|
+
msg: message.content,
|
|
388
|
+
type: 'txt',
|
|
389
|
+
chatType: 'chatRoom',
|
|
390
|
+
ext: {
|
|
391
|
+
sender: convertRteUserToFcrUser(localUserInfo, this._roomCache),
|
|
392
|
+
roomUuid: this._scene.sceneId,
|
|
393
|
+
isPrivate,
|
|
394
|
+
properties: msg.properties
|
|
395
|
+
},
|
|
396
|
+
receiverList: message.to
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
throw generateFcrCoreClientError(FcrErrorModuleCode.FCR_ROOM_CHATROOM, FcrErrorCode.UNDEFINED_ERROR, 'unknown local message type');
|
|
401
|
+
}
|
|
402
|
+
_handleScenePropertiesUpdated(sceneId, properties) {
|
|
403
|
+
const chatRoomId = get(properties.changedProperties, CHATROOM_ID_KEY_PATH);
|
|
404
|
+
if (chatRoomId) {
|
|
405
|
+
this.logger.info(`received chat room id change, chat room id: ${chatRoomId}, scene id: ${sceneId}`);
|
|
406
|
+
this.join();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|