fcr-core 3.7.8 → 3.7.9-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-connection/index.js +26 -41
- package/lib/engine/index.js +74 -67
- package/lib/imports.js +0 -1
- package/lib/media-control/desktop.js +13 -18
- package/lib/media-control/mobile.js +13 -18
- package/lib/monitor-control/index.js +5 -10
- package/lib/peer-session/index.js +39 -48
- package/lib/plugins/chatroom.js +202 -218
- package/lib/room-control/ability-control/index.js +9 -14
- package/lib/room-control/group-control/index.js +16 -21
- package/lib/room-control/helpers/validation-helper.js +1 -1
- package/lib/room-control/index.js +36 -53
- package/lib/room-control/interpreter-control/index.js +34 -47
- package/lib/room-control/interpreter-control/room.js +4 -6
- package/lib/room-control/join-before-host-waitingroom-control/index.js +4 -6
- package/lib/room-control/mainroom-control/index.js +17 -25
- package/lib/room-control/privilege-control/helper.js +5 -8
- package/lib/room-control/privilege-control/index.js +19 -26
- package/lib/room-control/room-connector-control/index.js +19 -28
- package/lib/room-control/room-control-factory.js +1 -2
- package/lib/room-control/room-session/index.js +39 -48
- package/lib/room-control/shared-cache.js +29 -36
- package/lib/room-control/sharing-control/index.js +32 -40
- package/lib/room-control/stream-control/index.js +173 -181
- package/lib/room-control/user-control/index.js +136 -143
- package/lib/room-control/waitingroom-control/index.js +9 -14
- package/lib/room-control/whiteboard-control-v2/annotation-control/control.js +24 -32
- package/lib/room-control/whiteboard-control-v2/annotation-control/index.js +16 -27
- package/lib/room-control/whiteboard-control-v2/annotation-control/privilege-control.js +53 -63
- package/lib/room-control/whiteboard-control-v2/index.js +28 -40
- package/lib/room-control/whiteboard-control-v2/main-window.js +23 -28
- package/lib/room-control/whiteboard-control-v2/utils.js +6 -7
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/control.js +27 -38
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/index.js +3 -5
- package/lib/room-control/whiteboard-control-v2/whiteboard-control/privilege-control.js +42 -54
- package/lib/room-router/index.js +42 -52
- package/lib/service/api.js +207 -231
- package/lib/utilities/collection.js +2 -3
- package/lib/utilities/error-helpers.js +27 -34
- package/lib/utilities/error.js +8 -9
- package/lib/utilities/join-helper.js +25 -32
- package/lib/utilities/logger.js +3 -6
- package/lib/utilities/parameters.js +4 -8
- package/lib/utilities/retry-helpers.js +0 -1
- package/lib/utilities/shared-storage.js +0 -1
- package/lib/utilities/storage.js +0 -1
- package/lib/utilities/stream.js +11 -16
- package/lib/utilities/user.js +3 -4
- package/lib/utilities/validate-params.js +1 -2
- package/package.json +4 -4
package/lib/plugins/chatroom.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.symbol.description.js");
|
|
4
3
|
require("core-js/modules/es.array.push.js");
|
|
5
4
|
require("core-js/modules/esnext.function.metadata.js");
|
|
6
|
-
require("core-js/modules/esnext.iterator.filter.js");
|
|
7
|
-
require("core-js/modules/esnext.iterator.for-each.js");
|
|
8
5
|
require("core-js/modules/esnext.map.delete-all.js");
|
|
9
6
|
require("core-js/modules/esnext.map.emplace.js");
|
|
10
7
|
require("core-js/modules/esnext.map.every.js");
|
|
@@ -25,12 +22,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
25
22
|
value: true
|
|
26
23
|
});
|
|
27
24
|
exports.FcrChatRoomControlImpl = void 0;
|
|
28
|
-
require("core-js/modules/es.error.cause.js");
|
|
29
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
30
25
|
require("core-js/modules/esnext.iterator.constructor.js");
|
|
31
26
|
require("core-js/modules/esnext.iterator.map.js");
|
|
32
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
33
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
34
27
|
var _imports = require("../imports");
|
|
35
28
|
var _observable = require("agora-foundation/lib/utilities/observable");
|
|
36
29
|
var _easemobWebsdk = _interopRequireDefault(require("easemob-websdk"));
|
|
@@ -41,20 +34,40 @@ var _type2 = require("../chat-connection/type");
|
|
|
41
34
|
var _logger = require("../utilities/logger");
|
|
42
35
|
var _validateParams = _interopRequireDefault(require("../utilities/validate-params"));
|
|
43
36
|
var _schema = require("../schema");
|
|
44
|
-
|
|
45
|
-
let _initProto, _sendMessageDecs, _ref;
|
|
46
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
47
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
37
|
+
let _initProto, _sendMessageDecs;
|
|
48
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)]; } }; }
|
|
49
39
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
50
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); }
|
|
51
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; }
|
|
52
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; }
|
|
53
|
-
_ref = (_sendMessageDecs = [_imports.trace, (0, _validateParams.default)(_schema.messageSchema, _schema.progressSchema.optional())], "logger");
|
|
54
43
|
/**
|
|
55
44
|
* @internal
|
|
56
45
|
*/
|
|
57
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
|
+
_chatConnectionObserver = {
|
|
56
|
+
onConnectionStateUpdated: async state => {
|
|
57
|
+
// im reconnect
|
|
58
|
+
this.logger.info(`onConnectionStateUpdated, chatConnectionState: ${state}, chatControlState: ${this.getConnectionState()}`);
|
|
59
|
+
if (state === _type2.FcrChatConnectionState.DISCONNECTED && this.getConnectionState() === _type.FcrChatRoomConnectionState.Connected) {
|
|
60
|
+
this._setConnectionState(_type.FcrChatRoomConnectionState.Disconnected);
|
|
61
|
+
} else if (state === _type2.FcrChatConnectionState.CONNECTED && this.getConnectionState() !== _type.FcrChatRoomConnectionState.Connected) {
|
|
62
|
+
this._removeEventListener();
|
|
63
|
+
this._addEventListener();
|
|
64
|
+
await this._joinChatRoom(state);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
onConnectionLoginSuccess: () => {
|
|
68
|
+
this._addEventListener();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
58
71
|
get conn() {
|
|
59
72
|
if (!this._chatConnection.getConnectionInstance()) {
|
|
60
73
|
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'));
|
|
@@ -65,195 +78,6 @@ class FcrChatRoomControlImpl {
|
|
|
65
78
|
return this._scene.getScenePropertiesByKeyPath('widgets.easemobIM.extra.chatRoomId');
|
|
66
79
|
}
|
|
67
80
|
constructor(_scene, _chatConnection, _sharedCache) {
|
|
68
|
-
(0, _defineProperty2.default)(this, _ref, (_initProto(this), (0, _logger.createLogger)({
|
|
69
|
-
prefix: 'FcrChatRoomControlImpl'
|
|
70
|
-
})));
|
|
71
|
-
(0, _defineProperty2.default)(this, "_observable", new _observable.AgoraObservable());
|
|
72
|
-
(0, _defineProperty2.default)(this, "_connectionState", _type.FcrChatRoomConnectionState.Disconnected);
|
|
73
|
-
(0, _defineProperty2.default)(this, "_chatConnectionObserver", {
|
|
74
|
-
onConnectionStateUpdated: async state => {
|
|
75
|
-
// im reconnect
|
|
76
|
-
this.logger.info("onConnectionStateUpdated, chatConnectionState: ".concat(state, ", chatControlState: ").concat(this.getConnectionState()));
|
|
77
|
-
if (state === _type2.FcrChatConnectionState.DISCONNECTED && this.getConnectionState() === _type.FcrChatRoomConnectionState.Connected) {
|
|
78
|
-
this._setConnectionState(_type.FcrChatRoomConnectionState.Disconnected);
|
|
79
|
-
} else if (state === _type2.FcrChatConnectionState.CONNECTED && this.getConnectionState() !== _type.FcrChatRoomConnectionState.Connected) {
|
|
80
|
-
this._removeEventListener();
|
|
81
|
-
this._addEventListener();
|
|
82
|
-
await this._joinChatRoom(state);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
onConnectionLoginSuccess: () => {
|
|
86
|
-
this._addEventListener();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
(0, _defineProperty2.default)(this, "_joinChatRoom", async state => {
|
|
90
|
-
this.logger.info("joinChatRoom, chatConnectionState: ".concat(state, ", chatControlState: ").concat(this.getConnectionState()));
|
|
91
|
-
if (state === _type2.FcrChatConnectionState.CONNECTED && this.getConnectionState() === _type.FcrChatRoomConnectionState.Disconnected && this.chatRoomId) {
|
|
92
|
-
this._setConnectionState(_type.FcrChatRoomConnectionState.Connecting);
|
|
93
|
-
this.logger.info("start join chat room, room id: ".concat(this.chatRoomId, ", scene id: ").concat(this._scene.sceneId));
|
|
94
|
-
let error = null;
|
|
95
|
-
[error] = await (0, _imports.to)((0, _imports.retryAttempt)(async () => {
|
|
96
|
-
await this.conn.joinChatRoom({
|
|
97
|
-
roomId: this.chatRoomId
|
|
98
|
-
});
|
|
99
|
-
}, [], {
|
|
100
|
-
retriesMax: 4
|
|
101
|
-
}).fail(async _ref2 => {
|
|
102
|
-
let {
|
|
103
|
-
error,
|
|
104
|
-
timeFn,
|
|
105
|
-
currentRetry
|
|
106
|
-
} = _ref2;
|
|
107
|
-
this.logger.error("retry to join chat room, ".concat(error.message, ", retry ").concat(currentRetry, " times"));
|
|
108
|
-
await timeFn();
|
|
109
|
-
return true;
|
|
110
|
-
}).exec());
|
|
111
|
-
if (error) {
|
|
112
|
-
this._setConnectionState(_type.FcrChatRoomConnectionState.Disconnected);
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
this._setConnectionState(_type.FcrChatRoomConnectionState.Connected);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
(0, _defineProperty2.default)(this, "_convertAgoraChatMessageToFcrChatRoomReceiveMessage", msg => {
|
|
119
|
-
// TODO: 没看到有 contentsType 字段
|
|
120
|
-
//@ts-ignore
|
|
121
|
-
switch (msg.type) {
|
|
122
|
-
case 'txt':
|
|
123
|
-
{
|
|
124
|
-
var _msg$ext, _msg$ext2;
|
|
125
|
-
const message = {
|
|
126
|
-
id: msg.id,
|
|
127
|
-
//@ts-ignore
|
|
128
|
-
from: msg.ext.sender,
|
|
129
|
-
type: _type.FcrChatRoomMessageType.Text,
|
|
130
|
-
//@ts-ignore
|
|
131
|
-
timestamp: parseInt(msg.time),
|
|
132
|
-
//@ts-ignore
|
|
133
|
-
content: msg.msg,
|
|
134
|
-
isPrivate: (_msg$ext = msg.ext) === null || _msg$ext === void 0 ? void 0 : _msg$ext.isPrivate,
|
|
135
|
-
properties: (_msg$ext2 = msg.ext) === null || _msg$ext2 === void 0 ? void 0 : _msg$ext2.properties
|
|
136
|
-
};
|
|
137
|
-
return message;
|
|
138
|
-
}
|
|
139
|
-
case 'img':
|
|
140
|
-
{
|
|
141
|
-
var _msg$ext3, _msg$ext4, _msg$ext5;
|
|
142
|
-
const message = {
|
|
143
|
-
id: msg.id,
|
|
144
|
-
from: (_msg$ext3 = msg.ext) === null || _msg$ext3 === void 0 ? void 0 : _msg$ext3.sender,
|
|
145
|
-
type: _type.FcrChatRoomMessageType.Image,
|
|
146
|
-
//@ts-ignore
|
|
147
|
-
timestamp: parseInt(msg.time),
|
|
148
|
-
url: msg.url || '',
|
|
149
|
-
isPrivate: (_msg$ext4 = msg.ext) === null || _msg$ext4 === void 0 ? void 0 : _msg$ext4.isPrivate,
|
|
150
|
-
properties: (_msg$ext5 = msg.ext) === null || _msg$ext5 === void 0 ? void 0 : _msg$ext5.properties
|
|
151
|
-
};
|
|
152
|
-
return message;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type', new Error('unknown remote message type'));
|
|
156
|
-
});
|
|
157
|
-
(0, _defineProperty2.default)(this, "_convertAgoraChatHistoryMessageToFcrChatRoomReceiveMessage", msg => {
|
|
158
|
-
// TODO: 没看到有 contentsType 字段
|
|
159
|
-
//@ts-ignore
|
|
160
|
-
switch (msg.contentsType) {
|
|
161
|
-
case 'TEXT':
|
|
162
|
-
{
|
|
163
|
-
var _msg$ext6;
|
|
164
|
-
const message = {
|
|
165
|
-
id: msg.id,
|
|
166
|
-
//@ts-ignore
|
|
167
|
-
from: msg.ext.sender,
|
|
168
|
-
type: _type.FcrChatRoomMessageType.Text,
|
|
169
|
-
//@ts-ignore
|
|
170
|
-
timestamp: parseInt(msg.time),
|
|
171
|
-
//@ts-ignore
|
|
172
|
-
content: msg.data,
|
|
173
|
-
//@ts-ignore
|
|
174
|
-
isPrivate: msg.ext.isPrivate,
|
|
175
|
-
//@ts-ignore
|
|
176
|
-
properties: (_msg$ext6 = msg.ext) === null || _msg$ext6 === void 0 ? void 0 : _msg$ext6.properties
|
|
177
|
-
};
|
|
178
|
-
return message;
|
|
179
|
-
}
|
|
180
|
-
case 'IMAGE':
|
|
181
|
-
{
|
|
182
|
-
var _msg$ext7, _msg$ext8, _msg$ext9;
|
|
183
|
-
const message = {
|
|
184
|
-
id: msg.id,
|
|
185
|
-
//@ts-ignore
|
|
186
|
-
from: (_msg$ext7 = msg.ext) === null || _msg$ext7 === void 0 ? void 0 : _msg$ext7.sender,
|
|
187
|
-
type: _type.FcrChatRoomMessageType.Image,
|
|
188
|
-
//@ts-ignore
|
|
189
|
-
timestamp: parseInt(msg.time),
|
|
190
|
-
//@ts-ignore
|
|
191
|
-
url: msg.url || '',
|
|
192
|
-
//@ts-ignore
|
|
193
|
-
isPrivate: (_msg$ext8 = msg.ext) === null || _msg$ext8 === void 0 ? void 0 : _msg$ext8.isPrivate,
|
|
194
|
-
//@ts-ignore
|
|
195
|
-
properties: (_msg$ext9 = msg.ext) === null || _msg$ext9 === void 0 ? void 0 : _msg$ext9.properties
|
|
196
|
-
};
|
|
197
|
-
return message;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type', new Error('unknown remote message type'));
|
|
201
|
-
});
|
|
202
|
-
(0, _defineProperty2.default)(this, "_convertFcrChatRoomSendBaseMessageToAgoraChatMessage", (msg, progress) => {
|
|
203
|
-
switch (msg.type) {
|
|
204
|
-
case _type.FcrChatRoomMessageType.Text:
|
|
205
|
-
{
|
|
206
|
-
var _message$to;
|
|
207
|
-
const message = msg;
|
|
208
|
-
const isPrivate = !!((_message$to = message.to) !== null && _message$to !== void 0 && _message$to.length);
|
|
209
|
-
const localUserId = this._scene.getLocalUser().getLocalUserId();
|
|
210
|
-
const localUserInfo = this._scene.getUser(localUserId);
|
|
211
|
-
return _easemobWebsdk.default.message.create({
|
|
212
|
-
to: this.chatRoomId,
|
|
213
|
-
msg: message.content,
|
|
214
|
-
type: 'txt',
|
|
215
|
-
chatType: 'chatRoom',
|
|
216
|
-
ext: {
|
|
217
|
-
sender: (0, _user.convertRteUserToFcrUser)(localUserInfo, this._roomCache),
|
|
218
|
-
roomUuid: this._scene.sceneId,
|
|
219
|
-
isPrivate,
|
|
220
|
-
properties: msg.properties
|
|
221
|
-
},
|
|
222
|
-
receiverList: message.to
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
case _type.FcrChatRoomMessageType.Image:
|
|
226
|
-
{
|
|
227
|
-
var _imageMessage$to;
|
|
228
|
-
const imageMessage = msg;
|
|
229
|
-
const isPrivateImage = !!((_imageMessage$to = imageMessage.to) !== null && _imageMessage$to !== void 0 && _imageMessage$to.length);
|
|
230
|
-
const localUser = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
|
|
231
|
-
return _easemobWebsdk.default.message.create({
|
|
232
|
-
to: this.chatRoomId,
|
|
233
|
-
type: 'img',
|
|
234
|
-
chatType: 'chatRoom',
|
|
235
|
-
url: imageMessage.file.filePath,
|
|
236
|
-
file: {
|
|
237
|
-
filename: imageMessage.file.fileName,
|
|
238
|
-
filetype: imageMessage.file.fileType,
|
|
239
|
-
data: imageMessage.file.data,
|
|
240
|
-
url: ''
|
|
241
|
-
},
|
|
242
|
-
ext: {
|
|
243
|
-
sender: (0, _user.convertRteUserToFcrUser)(localUser, this._roomCache),
|
|
244
|
-
roomUuid: this._scene.sceneId,
|
|
245
|
-
isPrivate: isPrivateImage,
|
|
246
|
-
properties: msg.properties
|
|
247
|
-
},
|
|
248
|
-
receiverList: imageMessage.to,
|
|
249
|
-
onFileUploadProgress: e => {
|
|
250
|
-
progress === null || progress === void 0 || progress(Math.round(e.loaded / e.total * 100));
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown local message type', new Error('unknown local message type'));
|
|
256
|
-
});
|
|
257
81
|
this._scene = _scene;
|
|
258
82
|
this._chatConnection = _chatConnection;
|
|
259
83
|
this._sharedCache = _sharedCache;
|
|
@@ -292,12 +116,40 @@ class FcrChatRoomControlImpl {
|
|
|
292
116
|
}
|
|
293
117
|
});
|
|
294
118
|
}
|
|
119
|
+
_joinChatRoom = async state => {
|
|
120
|
+
this.logger.info(`joinChatRoom, chatConnectionState: ${state}, chatControlState: ${this.getConnectionState()}`);
|
|
121
|
+
if (state === _type2.FcrChatConnectionState.CONNECTED && this.getConnectionState() === _type.FcrChatRoomConnectionState.Disconnected && this.chatRoomId) {
|
|
122
|
+
this._setConnectionState(_type.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 (0, _imports.to)((0, _imports.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(_type.FcrChatRoomConnectionState.Disconnected);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
this._setConnectionState(_type.FcrChatRoomConnectionState.Connected);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
295
147
|
_removeEventListener() {
|
|
296
|
-
this.conn.removeEventHandler(
|
|
148
|
+
this.conn.removeEventHandler(`chatroom${this._scene.sceneId}`);
|
|
297
149
|
}
|
|
298
150
|
_addEventListener() {
|
|
299
151
|
this._removeEventListener();
|
|
300
|
-
this.conn.addEventHandler(
|
|
152
|
+
this.conn.addEventHandler(`chatroom${this._scene.sceneId}`, {
|
|
301
153
|
onTextMessage: msg => {
|
|
302
154
|
if (msg.to !== this.chatRoomId) {
|
|
303
155
|
return;
|
|
@@ -312,9 +164,10 @@ class FcrChatRoomControlImpl {
|
|
|
312
164
|
}
|
|
313
165
|
// 这里的数据结构和 onTextMessage 不一样,实际上contentsType是img ,type是chatroom,
|
|
314
166
|
// 但是因为在onPictureMessage的回调中,所以这里直接用type: 'img',后续可以考虑优化
|
|
315
|
-
const message = this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(
|
|
167
|
+
const message = this._convertAgoraChatMessageToFcrChatRoomReceiveMessage({
|
|
168
|
+
...msg,
|
|
316
169
|
type: 'img'
|
|
317
|
-
})
|
|
170
|
+
});
|
|
318
171
|
this._observable.notifyObservers('onImageMessageReceived', this._scene.sceneId, message);
|
|
319
172
|
};
|
|
320
173
|
|
|
@@ -342,25 +195,158 @@ class FcrChatRoomControlImpl {
|
|
|
342
195
|
// }
|
|
343
196
|
// };
|
|
344
197
|
}
|
|
198
|
+
_convertAgoraChatMessageToFcrChatRoomReceiveMessage = msg => {
|
|
199
|
+
// TODO: 没看到有 contentsType 字段
|
|
200
|
+
//@ts-ignore
|
|
201
|
+
switch (msg.type) {
|
|
202
|
+
case 'txt':
|
|
203
|
+
{
|
|
204
|
+
const message = {
|
|
205
|
+
id: msg.id,
|
|
206
|
+
//@ts-ignore
|
|
207
|
+
from: msg.ext.sender,
|
|
208
|
+
type: _type.FcrChatRoomMessageType.Text,
|
|
209
|
+
//@ts-ignore
|
|
210
|
+
timestamp: parseInt(msg.time),
|
|
211
|
+
//@ts-ignore
|
|
212
|
+
content: msg.msg,
|
|
213
|
+
isPrivate: msg.ext?.isPrivate,
|
|
214
|
+
properties: msg.ext?.properties
|
|
215
|
+
};
|
|
216
|
+
return message;
|
|
217
|
+
}
|
|
218
|
+
case 'img':
|
|
219
|
+
{
|
|
220
|
+
const message = {
|
|
221
|
+
id: msg.id,
|
|
222
|
+
from: msg.ext?.sender,
|
|
223
|
+
type: _type.FcrChatRoomMessageType.Image,
|
|
224
|
+
//@ts-ignore
|
|
225
|
+
timestamp: parseInt(msg.time),
|
|
226
|
+
url: msg.url || '',
|
|
227
|
+
isPrivate: msg.ext?.isPrivate,
|
|
228
|
+
properties: msg.ext?.properties
|
|
229
|
+
};
|
|
230
|
+
return message;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type', new Error('unknown remote message type'));
|
|
234
|
+
};
|
|
235
|
+
_convertAgoraChatHistoryMessageToFcrChatRoomReceiveMessage = msg => {
|
|
236
|
+
// TODO: 没看到有 contentsType 字段
|
|
237
|
+
//@ts-ignore
|
|
238
|
+
switch (msg.contentsType) {
|
|
239
|
+
case 'TEXT':
|
|
240
|
+
{
|
|
241
|
+
const message = {
|
|
242
|
+
id: msg.id,
|
|
243
|
+
//@ts-ignore
|
|
244
|
+
from: msg.ext.sender,
|
|
245
|
+
type: _type.FcrChatRoomMessageType.Text,
|
|
246
|
+
//@ts-ignore
|
|
247
|
+
timestamp: parseInt(msg.time),
|
|
248
|
+
//@ts-ignore
|
|
249
|
+
content: msg.data,
|
|
250
|
+
//@ts-ignore
|
|
251
|
+
isPrivate: msg.ext.isPrivate,
|
|
252
|
+
//@ts-ignore
|
|
253
|
+
properties: msg.ext?.properties
|
|
254
|
+
};
|
|
255
|
+
return message;
|
|
256
|
+
}
|
|
257
|
+
case 'IMAGE':
|
|
258
|
+
{
|
|
259
|
+
const message = {
|
|
260
|
+
id: msg.id,
|
|
261
|
+
//@ts-ignore
|
|
262
|
+
from: msg.ext?.sender,
|
|
263
|
+
type: _type.FcrChatRoomMessageType.Image,
|
|
264
|
+
//@ts-ignore
|
|
265
|
+
timestamp: parseInt(msg.time),
|
|
266
|
+
//@ts-ignore
|
|
267
|
+
url: msg.url || '',
|
|
268
|
+
//@ts-ignore
|
|
269
|
+
isPrivate: msg.ext?.isPrivate,
|
|
270
|
+
//@ts-ignore
|
|
271
|
+
properties: msg.ext?.properties
|
|
272
|
+
};
|
|
273
|
+
return message;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type', new Error('unknown remote message type'));
|
|
277
|
+
};
|
|
278
|
+
_convertFcrChatRoomSendBaseMessageToAgoraChatMessage = (msg, progress) => {
|
|
279
|
+
switch (msg.type) {
|
|
280
|
+
case _type.FcrChatRoomMessageType.Text:
|
|
281
|
+
{
|
|
282
|
+
const message = msg;
|
|
283
|
+
const isPrivate = !!message.to?.length;
|
|
284
|
+
const localUserId = this._scene.getLocalUser().getLocalUserId();
|
|
285
|
+
const localUserInfo = this._scene.getUser(localUserId);
|
|
286
|
+
return _easemobWebsdk.default.message.create({
|
|
287
|
+
to: this.chatRoomId,
|
|
288
|
+
msg: message.content,
|
|
289
|
+
type: 'txt',
|
|
290
|
+
chatType: 'chatRoom',
|
|
291
|
+
ext: {
|
|
292
|
+
sender: (0, _user.convertRteUserToFcrUser)(localUserInfo, this._roomCache),
|
|
293
|
+
roomUuid: this._scene.sceneId,
|
|
294
|
+
isPrivate,
|
|
295
|
+
properties: msg.properties
|
|
296
|
+
},
|
|
297
|
+
receiverList: message.to
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
case _type.FcrChatRoomMessageType.Image:
|
|
301
|
+
{
|
|
302
|
+
const imageMessage = msg;
|
|
303
|
+
const isPrivateImage = !!imageMessage.to?.length;
|
|
304
|
+
const localUser = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
|
|
305
|
+
return _easemobWebsdk.default.message.create({
|
|
306
|
+
to: this.chatRoomId,
|
|
307
|
+
type: 'img',
|
|
308
|
+
chatType: 'chatRoom',
|
|
309
|
+
url: imageMessage.file.filePath,
|
|
310
|
+
file: {
|
|
311
|
+
filename: imageMessage.file.fileName,
|
|
312
|
+
filetype: imageMessage.file.fileType,
|
|
313
|
+
data: imageMessage.file.data,
|
|
314
|
+
url: ''
|
|
315
|
+
},
|
|
316
|
+
ext: {
|
|
317
|
+
sender: (0, _user.convertRteUserToFcrUser)(localUser, this._roomCache),
|
|
318
|
+
roomUuid: this._scene.sceneId,
|
|
319
|
+
isPrivate: isPrivateImage,
|
|
320
|
+
properties: msg.properties
|
|
321
|
+
},
|
|
322
|
+
receiverList: imageMessage.to,
|
|
323
|
+
onFileUploadProgress: e => {
|
|
324
|
+
progress?.(Math.round(e.loaded / e.total * 100));
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown local message type', new Error('unknown local message type'));
|
|
330
|
+
};
|
|
345
331
|
async sendMessage(message, progress) {
|
|
346
|
-
var _message$to2;
|
|
347
332
|
const msg = this._convertFcrChatRoomSendBaseMessageToAgoraChatMessage(message, progress);
|
|
348
333
|
const sendMsgRes = await this.conn.send(msg);
|
|
349
334
|
const localUserInfo = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
|
|
350
|
-
const res =
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
335
|
+
const res = {
|
|
336
|
+
...(message.type === _type.FcrChatRoomMessageType.Text ? {
|
|
337
|
+
content: message.content
|
|
338
|
+
} :
|
|
339
|
+
// @ts-ignore
|
|
340
|
+
{
|
|
341
|
+
url: sendMsgRes.message.url
|
|
342
|
+
}),
|
|
357
343
|
from: (0, _user.convertRteUserToFcrUser)(localUserInfo, this._roomCache),
|
|
358
344
|
id: sendMsgRes.serverMsgId,
|
|
359
345
|
type: message.type,
|
|
360
346
|
properties: message.properties,
|
|
361
347
|
timestamp: Date.now(),
|
|
362
|
-
isPrivate: !!
|
|
363
|
-
}
|
|
348
|
+
isPrivate: !!message.to?.length
|
|
349
|
+
};
|
|
364
350
|
return res;
|
|
365
351
|
}
|
|
366
352
|
addObserver(observer) {
|
|
@@ -449,6 +435,4 @@ class FcrChatRoomControlImpl {
|
|
|
449
435
|
// });
|
|
450
436
|
// }
|
|
451
437
|
}
|
|
452
|
-
exports.FcrChatRoomControlImpl = FcrChatRoomControlImpl;
|
|
453
|
-
_FcrChatRoomControlImpl = FcrChatRoomControlImpl;
|
|
454
|
-
[_initProto] = _applyDecs(_FcrChatRoomControlImpl, [[_imports.trace, 2, "join"], [_imports.trace, 2, "getConnectionState"], [_imports.trace, 2, "leave"], [_sendMessageDecs, 2, "sendMessage"], [_imports.trace, 2, "addObserver"], [_imports.trace, 2, "removeObserver"]], []).e;
|
|
438
|
+
exports.FcrChatRoomControlImpl = FcrChatRoomControlImpl;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.symbol.description.js");
|
|
4
|
-
require("core-js/modules/es.error.cause.js");
|
|
5
3
|
require("core-js/modules/es.array.push.js");
|
|
6
4
|
require("core-js/modules/esnext.function.metadata.js");
|
|
7
5
|
require("core-js/modules/esnext.map.delete-all.js");
|
|
@@ -19,16 +17,12 @@ require("core-js/modules/esnext.map.reduce.js");
|
|
|
19
17
|
require("core-js/modules/esnext.map.some.js");
|
|
20
18
|
require("core-js/modules/esnext.map.update.js");
|
|
21
19
|
require("core-js/modules/esnext.symbol.metadata.js");
|
|
22
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
23
20
|
Object.defineProperty(exports, "__esModule", {
|
|
24
21
|
value: true
|
|
25
22
|
});
|
|
26
23
|
exports.FcrAbilityControlImpl = void 0;
|
|
27
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
28
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
29
24
|
var _imports = require("../../imports");
|
|
30
25
|
var _logger = require("../../utilities/logger");
|
|
31
|
-
var _FcrAbilityControlImpl;
|
|
32
26
|
let _initProto;
|
|
33
27
|
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)]; } }; }
|
|
34
28
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
@@ -40,15 +34,18 @@ function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side
|
|
|
40
34
|
* @internal
|
|
41
35
|
*/
|
|
42
36
|
class FcrAbilityControlImpl {
|
|
37
|
+
static {
|
|
38
|
+
[_initProto] = _applyDecs(this, [[_imports.trace, 2, "isPlatformAbilitySupported"]], []).e;
|
|
39
|
+
}
|
|
40
|
+
//@internal
|
|
41
|
+
logger = (_initProto(this), (0, _logger.createLogger)({
|
|
42
|
+
prefix: 'FcrAbilityControlImpl'
|
|
43
|
+
}));
|
|
43
44
|
constructor(_scene) {
|
|
44
|
-
//@internal
|
|
45
|
-
(0, _defineProperty2.default)(this, "logger", (_initProto(this), (0, _logger.createLogger)({
|
|
46
|
-
prefix: 'FcrAbilityControlImpl'
|
|
47
|
-
})));
|
|
48
45
|
this._scene = _scene;
|
|
49
46
|
}
|
|
50
47
|
getPlatformAbility(ability) {
|
|
51
|
-
const platforms = this._scene.getScenePropertiesByKeyPath(
|
|
48
|
+
const platforms = this._scene.getScenePropertiesByKeyPath(`setting.ability.${ability}`);
|
|
52
49
|
if (!Array.isArray(platforms)) {
|
|
53
50
|
return [];
|
|
54
51
|
}
|
|
@@ -64,6 +61,4 @@ class FcrAbilityControlImpl {
|
|
|
64
61
|
return platforms.includes(platform);
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
|
-
exports.FcrAbilityControlImpl = FcrAbilityControlImpl;
|
|
68
|
-
_FcrAbilityControlImpl = FcrAbilityControlImpl;
|
|
69
|
-
[_initProto] = _applyDecs(_FcrAbilityControlImpl, [[_imports.trace, 2, "isPlatformAbilitySupported"]], []).e;
|
|
64
|
+
exports.FcrAbilityControlImpl = FcrAbilityControlImpl;
|