fcr-core 3.4.0
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/base-session.d.ts +3 -0
- package/lib/base-session.js +8 -0
- package/lib/chat-connection/config.d.ts +51 -0
- package/lib/chat-connection/config.js +105 -0
- package/lib/chat-connection/index.d.ts +25 -0
- package/lib/chat-connection/index.js +118 -0
- package/lib/chat-connection/type.d.ts +17 -0
- package/lib/chat-connection/type.js +12 -0
- package/lib/engine/index.d.ts +86 -0
- package/lib/engine/index.js +317 -0
- package/lib/imports.d.ts +43 -0
- package/lib/imports.js +322 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +140 -0
- package/lib/media-control/desktop.d.ts +1 -0
- package/lib/media-control/desktop.js +120 -0
- package/lib/media-control/mobile.d.ts +1 -0
- package/lib/media-control/mobile.js +168 -0
- package/lib/media-control/type.d.ts +640 -0
- package/lib/media-control/type.js +5 -0
- package/lib/monitor-control/index.d.ts +1 -0
- package/lib/monitor-control/index.js +22 -0
- package/lib/monitor-control/type.d.ts +16 -0
- package/lib/monitor-control/type.js +5 -0
- package/lib/peer-session/index.d.ts +1 -0
- package/lib/peer-session/index.js +286 -0
- package/lib/peer-session/type.d.ts +54 -0
- package/lib/peer-session/type.js +5 -0
- package/lib/plugins/chatroom.d.ts +1 -0
- package/lib/plugins/chatroom.js +331 -0
- package/lib/plugins/electron-rtc-plugin.d.ts +1 -0
- package/lib/plugins/electron-rtc-plugin.js +13 -0
- package/lib/plugins/rtm-plugin.d.ts +1 -0
- package/lib/plugins/rtm-plugin.js +13 -0
- package/lib/plugins/web-rtc-plugin.d.ts +1 -0
- package/lib/plugins/web-rtc-plugin.js +13 -0
- package/lib/room-control/chatroom-control/config.d.ts +51 -0
- package/lib/room-control/chatroom-control/config.js +105 -0
- package/lib/room-control/chatroom-control/index.d.ts +1 -0
- package/lib/room-control/chatroom-control/index.js +323 -0
- package/lib/room-control/chatroom-control/type.d.ts +95 -0
- package/lib/room-control/chatroom-control/type.js +18 -0
- package/lib/room-control/group-control/index.d.ts +25 -0
- package/lib/room-control/group-control/index.js +227 -0
- package/lib/room-control/index.d.ts +1 -0
- package/lib/room-control/index.js +459 -0
- package/lib/room-control/interpreter-control/index.d.ts +1 -0
- package/lib/room-control/interpreter-control/index.js +136 -0
- package/lib/room-control/interpreter-control/room.d.ts +1 -0
- package/lib/room-control/interpreter-control/room.js +22 -0
- package/lib/room-control/interpreter-control/types.d.ts +66 -0
- package/lib/room-control/interpreter-control/types.js +32 -0
- package/lib/room-control/mainroom-control/index.d.ts +1 -0
- package/lib/room-control/mainroom-control/index.js +181 -0
- package/lib/room-control/privilege-control/helper.d.ts +9 -0
- package/lib/room-control/privilege-control/helper.js +43 -0
- package/lib/room-control/privilege-control/index.d.ts +1 -0
- package/lib/room-control/privilege-control/index.js +245 -0
- package/lib/room-control/privilege-control/type.d.ts +293 -0
- package/lib/room-control/privilege-control/type.js +141 -0
- package/lib/room-control/room-connector-control/index.d.ts +1 -0
- package/lib/room-control/room-connector-control/index.js +160 -0
- package/lib/room-control/room-connector-control/type.d.ts +102 -0
- package/lib/room-control/room-connector-control/type.js +34 -0
- package/lib/room-control/room-session/index.d.ts +1 -0
- package/lib/room-control/room-session/index.js +286 -0
- package/lib/room-control/room-session/type.d.ts +61 -0
- package/lib/room-control/room-session/type.js +5 -0
- package/lib/room-control/stream-control/index.d.ts +1 -0
- package/lib/room-control/stream-control/index.js +341 -0
- package/lib/room-control/stream-control/type.d.ts +209 -0
- package/lib/room-control/stream-control/type.js +5 -0
- package/lib/room-control/type.d.ts +281 -0
- package/lib/room-control/type.js +23 -0
- package/lib/room-control/user-control/index.d.ts +1 -0
- package/lib/room-control/user-control/index.js +318 -0
- package/lib/room-control/user-control/type.d.ts +177 -0
- package/lib/room-control/user-control/type.js +17 -0
- package/lib/room-control/waitingroom-control/index.d.ts +1 -0
- package/lib/room-control/waitingroom-control/index.js +46 -0
- package/lib/room-control/whiteboard-control/board-window.d.ts +47 -0
- package/lib/room-control/whiteboard-control/board-window.js +396 -0
- package/lib/room-control/whiteboard-control/enums.d.ts +164 -0
- package/lib/room-control/whiteboard-control/enums.js +96 -0
- package/lib/room-control/whiteboard-control/index.d.ts +1 -0
- package/lib/room-control/whiteboard-control/index.js +342 -0
- package/lib/room-control/whiteboard-control/mount-manager.d.ts +4 -0
- package/lib/room-control/whiteboard-control/mount-manager.js +15 -0
- package/lib/room-control/whiteboard-control/types.d.ts +330 -0
- package/lib/room-control/whiteboard-control/types.js +12 -0
- package/lib/room-control/whiteboard-control/utils.d.ts +51 -0
- package/lib/room-control/whiteboard-control/utils.js +273 -0
- package/lib/room-control/whiteboard-control-v2/index.d.ts +35 -0
- package/lib/room-control/whiteboard-control-v2/index.js +242 -0
- package/lib/room-control/whiteboard-control-v2/main-window.d.ts +33 -0
- package/lib/room-control/whiteboard-control-v2/main-window.js +213 -0
- package/lib/room-control/whiteboard-control-v2/utils.d.ts +3 -0
- package/lib/room-control/whiteboard-control-v2/utils.js +39 -0
- package/lib/service/api.d.ts +401 -0
- package/lib/service/api.js +924 -0
- package/lib/service/type.d.ts +7 -0
- package/lib/service/type.js +5 -0
- package/lib/type.d.ts +254 -0
- package/lib/type.js +87 -0
- package/lib/utilities/cmd.d.ts +1 -0
- package/lib/utilities/cmd.js +7 -0
- package/lib/utilities/collection.d.ts +22 -0
- package/lib/utilities/collection.js +74 -0
- package/lib/utilities/error.d.ts +41 -0
- package/lib/utilities/error.js +68 -0
- package/lib/utilities/package-info.d.ts +1 -0
- package/lib/utilities/package-info.js +12 -0
- package/lib/utilities/parameters.d.ts +9 -0
- package/lib/utilities/parameters.js +30 -0
- package/lib/utilities/stream.d.ts +27 -0
- package/lib/utilities/stream.js +34 -0
- package/lib/utilities/user.d.ts +7 -0
- package/lib/utilities/user.js +34 -0
- package/package.json +98 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.array.push.js");
|
|
4
|
+
require("core-js/modules/esnext.async-iterator.filter.js");
|
|
5
|
+
require("core-js/modules/esnext.async-iterator.for-each.js");
|
|
6
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
7
|
+
require("core-js/modules/esnext.iterator.filter.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
10
|
+
Object.defineProperty(exports, "__esModule", {
|
|
11
|
+
value: true
|
|
12
|
+
});
|
|
13
|
+
exports.FcrChatRoomControlImpl = void 0;
|
|
14
|
+
require("core-js/modules/es.error.cause.js");
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
var _observable = require("agora-foundation/lib/utilities/observable");
|
|
17
|
+
var _easemobWebsdk = _interopRequireDefault(require("easemob-websdk"));
|
|
18
|
+
var _user = require("../../utilities/user");
|
|
19
|
+
var _error = require("../../utilities/error");
|
|
20
|
+
var _logger = require("agora-foundation/lib/logger");
|
|
21
|
+
var _type = require("./type");
|
|
22
|
+
var _type2 = require("../../chat-connection/type");
|
|
23
|
+
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; }
|
|
24
|
+
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; }
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
class FcrChatRoomControlImpl {
|
|
29
|
+
_setConnectionState(state) {
|
|
30
|
+
this._connectionState = state;
|
|
31
|
+
this._observable.notifyObservers('onConnectionStateUpdated', this._scene.sceneId, state);
|
|
32
|
+
}
|
|
33
|
+
get conn() {
|
|
34
|
+
if (!this._chatConnection.getConnectionInstance()) {
|
|
35
|
+
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'));
|
|
36
|
+
}
|
|
37
|
+
return this._chatConnection.getConnectionInstance();
|
|
38
|
+
}
|
|
39
|
+
get chatRoomId() {
|
|
40
|
+
return this._scene.getScenePropertiesByKeyPath('widgets.easemobIM.extra.chatRoomId');
|
|
41
|
+
}
|
|
42
|
+
constructor(_engine, _scene, _api, _chatConnection, _chatIpList, _restIpList) {
|
|
43
|
+
(0, _defineProperty2.default)(this, "logger", (0, _logger.getLogger)());
|
|
44
|
+
(0, _defineProperty2.default)(this, "_observable", new _observable.AgoraObservable());
|
|
45
|
+
(0, _defineProperty2.default)(this, "_connectionState", _type.FcrChatRoomConnectionState.Disconnected);
|
|
46
|
+
(0, _defineProperty2.default)(this, "_chatConnectionObserver", {
|
|
47
|
+
onConnectionStateUpdated: async state => {
|
|
48
|
+
this._joinChatRoom(state);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
(0, _defineProperty2.default)(this, "_joinChatRoom", async state => {
|
|
52
|
+
if (state === _type2.FcrChatConnectionState.DISCONNECTED && this.getConnectionState() === _type.FcrChatRoomConnectionState.Connected) {
|
|
53
|
+
this._setConnectionState(_type.FcrChatRoomConnectionState.Connecting);
|
|
54
|
+
await this.conn.joinChatRoom({
|
|
55
|
+
roomId: this.chatRoomId
|
|
56
|
+
});
|
|
57
|
+
this._setConnectionState(_type.FcrChatRoomConnectionState.Connected);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
(0, _defineProperty2.default)(this, "_convertAgoraChatMessageToFcrChatRoomReceiveMessage", msg => {
|
|
61
|
+
// TODO: 没看到有 contentsType 字段
|
|
62
|
+
//@ts-ignore
|
|
63
|
+
switch (msg.type) {
|
|
64
|
+
case 'txt':
|
|
65
|
+
{
|
|
66
|
+
const message = {
|
|
67
|
+
id: msg.id,
|
|
68
|
+
//@ts-ignore
|
|
69
|
+
from: msg.ext.sender,
|
|
70
|
+
type: _type.FcrChatRoomMessageType.Text,
|
|
71
|
+
//@ts-ignore
|
|
72
|
+
timestamp: parseInt(msg.time),
|
|
73
|
+
//@ts-ignore
|
|
74
|
+
content: msg.msg,
|
|
75
|
+
//@ts-ignore
|
|
76
|
+
isPrivate: msg.ext.isPrivate
|
|
77
|
+
};
|
|
78
|
+
return message;
|
|
79
|
+
}
|
|
80
|
+
// TODO: 3.x
|
|
81
|
+
// case 'IMAGE': {
|
|
82
|
+
// const message: FcrChatRoomReceiveImageMessage = {
|
|
83
|
+
// id: msg.id,
|
|
84
|
+
// //@ts-ignore
|
|
85
|
+
// from: msg.ext.sender,
|
|
86
|
+
// type: FcrChatRoomMessageType.Image,
|
|
87
|
+
// //@ts-ignore
|
|
88
|
+
// timestamp: parseInt(msg.time),
|
|
89
|
+
// //@ts-ignore
|
|
90
|
+
// file: msg.url,
|
|
91
|
+
// //@ts-ignore
|
|
92
|
+
// isPrivate: msg.ext.isPrivate,
|
|
93
|
+
// };
|
|
94
|
+
// return message;
|
|
95
|
+
// }
|
|
96
|
+
}
|
|
97
|
+
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown remote message type', new Error('unknown remote message type'));
|
|
98
|
+
});
|
|
99
|
+
(0, _defineProperty2.default)(this, "_convertFcrChatRoomSendBaseMessageToAgoraChatMessage", msg => {
|
|
100
|
+
var _message$to;
|
|
101
|
+
switch (msg.type) {
|
|
102
|
+
case _type.FcrChatRoomMessageType.Text:
|
|
103
|
+
const message = msg;
|
|
104
|
+
const isPrivate = !!((_message$to = message.to) !== null && _message$to !== void 0 && _message$to.length);
|
|
105
|
+
const localUserInfo = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
|
|
106
|
+
return _easemobWebsdk.default.message.create({
|
|
107
|
+
to: this.chatRoomId,
|
|
108
|
+
msg: message.content,
|
|
109
|
+
type: 'txt',
|
|
110
|
+
chatType: 'chatRoom',
|
|
111
|
+
ext: {
|
|
112
|
+
sender: (0, _user.convertRteUserToFcrUser)(localUserInfo),
|
|
113
|
+
roomUuid: this._scene.sceneId,
|
|
114
|
+
isPrivate
|
|
115
|
+
},
|
|
116
|
+
receiverList: message.to
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
throw (0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'unknown local message type', new Error('unknown local message type'));
|
|
120
|
+
});
|
|
121
|
+
this._engine = _engine;
|
|
122
|
+
this._scene = _scene;
|
|
123
|
+
this._api = _api;
|
|
124
|
+
this._chatConnection = _chatConnection;
|
|
125
|
+
this._chatIpList = _chatIpList;
|
|
126
|
+
this._restIpList = _restIpList;
|
|
127
|
+
this._chatConnection.addObserver(this._chatConnectionObserver);
|
|
128
|
+
this._join();
|
|
129
|
+
this._addEventListener();
|
|
130
|
+
}
|
|
131
|
+
async _join() {
|
|
132
|
+
await this._joinChatRoom(this._chatConnection.getConnectionState());
|
|
133
|
+
}
|
|
134
|
+
_removeEventListener() {
|
|
135
|
+
this.conn.removeEventHandler("chatroom".concat(this._scene.sceneId));
|
|
136
|
+
}
|
|
137
|
+
_addEventListener() {
|
|
138
|
+
this.conn.addEventHandler("chatroom".concat(this._scene.sceneId), {
|
|
139
|
+
onTextMessage: msg => {
|
|
140
|
+
if (msg.to !== this._scene.getScenePropertiesByKeyPath('widgets.easemobIM.extra.chatRoomId')) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const message = this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(msg);
|
|
144
|
+
this._observable.notifyObservers('onTextMessageReceived', this._scene.sceneId, message);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
// TODO: 3.x
|
|
148
|
+
// this.conn.onPictureMessage = (msg) => {
|
|
149
|
+
// if (msg.to !== this.initConfig.chatRoomId) {
|
|
150
|
+
// return;
|
|
151
|
+
// }
|
|
152
|
+
// const message: FcrChatRoomReceiveImageMessage =
|
|
153
|
+
// this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(
|
|
154
|
+
// msg,
|
|
155
|
+
// ) as FcrChatRoomReceiveImageMessage;
|
|
156
|
+
// this._observable.notifyObservers('onImageMessageReceived', this._scene.sceneId, message);
|
|
157
|
+
// };
|
|
158
|
+
|
|
159
|
+
// TODO: 3.x
|
|
160
|
+
// this.conn.onCmdMessage = (msg) => {
|
|
161
|
+
// if (msg.to !== this.initConfig.chatRoomId) {
|
|
162
|
+
// return;
|
|
163
|
+
// }
|
|
164
|
+
// const message: FcrChatRoomReceiveCustomMessage =
|
|
165
|
+
// this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(msg);
|
|
166
|
+
// this._observable.notifyObservers('onCustomMessageReceived', this._scene.sceneId, message);
|
|
167
|
+
// };
|
|
168
|
+
|
|
169
|
+
// TODO: 3.x
|
|
170
|
+
// this.conn.onChatroomEvent = (eventData: EasemobChat.ChatroomEvent) => {
|
|
171
|
+
// if (eventData.operation === 'updateAnnouncement') {
|
|
172
|
+
// this._observable.notifyObservers(
|
|
173
|
+
// 'onAnnouncementUpdated',
|
|
174
|
+
// this._scene.sceneId,
|
|
175
|
+
// // TODO: 应该用什么字段传递?
|
|
176
|
+
// (eventData.attributes as { [key: string]: string })?.announcement,
|
|
177
|
+
// );
|
|
178
|
+
// } else if (eventData.operation === 'deleteAnnouncement') {
|
|
179
|
+
// this._observable.notifyObservers('onAnnouncementDeleted', this._scene.sceneId);
|
|
180
|
+
// }
|
|
181
|
+
// };
|
|
182
|
+
}
|
|
183
|
+
getConnectionState() {
|
|
184
|
+
return this._connectionState;
|
|
185
|
+
}
|
|
186
|
+
async sendMessage(message) {
|
|
187
|
+
var _message$to2;
|
|
188
|
+
const msg = this._convertFcrChatRoomSendBaseMessageToAgoraChatMessage(message);
|
|
189
|
+
await this.conn.send(msg);
|
|
190
|
+
const localUserInfo = this._scene.getUser(this._scene.getLocalUser().getLocalUserId());
|
|
191
|
+
const res = _objectSpread(_objectSpread({}, message.type === _type.FcrChatRoomMessageType.Text ? {
|
|
192
|
+
content: message.content
|
|
193
|
+
} : {
|
|
194
|
+
file: message.file
|
|
195
|
+
}), {}, {
|
|
196
|
+
from: (0, _user.convertRteUserToFcrUser)(localUserInfo),
|
|
197
|
+
id: msg.id,
|
|
198
|
+
type: _type.FcrChatRoomMessageType.Text,
|
|
199
|
+
properties: message.properties,
|
|
200
|
+
timestamp: Date.now(),
|
|
201
|
+
isPrivate: !!((_message$to2 = message.to) !== null && _message$to2 !== void 0 && _message$to2.length)
|
|
202
|
+
});
|
|
203
|
+
return res;
|
|
204
|
+
}
|
|
205
|
+
addObserver(observer) {
|
|
206
|
+
this._observable.addObserver(observer);
|
|
207
|
+
}
|
|
208
|
+
removeObserver(observer) {
|
|
209
|
+
this._observable.removeObserver(observer);
|
|
210
|
+
}
|
|
211
|
+
async leave() {
|
|
212
|
+
await new Promise(async (resolve, reject) => {
|
|
213
|
+
this._removeEventListener();
|
|
214
|
+
try {
|
|
215
|
+
await this.conn.leaveChatRoom({
|
|
216
|
+
roomId: this.chatRoomId,
|
|
217
|
+
success: () => {
|
|
218
|
+
resolve(undefined);
|
|
219
|
+
},
|
|
220
|
+
error: e => {
|
|
221
|
+
reject((0, _error.generateFcrCoreClientError)(_error.FcrErrorModuleCode.ROOM_CHATROOM, _error.FcrErrorCode.UNDEFINED_ERROR, 'leave chat room failed', e));
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
} catch (e) {
|
|
225
|
+
resolve(undefined);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// TODO: 3.x
|
|
231
|
+
// /**
|
|
232
|
+
// *
|
|
233
|
+
// * @param pageSize max 50
|
|
234
|
+
// * @param startedMessageId
|
|
235
|
+
// * @returns
|
|
236
|
+
// */
|
|
237
|
+
// async getHistoryMessageList(
|
|
238
|
+
// pageSize: number,
|
|
239
|
+
// startedMessageId: string,
|
|
240
|
+
// ): Promise<Array<FcrChatRoomReceiveBaseMessage>> {
|
|
241
|
+
// if (pageSize > 50) {
|
|
242
|
+
// throw generateFcrCoreClientError(
|
|
243
|
+
// FcrErrorModuleCode.ROOM_CHATROOM,
|
|
244
|
+
// FcrErrorCode.UNDEFINED_ERROR,
|
|
245
|
+
// 'pageSize should be less than 50',
|
|
246
|
+
// new Error('pageSize should be less than 50'),
|
|
247
|
+
// );
|
|
248
|
+
// }
|
|
249
|
+
|
|
250
|
+
// const assembleRet = await this.conn.fetchHistoryMessages({
|
|
251
|
+
// queue: this.initConfig.chatRoomId,
|
|
252
|
+
// isGroup: true,
|
|
253
|
+
// count: pageSize,
|
|
254
|
+
// start: startedMessageId,
|
|
255
|
+
// fail(error) {
|
|
256
|
+
// throw generateFcrCoreClientError(
|
|
257
|
+
// FcrErrorModuleCode.ROOM_CHATROOM,
|
|
258
|
+
// FcrErrorCode.UNDEFINED_ERROR,
|
|
259
|
+
// error.message,
|
|
260
|
+
// new Error('get history message list failed'),
|
|
261
|
+
// );
|
|
262
|
+
// },
|
|
263
|
+
// });
|
|
264
|
+
|
|
265
|
+
// const ret: FcrChatRoomReceiveBaseMessage[] = assembleRet.map((msgBody) => {
|
|
266
|
+
// return this._convertAgoraChatMessageToFcrChatRoomReceiveMessage(msgBody);
|
|
267
|
+
// });
|
|
268
|
+
// return ret;
|
|
269
|
+
// }
|
|
270
|
+
|
|
271
|
+
// TODO: 3.x
|
|
272
|
+
// async getAnnouncement(): Promise<string> {
|
|
273
|
+
// const announcement = await this.conn.fetchChatRoomAnnouncement({
|
|
274
|
+
// roomId: this.initConfig.chatRoomId,
|
|
275
|
+
// error: (e) => {
|
|
276
|
+
// throw generateFcrCoreClientError(
|
|
277
|
+
// FcrErrorModuleCode.ROOM_CHATROOM,
|
|
278
|
+
// FcrErrorCode.UNDEFINED_ERROR,
|
|
279
|
+
// e.message,
|
|
280
|
+
// new Error('get announcement failed'),
|
|
281
|
+
// );
|
|
282
|
+
// },
|
|
283
|
+
// });
|
|
284
|
+
|
|
285
|
+
// return announcement.data?.announcement || '';
|
|
286
|
+
// }
|
|
287
|
+
|
|
288
|
+
// TODO: 3.x
|
|
289
|
+
// async setAnnouncement(announcement: string) {
|
|
290
|
+
// await this.conn.updateChatRoomAnnouncement({
|
|
291
|
+
// roomId: this.initConfig.chatRoomId,
|
|
292
|
+
// announcement,
|
|
293
|
+
// success: (_) => {},
|
|
294
|
+
// error: (e) => {
|
|
295
|
+
// throw generateFcrCoreClientError(
|
|
296
|
+
// FcrErrorModuleCode.ROOM_CHATROOM,
|
|
297
|
+
// FcrErrorCode.UNDEFINED_ERROR,
|
|
298
|
+
// e.message,
|
|
299
|
+
// new Error('set announcement failed'),
|
|
300
|
+
// );
|
|
301
|
+
// },
|
|
302
|
+
// });
|
|
303
|
+
// }
|
|
304
|
+
|
|
305
|
+
// TODO: 3.x
|
|
306
|
+
// async deleteAnnouncement() {
|
|
307
|
+
// await this.conn.updateChatRoomAnnouncement({
|
|
308
|
+
// roomId: this.initConfig.chatRoomId,
|
|
309
|
+
// announcement: '',
|
|
310
|
+
// success: (_) => {},
|
|
311
|
+
// error: (e) => {
|
|
312
|
+
// const { message } = e;
|
|
313
|
+
// throw generateFcrCoreClientError(
|
|
314
|
+
// FcrErrorModuleCode.ROOM_CHATROOM,
|
|
315
|
+
// FcrErrorCode.UNDEFINED_ERROR,
|
|
316
|
+
// message,
|
|
317
|
+
// new Error('delete announcement failed'),
|
|
318
|
+
// );
|
|
319
|
+
// },
|
|
320
|
+
// });
|
|
321
|
+
// }
|
|
322
|
+
}
|
|
323
|
+
exports.FcrChatRoomControlImpl = FcrChatRoomControlImpl;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { FcrUserInfo } from '../../type';
|
|
2
|
+
import { FcrError } from '../../utilities/error';
|
|
3
|
+
export interface FcrChatRoomControl {
|
|
4
|
+
join(): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Gets the connection state of the chat room.
|
|
7
|
+
*/
|
|
8
|
+
getConnectionState(): FcrChatRoomConnectionState;
|
|
9
|
+
/**
|
|
10
|
+
* Sends a message to the chat room.
|
|
11
|
+
* @param message
|
|
12
|
+
*/
|
|
13
|
+
sendMessage(message: FcrChatRoomSendBaseMessage): Promise<FcrChatRoomReceiveBaseMessage>;
|
|
14
|
+
/**
|
|
15
|
+
* Adds an observer to the chat room.
|
|
16
|
+
* @param observer
|
|
17
|
+
*/
|
|
18
|
+
addObserver(observer: FcrChatRoomObserver): void;
|
|
19
|
+
/**
|
|
20
|
+
* Removes the observer from the chat room.
|
|
21
|
+
* @param observer
|
|
22
|
+
*/
|
|
23
|
+
removeObserver(observer: FcrChatRoomObserver): void;
|
|
24
|
+
}
|
|
25
|
+
export declare enum FcrChatRoomConnectionState {
|
|
26
|
+
Disconnected = 0,
|
|
27
|
+
Connecting = 1,
|
|
28
|
+
Connected = 2
|
|
29
|
+
}
|
|
30
|
+
export declare enum FcrChatRoomMessageType {
|
|
31
|
+
Text = "text",
|
|
32
|
+
Image = "image",
|
|
33
|
+
Custom = "custom"
|
|
34
|
+
}
|
|
35
|
+
export type FcrChatRoomSendBaseMessage = {
|
|
36
|
+
type: FcrChatRoomMessageType;
|
|
37
|
+
properties?: Record<string, unknown>;
|
|
38
|
+
to?: string[];
|
|
39
|
+
};
|
|
40
|
+
export type FcrChatRoomSendTextMessage = FcrChatRoomSendBaseMessage & {
|
|
41
|
+
content: string;
|
|
42
|
+
};
|
|
43
|
+
export type FcrChatRoomReceiveBaseMessage = {
|
|
44
|
+
id: string;
|
|
45
|
+
from: FcrUserInfo;
|
|
46
|
+
type: FcrChatRoomMessageType;
|
|
47
|
+
properties?: Record<string, unknown>;
|
|
48
|
+
timestamp: number;
|
|
49
|
+
isPrivate: boolean;
|
|
50
|
+
};
|
|
51
|
+
export type FcrChatRoomReceiveTextMessage = FcrChatRoomReceiveBaseMessage & {
|
|
52
|
+
content: string;
|
|
53
|
+
};
|
|
54
|
+
export type FcrChatRoomFile = {
|
|
55
|
+
filename: string;
|
|
56
|
+
filetype: string;
|
|
57
|
+
url: string;
|
|
58
|
+
data: any;
|
|
59
|
+
};
|
|
60
|
+
export type FcrChatRoomReceiveImageMessage = FcrChatRoomReceiveBaseMessage & {
|
|
61
|
+
file: FcrChatRoomFile;
|
|
62
|
+
};
|
|
63
|
+
export type FcrChatRoomSendImageMessage = FcrChatRoomSendBaseMessage & {
|
|
64
|
+
file: FcrChatRoomFile;
|
|
65
|
+
};
|
|
66
|
+
export type FcrChatRoomReceiveCustomMessage = FcrChatRoomReceiveBaseMessage & {};
|
|
67
|
+
export type FcrChatRoomObserver = {
|
|
68
|
+
/**
|
|
69
|
+
* Callback to receive the connection state change of the chat room.
|
|
70
|
+
* @param roomId
|
|
71
|
+
* @param state
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
onConnectionStateUpdated?: (roomId: string, state: FcrChatRoomConnectionState) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Callback to receive the message sent to the chat room.
|
|
77
|
+
* @param roomId
|
|
78
|
+
* @param message
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
onTextMessageReceived?: (roomId: string, message: FcrChatRoomReceiveTextMessage) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Callback when an error occurs.
|
|
84
|
+
* @param roomId
|
|
85
|
+
* @param error
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
onErrorOccurred?: (roomId: string, error: FcrError) => void;
|
|
89
|
+
};
|
|
90
|
+
export type FcrChatRoomControlInitConfig = {
|
|
91
|
+
appkey: string;
|
|
92
|
+
token: string;
|
|
93
|
+
roomId: string;
|
|
94
|
+
userInfo: FcrUserInfo;
|
|
95
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FcrChatRoomMessageType = exports.FcrChatRoomConnectionState = void 0;
|
|
7
|
+
let FcrChatRoomConnectionState = exports.FcrChatRoomConnectionState = /*#__PURE__*/function (FcrChatRoomConnectionState) {
|
|
8
|
+
FcrChatRoomConnectionState[FcrChatRoomConnectionState["Disconnected"] = 0] = "Disconnected";
|
|
9
|
+
FcrChatRoomConnectionState[FcrChatRoomConnectionState["Connecting"] = 1] = "Connecting";
|
|
10
|
+
FcrChatRoomConnectionState[FcrChatRoomConnectionState["Connected"] = 2] = "Connected";
|
|
11
|
+
return FcrChatRoomConnectionState;
|
|
12
|
+
}({});
|
|
13
|
+
let FcrChatRoomMessageType = exports.FcrChatRoomMessageType = /*#__PURE__*/function (FcrChatRoomMessageType) {
|
|
14
|
+
FcrChatRoomMessageType["Text"] = "text";
|
|
15
|
+
FcrChatRoomMessageType["Image"] = "image";
|
|
16
|
+
FcrChatRoomMessageType["Custom"] = "custom";
|
|
17
|
+
return FcrChatRoomMessageType;
|
|
18
|
+
}({});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AgoraRteEngine, AgoraRteScene } from '../../imports';
|
|
2
|
+
import { FcrCoreEngineConfig, FcrGroupCreateConfig, FcrGroupInfo, FcrGroupObserver, FcrGroupUpdateOptions } from '../../type';
|
|
3
|
+
import { FcrCoreServiceApi } from '../../service/api';
|
|
4
|
+
export declare class FcrGroupControl {
|
|
5
|
+
private _engine;
|
|
6
|
+
private _scene;
|
|
7
|
+
private _api;
|
|
8
|
+
private _config;
|
|
9
|
+
protected logger: import("agora-foundation/lib/logger").Logger;
|
|
10
|
+
private _observable;
|
|
11
|
+
constructor(_engine: AgoraRteEngine, _scene: AgoraRteScene, _api: FcrCoreServiceApi, _config: FcrCoreEngineConfig);
|
|
12
|
+
private _addSceneObserver;
|
|
13
|
+
private _getGroupDetails;
|
|
14
|
+
getGroupList(): FcrGroupInfo[];
|
|
15
|
+
getGroupUserList(groupId: string): string[];
|
|
16
|
+
addGroups(groups: FcrGroupCreateConfig[]): Promise<void>;
|
|
17
|
+
updateGroups(groups: FcrGroupUpdateOptions[]): Promise<void>;
|
|
18
|
+
deleteGroups(groupIds: string[]): Promise<void>;
|
|
19
|
+
deleteAllGroups(): Promise<void>;
|
|
20
|
+
addUsers(userList: string[], groupId: string): Promise<void>;
|
|
21
|
+
removeUsers(userList: string[], groupId: string): Promise<void>;
|
|
22
|
+
moveUsers(userList: string[], fromGroupId: string, toGroupId: string): Promise<void>;
|
|
23
|
+
addObserver(observer: FcrGroupObserver): void;
|
|
24
|
+
removeObserver(observer: FcrGroupObserver): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.FcrGroupControl = void 0;
|
|
8
|
+
require("core-js/modules/es.array.push.js");
|
|
9
|
+
require("core-js/modules/esnext.async-iterator.for-each.js");
|
|
10
|
+
require("core-js/modules/esnext.async-iterator.map.js");
|
|
11
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
12
|
+
require("core-js/modules/esnext.iterator.for-each.js");
|
|
13
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
14
|
+
require("core-js/modules/esnext.map.delete-all.js");
|
|
15
|
+
require("core-js/modules/esnext.map.emplace.js");
|
|
16
|
+
require("core-js/modules/esnext.map.every.js");
|
|
17
|
+
require("core-js/modules/esnext.map.filter.js");
|
|
18
|
+
require("core-js/modules/esnext.map.find.js");
|
|
19
|
+
require("core-js/modules/esnext.map.find-key.js");
|
|
20
|
+
require("core-js/modules/esnext.map.includes.js");
|
|
21
|
+
require("core-js/modules/esnext.map.key-of.js");
|
|
22
|
+
require("core-js/modules/esnext.map.map-keys.js");
|
|
23
|
+
require("core-js/modules/esnext.map.map-values.js");
|
|
24
|
+
require("core-js/modules/esnext.map.merge.js");
|
|
25
|
+
require("core-js/modules/esnext.map.reduce.js");
|
|
26
|
+
require("core-js/modules/esnext.map.some.js");
|
|
27
|
+
require("core-js/modules/esnext.map.update.js");
|
|
28
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
29
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
30
|
+
var _imports = require("../../imports");
|
|
31
|
+
var _user = require("../../utilities/user");
|
|
32
|
+
class FcrGroupControl {
|
|
33
|
+
constructor(_engine, _scene, _api, _config) {
|
|
34
|
+
(0, _defineProperty2.default)(this, "logger", (0, _imports.getLogger)());
|
|
35
|
+
(0, _defineProperty2.default)(this, "_observable", new _imports.AgoraObservable());
|
|
36
|
+
this._engine = _engine;
|
|
37
|
+
this._scene = _scene;
|
|
38
|
+
this._api = _api;
|
|
39
|
+
this._config = _config;
|
|
40
|
+
this._addSceneObserver();
|
|
41
|
+
}
|
|
42
|
+
_addSceneObserver() {
|
|
43
|
+
const observer = {
|
|
44
|
+
onScenePropertiesUpdated: (sceneId, event) => {
|
|
45
|
+
var _event$cause;
|
|
46
|
+
if (((_event$cause = event.cause) === null || _event$cause === void 0 ? void 0 : _event$cause.cmd) === 11) {
|
|
47
|
+
const data = event.cause.data;
|
|
48
|
+
const changedProperties = event.changedProperties;
|
|
49
|
+
const groupDetails = changedProperties.groups.details;
|
|
50
|
+
const groupEvents = Object.keys(groupDetails).map(groupId => {
|
|
51
|
+
return {
|
|
52
|
+
info: {
|
|
53
|
+
groupId,
|
|
54
|
+
groupName: groupDetails[groupId].groupName
|
|
55
|
+
},
|
|
56
|
+
operatorUser: event.operatorUser && (0, _user.convertRteUserToFcrUser)(event.operatorUser)
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
if (data.actionType === 2) {
|
|
60
|
+
if (data.removeGroupUuids) {
|
|
61
|
+
this._observable.notifyObservers('onGroupsRemoved', groupEvents);
|
|
62
|
+
} else {
|
|
63
|
+
this._observable.notifyObservers('onGroupsAdded', groupEvents);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (data.actionType === 3) {
|
|
67
|
+
this._observable.notifyObservers('onGroupsUpdated', groupEvents);
|
|
68
|
+
}
|
|
69
|
+
if (data.actionType === 4) {
|
|
70
|
+
var _data$changeGroups, _data$changeGroups2, _data$changeGroups3;
|
|
71
|
+
(_data$changeGroups = data.changeGroups) === null || _data$changeGroups === void 0 || _data$changeGroups.forEach(group => {
|
|
72
|
+
const {
|
|
73
|
+
removeUsers,
|
|
74
|
+
groupUuid
|
|
75
|
+
} = group;
|
|
76
|
+
if (removeUsers) {
|
|
77
|
+
this._observable.notifyObservers('onUserListRemovedFromGroup', removeUsers.map(user => {
|
|
78
|
+
return {
|
|
79
|
+
groupId: groupUuid,
|
|
80
|
+
userId: user.userUuid,
|
|
81
|
+
reason: user.reason,
|
|
82
|
+
operatorUser: event.operatorUser && (0, _user.convertRteUserToFcrUser)(event.operatorUser)
|
|
83
|
+
};
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const toGroupMap = new Map();
|
|
88
|
+
(_data$changeGroups2 = data.changeGroups) === null || _data$changeGroups2 === void 0 || _data$changeGroups2.forEach(group => {
|
|
89
|
+
const {
|
|
90
|
+
removeUsers
|
|
91
|
+
} = group;
|
|
92
|
+
if (removeUsers) {
|
|
93
|
+
removeUsers.forEach(user => {
|
|
94
|
+
if (user.toGroupUuid) {
|
|
95
|
+
const toGroup = toGroupMap.get(user.toGroupUuid);
|
|
96
|
+
if (toGroup) {
|
|
97
|
+
toGroup.userList.push({
|
|
98
|
+
userUuid: user.userUuid,
|
|
99
|
+
reason: user.reason,
|
|
100
|
+
toGroupUuid: user.toGroupUuid
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
toGroupMap.set(user.toGroupUuid, {
|
|
104
|
+
fromGroupId: group.groupUuid,
|
|
105
|
+
userList: [{
|
|
106
|
+
userUuid: user.userUuid,
|
|
107
|
+
reason: user.reason,
|
|
108
|
+
toGroupUuid: user.toGroupUuid
|
|
109
|
+
}]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
toGroupMap.forEach((toGroupInfo, toGroupUuid) => {
|
|
117
|
+
this._observable.notifyObservers('onUserListMoveToGroup', toGroupInfo.userList.map(user => {
|
|
118
|
+
return {
|
|
119
|
+
fromGroupId: toGroupInfo.fromGroupId,
|
|
120
|
+
toGroupId: toGroupUuid,
|
|
121
|
+
userId: user.userUuid,
|
|
122
|
+
reason: user.reason,
|
|
123
|
+
operatorUser: event.operatorUser && (0, _user.convertRteUserToFcrUser)(event.operatorUser)
|
|
124
|
+
};
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
(_data$changeGroups3 = data.changeGroups) === null || _data$changeGroups3 === void 0 || _data$changeGroups3.forEach(group => {
|
|
128
|
+
const {
|
|
129
|
+
addUsers,
|
|
130
|
+
groupUuid
|
|
131
|
+
} = group;
|
|
132
|
+
if (addUsers) {
|
|
133
|
+
this._observable.notifyObservers('onUserListAddedToGroup', addUsers.map(user => {
|
|
134
|
+
return {
|
|
135
|
+
groupId: groupUuid,
|
|
136
|
+
userId: user.userUuid,
|
|
137
|
+
operatorUser: event.operatorUser && (0, _user.convertRteUserToFcrUser)(event.operatorUser)
|
|
138
|
+
};
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
this._scene.addObserver(observer);
|
|
147
|
+
}
|
|
148
|
+
_getGroupDetails() {
|
|
149
|
+
return this._scene.getScenePropertiesByKeyPath('groups.details');
|
|
150
|
+
}
|
|
151
|
+
getGroupList() {
|
|
152
|
+
const groupDetails = this._getGroupDetails();
|
|
153
|
+
const list = [];
|
|
154
|
+
Object.keys(groupDetails).forEach(groupId => {
|
|
155
|
+
const {
|
|
156
|
+
groupName
|
|
157
|
+
} = groupDetails[groupId];
|
|
158
|
+
list.push({
|
|
159
|
+
groupId,
|
|
160
|
+
groupName
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
return list;
|
|
164
|
+
}
|
|
165
|
+
getGroupUserList(groupId) {
|
|
166
|
+
const groupDetails = this._getGroupDetails();
|
|
167
|
+
const groupInfo = groupDetails[groupId];
|
|
168
|
+
if (groupInfo) {
|
|
169
|
+
return groupInfo.users.map(user => user.userUuid);
|
|
170
|
+
} else {
|
|
171
|
+
this.logger.warn('group not found', groupId);
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
addGroups(groups) {
|
|
176
|
+
return this._api.addGroups(groups, {
|
|
177
|
+
roomId: this._scene.sceneId,
|
|
178
|
+
startTime: Date.now()
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
updateGroups(groups) {
|
|
182
|
+
return this._api.updateGroups(groups, {
|
|
183
|
+
roomId: this._scene.sceneId
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
deleteGroups(groupIds) {
|
|
187
|
+
return this._api.deleteGroups(groupIds, {
|
|
188
|
+
roomId: this._scene.sceneId
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
deleteAllGroups() {
|
|
192
|
+
return this._api.deleteAllGroups({
|
|
193
|
+
roomId: this._scene.sceneId
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
addUsers(userList, groupId) {
|
|
197
|
+
return this._api.addUsers(userList, groupId, {
|
|
198
|
+
roomId: this._scene.sceneId
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
removeUsers(userList, groupId) {
|
|
202
|
+
return this._api.removeUsers(userList, groupId, {
|
|
203
|
+
roomId: this._scene.sceneId
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
moveUsers(userList, fromGroupId, toGroupId) {
|
|
207
|
+
return this._api.moveUsers(userList, fromGroupId, toGroupId, {
|
|
208
|
+
roomId: this._scene.sceneId
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
// createSubRoomControl(groupId: string) {
|
|
212
|
+
// return new FcrSubRoomControlImpl(
|
|
213
|
+
// this._engine,
|
|
214
|
+
// this._engine.createScene({ sceneId: groupId }),
|
|
215
|
+
// this._api,
|
|
216
|
+
// this._config,
|
|
217
|
+
// 101
|
|
218
|
+
// );
|
|
219
|
+
// }
|
|
220
|
+
addObserver(observer) {
|
|
221
|
+
this._observable.addObserver(observer);
|
|
222
|
+
}
|
|
223
|
+
removeObserver(observer) {
|
|
224
|
+
this._observable.removeObserver(observer);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.FcrGroupControl = FcrGroupControl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|