agora-appbuilder-core 2.0.1 → 2.0.3-rc2
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/Readme.md +2 -1
- package/package.json +1 -1
- package/template/_package-lock.json +8853 -8806
- package/template/agora-rn-uikit/.git/index +0 -0
- package/template/agora-rn-uikit/.git/logs/HEAD +2 -2
- package/template/agora-rn-uikit/.git/logs/refs/heads/ab-dev-auto +1 -1
- package/template/agora-rn-uikit/.git/logs/refs/heads/master +1 -1
- package/template/agora-rn-uikit/.git/logs/refs/remotes/origin/HEAD +1 -1
- package/template/agora-rn-uikit/.git/objects/pack/pack-2a0122bf5a3199f941e5a52535f43881623f752c.idx +0 -0
- package/template/agora-rn-uikit/.git/objects/pack/{pack-f379286d0537eb68377220b4929979324b8d5d1c.pack → pack-2a0122bf5a3199f941e5a52535f43881623f752c.pack} +0 -0
- package/template/agora-rn-uikit/.git/packed-refs +4 -2
- package/template/agora-rn-uikit/.git/refs/heads/ab-dev-auto +1 -1
- package/template/agora-rn-uikit/src/Contexts/PropsContext.tsx +21 -0
- package/template/agora-rn-uikit/src/Controls/BtnTemplate.tsx +22 -14
- package/template/agora-rn-uikit/src/Controls/ImageIcon.tsx +17 -13
- package/template/agora-rn-uikit/src/Controls/types.ts +4 -0
- package/template/agora-rn-uikit/src/Rtc/Create.tsx +117 -19
- package/template/agora-rn-uikit/src/RtcConfigure.tsx +24 -13
- package/template/{src/utils/isSafariBrowser.tsx → agora-rn-uikit/src/Utils/isSafariBrowser.ts} +3 -0
- package/template/{src → agora-rn-uikit/src}/hooks/useImageDelay.tsx +5 -2
- package/template/agora-rn-uikit/src/index.ts +2 -0
- package/template/bridge/rtc/webNg/RtcEngine.ts +73 -70
- package/template/bridge/rtc/webNg/Types.ts +59 -5
- package/template/bridge/rtm/web/Types.ts +13 -0
- package/template/bridge/rtm/web/index.ts +78 -1
- package/template/global.d.ts +2 -0
- package/template/package-lock.json +8853 -8806
- package/template/package.json +3 -4
- package/template/react-native-toast-message/src/components/base/styles.js +4 -2
- package/template/src/assets/icons.ts +41 -28
- package/template/src/components/Chat.tsx +70 -184
- package/template/src/components/ChatContext.ts +13 -2
- package/template/src/components/Controls.native.tsx +37 -76
- package/template/src/components/Controls.tsx +50 -158
- package/template/src/components/DeviceConfigure.native.tsx +5 -1
- package/template/src/components/DeviceConfigure.tsx +38 -20
- package/template/src/components/Navbar.tsx +185 -226
- package/template/src/components/ParticipantsView.tsx +176 -184
- package/template/src/components/Precall.native.tsx +83 -69
- package/template/src/components/Precall.tsx +174 -191
- package/template/src/components/RTMConfigure.tsx +264 -78
- package/template/src/components/SettingsView.tsx +9 -19
- package/template/src/components/livestream/LiveStreamContext.tsx +411 -0
- package/template/src/components/livestream/Types.ts +69 -0
- package/template/src/components/livestream/index.ts +9 -0
- package/template/src/components/livestream/views/LiveStreamControls.tsx +27 -0
- package/template/src/components/participants/AllAudienceParticipants.tsx +53 -0
- package/template/src/components/participants/AllHostParticipants.tsx +65 -0
- package/template/src/components/participants/MeParticipant.tsx +37 -0
- package/template/src/components/participants/ParticipantName.tsx +47 -0
- package/template/src/components/participants/ParticipantSectionTitle.tsx +29 -0
- package/template/src/components/participants/RemoteParticipants.tsx +69 -0
- package/template/src/components/participants/ScreenshareParticipants.tsx +28 -0
- package/template/src/components/participants/context/ParticipantContext.tsx +97 -0
- package/template/src/components/styles.ts +13 -0
- package/template/src/pages/Create.tsx +25 -14
- package/template/src/pages/VideoCall.tsx +197 -159
- package/template/src/subComponents/ChatBubble.tsx +4 -1
- package/template/src/subComponents/ChatContainer.tsx +44 -20
- package/template/src/subComponents/ChatInput.tsx +4 -12
- package/template/src/subComponents/Checkbox.native.tsx +6 -5
- package/template/src/subComponents/Checkbox.tsx +1 -0
- package/template/src/subComponents/Recording.tsx +23 -9
- package/template/src/subComponents/RemoteVideoMute.tsx +2 -3
- package/template/src/subComponents/SelectDevice.tsx +70 -35
- package/template/src/subComponents/chat/ChatParticipants.tsx +121 -0
- package/template/src/subComponents/livestream/ApprovedLiveStreamControlsView.tsx +23 -0
- package/template/src/subComponents/livestream/CurrentLiveStreamRequestsView.tsx +70 -0
- package/template/src/subComponents/livestream/controls/LocalRaiseHand.tsx +57 -0
- package/template/src/subComponents/livestream/controls/RemoteLiveStreamApprovedRequestRecall.tsx +24 -0
- package/template/src/subComponents/livestream/controls/RemoteLiveStreamRequestApprove.tsx +38 -0
- package/template/src/subComponents/livestream/controls/RemoteLiveStreamRequestReject.tsx +37 -0
- package/template/src/subComponents/livestream/index.ts +18 -0
- package/template/src/subComponents/screenshare/ScreenshareButton.tsx +80 -0
- package/template/src/subComponents/screenshare/ScreenshareConfigure.native.tsx +24 -0
- package/template/src/subComponents/screenshare/ScreenshareConfigure.tsx +200 -0
- package/template/src/subComponents/screenshare/ScreenshareContext.tsx +21 -0
- package/template/src/utils/index.tsx +48 -0
- package/template/agora-rn-uikit/.git/objects/pack/pack-f379286d0537eb68377220b4929979324b8d5d1c.idx +0 -0
|
@@ -16,19 +16,20 @@ import AgoraRTC, {
|
|
|
16
16
|
IRemoteAudioTrack,
|
|
17
17
|
IRemoteVideoTrack,
|
|
18
18
|
UID,
|
|
19
|
-
CameraVideoTrackInitConfig,
|
|
20
19
|
ScreenVideoTrackInitConfig,
|
|
21
20
|
RemoteStreamType,
|
|
22
|
-
ClientConfig,
|
|
23
21
|
ICameraVideoTrack,
|
|
24
22
|
EncryptionMode,
|
|
25
23
|
ILocalTrack,
|
|
24
|
+
ClientRoleOptions,
|
|
26
25
|
} from 'agora-rtc-sdk-ng';
|
|
27
26
|
import type {
|
|
28
27
|
RtcEngineEvents,
|
|
29
28
|
Subscription,
|
|
30
29
|
} from 'react-native-agora/lib/typescript/src/common/RtcEvents';
|
|
31
|
-
import {
|
|
30
|
+
import {VideoProfile} from '../quality';
|
|
31
|
+
import {ChannelProfile, ClientRole} from '../../../agora-rn-uikit';
|
|
32
|
+
import {role, mode} from './Types';
|
|
32
33
|
|
|
33
34
|
interface MediaDeviceInfo {
|
|
34
35
|
readonly deviceId: string;
|
|
@@ -43,6 +44,7 @@ declare global {
|
|
|
43
44
|
engine: RtcEngine;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
|
|
46
48
|
export enum AREAS {
|
|
47
49
|
/**
|
|
48
50
|
* China.
|
|
@@ -141,8 +143,8 @@ AgoraRTC.setArea({
|
|
|
141
143
|
export default class RtcEngine {
|
|
142
144
|
public appId: string;
|
|
143
145
|
// public AgoraRTC: any;
|
|
144
|
-
public client: IAgoraRTCClient;
|
|
145
|
-
public screenClient: IAgoraRTCClient;
|
|
146
|
+
public client: any | IAgoraRTCClient;
|
|
147
|
+
public screenClient: any | IAgoraRTCClient;
|
|
146
148
|
public eventsMap = new Map<string, callbackType>([
|
|
147
149
|
['UserJoined', () => null],
|
|
148
150
|
['UserOffline', () => null],
|
|
@@ -155,12 +157,7 @@ export default class RtcEngine {
|
|
|
155
157
|
public localStream: LocalStream = {};
|
|
156
158
|
public screenStream: ScreenStream = {};
|
|
157
159
|
public remoteStreams = new Map<UID, RemoteStream>();
|
|
158
|
-
// public streamSpec: AgoraRTC.StreamSpec;
|
|
159
|
-
// public streamSpecScreenshare: ScreenVideoTrackInitConfig;
|
|
160
160
|
private inScreenshare: Boolean = false;
|
|
161
|
-
// private removeStream = (uid: UID) => {
|
|
162
|
-
|
|
163
|
-
// };
|
|
164
161
|
private videoProfile: VideoProfile = '480p_9';
|
|
165
162
|
private isPublished = false;
|
|
166
163
|
private isAudioEnabled = true;
|
|
@@ -171,45 +168,16 @@ export default class RtcEngine {
|
|
|
171
168
|
private deviceId = '';
|
|
172
169
|
private muteLocalVideoMutex = false;
|
|
173
170
|
|
|
171
|
+
// Create channel profile and set it here
|
|
172
|
+
|
|
174
173
|
constructor(appId: string) {
|
|
175
174
|
this.appId = appId;
|
|
176
175
|
// this.AgoraRTC = AgoraRTC;
|
|
177
|
-
this.client = AgoraRTC.createClient({
|
|
178
|
-
codec: 'vp8',
|
|
179
|
-
mode: 'rtc',
|
|
180
|
-
});
|
|
181
|
-
this.screenClient = AgoraRTC.createClient({
|
|
182
|
-
codec: 'vp8',
|
|
183
|
-
mode: 'rtc',
|
|
184
|
-
});
|
|
185
|
-
// this.streamSpec = {
|
|
186
|
-
// video: true,
|
|
187
|
-
// audio: true,
|
|
188
|
-
// };
|
|
189
|
-
// this.streamSpecScreenshare = {
|
|
190
|
-
// audio: false,
|
|
191
|
-
// video: false,
|
|
192
|
-
// screen: true,
|
|
193
|
-
// screenAudio: true,
|
|
194
|
-
// };
|
|
195
176
|
}
|
|
177
|
+
|
|
196
178
|
static async create(appId: string): Promise<RtcEngine> {
|
|
197
179
|
let engine = new RtcEngine(appId);
|
|
198
180
|
window.engine = engine;
|
|
199
|
-
// let init = new Promise((resolve, reject) => {
|
|
200
|
-
// engine.client.init(
|
|
201
|
-
// appId,
|
|
202
|
-
// function () {
|
|
203
|
-
// window.engine = engine;
|
|
204
|
-
// resolve();
|
|
205
|
-
// },
|
|
206
|
-
// function (err) {
|
|
207
|
-
// console.error(err);
|
|
208
|
-
// reject();
|
|
209
|
-
// },
|
|
210
|
-
// );
|
|
211
|
-
// });
|
|
212
|
-
// await init;
|
|
213
181
|
return engine;
|
|
214
182
|
}
|
|
215
183
|
|
|
@@ -222,25 +190,15 @@ export default class RtcEngine {
|
|
|
222
190
|
let [localAudio, localVideo] =
|
|
223
191
|
await AgoraRTC.createMicrophoneAndCameraTracks(
|
|
224
192
|
{},
|
|
225
|
-
{
|
|
193
|
+
{encoderConfig: this.videoProfile},
|
|
226
194
|
);
|
|
227
|
-
// localVideo.setEncoderConfiguration(this.videoProfile);
|
|
228
195
|
this.localStream.audio = localAudio;
|
|
229
196
|
this.localStream.video = localVideo;
|
|
230
197
|
} catch (e) {
|
|
231
198
|
throw e;
|
|
232
199
|
}
|
|
233
|
-
// let enable = new Promise((resolve, reject) => {
|
|
234
|
-
// this.streams.set(0, );
|
|
235
|
-
// (this.streams.get(0) as AgoraRTC.Stream).setVideoProfile(
|
|
236
|
-
// this.videoProfile,
|
|
237
|
-
// );
|
|
238
|
-
// (this.streams.get(0) as AgoraRTC.Stream).init(() => {
|
|
239
|
-
// resolve();
|
|
240
|
-
// }, reject);
|
|
241
|
-
// });
|
|
242
|
-
// await enable;
|
|
243
200
|
}
|
|
201
|
+
|
|
244
202
|
async publish() {
|
|
245
203
|
if (this.localStream.audio && this.localStream.video) {
|
|
246
204
|
try {
|
|
@@ -249,7 +207,6 @@ export default class RtcEngine {
|
|
|
249
207
|
this.isVideoEnabled && tracks.push(this.localStream.video);
|
|
250
208
|
|
|
251
209
|
if (tracks.length > 0) {
|
|
252
|
-
console.log('publishing now');
|
|
253
210
|
await this.client.publish(tracks);
|
|
254
211
|
if (tracks[0].trackMediaType === 'audio') {
|
|
255
212
|
this.isAudioPublished = true;
|
|
@@ -281,6 +238,7 @@ export default class RtcEngine {
|
|
|
281
238
|
optionalInfo: string,
|
|
282
239
|
optionalUid: number,
|
|
283
240
|
): Promise<void> {
|
|
241
|
+
// TODO create agora client here
|
|
284
242
|
this.client.on('user-joined', (user) => {
|
|
285
243
|
const uid = this.inScreenshare
|
|
286
244
|
? user.uid !== this.screenClient.uid
|
|
@@ -308,7 +266,6 @@ export default class RtcEngine {
|
|
|
308
266
|
? user.uid
|
|
309
267
|
: 1
|
|
310
268
|
: user.uid;
|
|
311
|
-
|
|
312
269
|
// if (uid ===1) {
|
|
313
270
|
// this.screenStream.audio?.close();
|
|
314
271
|
// this.screenStream.video?.close();
|
|
@@ -333,7 +290,6 @@ export default class RtcEngine {
|
|
|
333
290
|
} else {
|
|
334
291
|
await this.client.subscribe(user, mediaType);
|
|
335
292
|
}
|
|
336
|
-
|
|
337
293
|
// If the subscribed track is an audio track
|
|
338
294
|
if (mediaType === 'audio') {
|
|
339
295
|
const audioTrack = user.audioTrack;
|
|
@@ -367,7 +323,7 @@ export default class RtcEngine {
|
|
|
367
323
|
});
|
|
368
324
|
this.client.on('user-unpublished', async (user, mediaType) => {
|
|
369
325
|
if (mediaType === 'audio') {
|
|
370
|
-
const {
|
|
326
|
+
const {audio, ...rest} = this.remoteStreams.get(user.uid);
|
|
371
327
|
this.remoteStreams.set(user.uid, rest);
|
|
372
328
|
(this.eventsMap.get('RemoteAudioStateChanged') as callbackType)(
|
|
373
329
|
user.uid,
|
|
@@ -376,7 +332,7 @@ export default class RtcEngine {
|
|
|
376
332
|
0,
|
|
377
333
|
);
|
|
378
334
|
} else {
|
|
379
|
-
const {
|
|
335
|
+
const {video, ...rest} = this.remoteStreams.get(user.uid);
|
|
380
336
|
this.remoteStreams.set(user.uid, rest);
|
|
381
337
|
(this.eventsMap.get('RemoteVideoStateChanged') as callbackType)(
|
|
382
338
|
user.uid,
|
|
@@ -388,22 +344,35 @@ export default class RtcEngine {
|
|
|
388
344
|
});
|
|
389
345
|
|
|
390
346
|
// this.client.on('stream-fallback', (evt))
|
|
391
|
-
this.client.on('stream-type-changed', function(uid, streamType) {
|
|
347
|
+
this.client.on('stream-type-changed', function (uid, streamType) {
|
|
392
348
|
console.log('[fallback]: ', uid, streamType);
|
|
393
349
|
});
|
|
394
350
|
|
|
395
|
-
this.client.on(
|
|
396
|
-
|
|
351
|
+
this.client.on(
|
|
352
|
+
'network-quality',
|
|
353
|
+
async ({downlinkNetworkQuality, uplinkNetworkQuality}) => {
|
|
354
|
+
const networkQualityIndicatorCallback = this.eventsMap.get(
|
|
355
|
+
'NetworkQuality',
|
|
356
|
+
) as callbackType;
|
|
397
357
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
358
|
+
networkQualityIndicatorCallback(
|
|
359
|
+
0,
|
|
360
|
+
downlinkNetworkQuality,
|
|
361
|
+
uplinkNetworkQuality,
|
|
362
|
+
);
|
|
401
363
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
})
|
|
364
|
+
const remoteUserNetworkQualities =
|
|
365
|
+
this.client.getRemoteNetworkQuality();
|
|
405
366
|
|
|
406
|
-
|
|
367
|
+
Object.keys(remoteUserNetworkQualities).forEach((uid) => {
|
|
368
|
+
networkQualityIndicatorCallback(
|
|
369
|
+
uid,
|
|
370
|
+
remoteUserNetworkQualities[uid].downlinkNetworkQuality,
|
|
371
|
+
remoteUserNetworkQualities[uid].uplinkNetworkQuality,
|
|
372
|
+
);
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
);
|
|
407
376
|
|
|
408
377
|
await this.client.join(
|
|
409
378
|
this.appId,
|
|
@@ -412,10 +381,10 @@ export default class RtcEngine {
|
|
|
412
381
|
optionalUid || null,
|
|
413
382
|
);
|
|
414
383
|
this.isJoined = true;
|
|
384
|
+
|
|
415
385
|
await this.publish();
|
|
416
386
|
}
|
|
417
387
|
|
|
418
|
-
|
|
419
388
|
async leaveChannel(): Promise<void> {
|
|
420
389
|
this.client.leave();
|
|
421
390
|
this.remoteStreams.forEach((stream, uid, map) => {
|
|
@@ -521,6 +490,40 @@ export default class RtcEngine {
|
|
|
521
490
|
return devices;
|
|
522
491
|
}
|
|
523
492
|
|
|
493
|
+
async setChannelProfile(profile: ChannelProfile): Promise<void> {
|
|
494
|
+
try {
|
|
495
|
+
this.client = AgoraRTC.createClient({
|
|
496
|
+
codec: 'vp8',
|
|
497
|
+
mode:
|
|
498
|
+
profile === ChannelProfile.LiveBroadcasting ? mode.live : mode.rtc,
|
|
499
|
+
});
|
|
500
|
+
this.screenClient = AgoraRTC.createClient({
|
|
501
|
+
codec: 'vp8',
|
|
502
|
+
mode:
|
|
503
|
+
profile === ChannelProfile.LiveBroadcasting ? mode.live : mode.rtc,
|
|
504
|
+
});
|
|
505
|
+
} catch (e) {
|
|
506
|
+
throw e;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async setClientRole(
|
|
511
|
+
clientRole: ClientRole,
|
|
512
|
+
options?: ClientRoleOptions,
|
|
513
|
+
): Promise<void> {
|
|
514
|
+
try {
|
|
515
|
+
if (clientRole == ClientRole.Audience) {
|
|
516
|
+
await this.client.setClientRole(role.audience, options);
|
|
517
|
+
await this.screenClient.setClientRole(role.audience, options);
|
|
518
|
+
} else if (clientRole == ClientRole.Broadcaster) {
|
|
519
|
+
await this.client.setClientRole(role.host);
|
|
520
|
+
await this.screenClient.setClientRole(role.host);
|
|
521
|
+
}
|
|
522
|
+
} catch (e) {
|
|
523
|
+
throw e;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
524
527
|
async changeCamera(cameraId, callback, error): Promise<void> {
|
|
525
528
|
try {
|
|
526
529
|
await this.localStream.video?.setDevice(cameraId);
|
|
@@ -9,8 +9,62 @@
|
|
|
9
9
|
information visit https://appbuilder.agora.io.
|
|
10
10
|
*********************************************
|
|
11
11
|
*/
|
|
12
|
-
export enum VideoRenderMode{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
12
|
+
export enum VideoRenderMode {
|
|
13
|
+
Hidden = 1,
|
|
14
|
+
Fit,
|
|
15
|
+
Adaptive,
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* The latency level of an audience member in a live interactive streaming. Takes effect only when the user role is `"audience"`.
|
|
20
|
+
* - `1`: Low latency.
|
|
21
|
+
* - `2`: (Default) Ultra low latency.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export const enum AudienceLatencyLevelType {
|
|
25
|
+
/**
|
|
26
|
+
* Low latency.
|
|
27
|
+
*/
|
|
28
|
+
AUDIENCE_LEVEL_LOW_LATENCY = 1,
|
|
29
|
+
/**
|
|
30
|
+
* Ultra-low latency.
|
|
31
|
+
*/
|
|
32
|
+
AUDIENCE_LEVEL_ULTRA_LOW_LATENCY = 2,
|
|
33
|
+
/**
|
|
34
|
+
* @ignore
|
|
35
|
+
*/
|
|
36
|
+
AUDIENCE_LEVEL_SYNC_LATENCY = 3,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ClientRoleOptions {
|
|
40
|
+
/**
|
|
41
|
+
* The latency level of an audience member in a live interactive streaming.
|
|
42
|
+
*
|
|
43
|
+
* > Note:
|
|
44
|
+
* > - Takes effect only when the user role is `"audience"`.
|
|
45
|
+
* > - Levels affect prices.
|
|
46
|
+
*/
|
|
47
|
+
level: AudienceLatencyLevelType;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* User role for live streaming mode */
|
|
51
|
+
export enum role {
|
|
52
|
+
/* 1: A host can both send and receive streams. */
|
|
53
|
+
host = 'host',
|
|
54
|
+
/* 2: The default role. An audience can only receive streams.*/
|
|
55
|
+
audience = 'audience',
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* Mode for RTC (Live or Broadcast)*/
|
|
59
|
+
export enum mode {
|
|
60
|
+
/**
|
|
61
|
+
* 0: (Default) The Communication profile.
|
|
62
|
+
* Use this profile in one-on-one calls or group calls, where all users can talk freely.
|
|
63
|
+
*/
|
|
64
|
+
live = 'live',
|
|
65
|
+
/**
|
|
66
|
+
* 1: The Live-Broadcast profile.
|
|
67
|
+
* Users in a live-broadcast channel have a role as either host or audience. A host can both send and receive streams; an audience can only receive streams.
|
|
68
|
+
*/
|
|
69
|
+
rtc = 'rtc',
|
|
70
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface AttributesMap {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface ChannelAttributeOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Indicates whether or not to notify all channel members of a channel attribute change
|
|
8
|
+
* This flag is valid only within the current method call:
|
|
9
|
+
* true: Notify all channel members of a channel attribute change.
|
|
10
|
+
* false: (Default) Do not notify all channel members of a channel attribute change.
|
|
11
|
+
*/
|
|
12
|
+
enableNotificationToChannelMembers?: undefined | false | true;
|
|
13
|
+
}
|
|
@@ -9,8 +9,17 @@
|
|
|
9
9
|
information visit https://appbuilder.agora.io.
|
|
10
10
|
*********************************************
|
|
11
11
|
*/
|
|
12
|
+
import {
|
|
13
|
+
ChannelAttributeOptions,
|
|
14
|
+
RtmAttribute,
|
|
15
|
+
RtmChannelAttribute,
|
|
16
|
+
Subscription,
|
|
17
|
+
} from 'agora-react-native-rtm';
|
|
18
|
+
import {RtmClientEvents} from 'agora-react-native-rtm/lib/typescript/src/RtmEngine';
|
|
12
19
|
import AgoraRTM, {VERSION} from 'agora-rtm-sdk';
|
|
13
20
|
|
|
21
|
+
type callbackType = (args?: any) => void;
|
|
22
|
+
|
|
14
23
|
export default class RtmEngine {
|
|
15
24
|
public appId: string;
|
|
16
25
|
public client: any;
|
|
@@ -21,6 +30,7 @@ export default class RtmEngine {
|
|
|
21
30
|
['channelMessageReceived', () => null],
|
|
22
31
|
['channelMemberJoined', () => null],
|
|
23
32
|
['channelMemberLeft', () => null],
|
|
33
|
+
['ChannelAttributesUpdated', () => null],
|
|
24
34
|
]);
|
|
25
35
|
public clientEventsMap = new Map<string, any>([
|
|
26
36
|
['connectionStateChanged', () => null],
|
|
@@ -50,7 +60,8 @@ export default class RtmEngine {
|
|
|
50
60
|
if (
|
|
51
61
|
event === 'channelMessageReceived' ||
|
|
52
62
|
event === 'channelMemberJoined' ||
|
|
53
|
-
event === 'channelMemberLeft'
|
|
63
|
+
event === 'channelMemberLeft' ||
|
|
64
|
+
event === 'ChannelAttributesUpdated'
|
|
54
65
|
) {
|
|
55
66
|
this.channelEventsMap.set(event, listener);
|
|
56
67
|
} else if (
|
|
@@ -181,6 +192,22 @@ export default class RtmEngine {
|
|
|
181
192
|
console.log('Member Left', this.channelEventsMap);
|
|
182
193
|
this.channelEventsMap.get('channelMemberLeft')({uid});
|
|
183
194
|
});
|
|
195
|
+
this.channelMap
|
|
196
|
+
.get(channelId)
|
|
197
|
+
.on('AttributesUpdated', (attributes: RtmChannelAttribute) => {
|
|
198
|
+
/**
|
|
199
|
+
* a) The following piece of code is commented for future reference.
|
|
200
|
+
* b) To be used in future implementations of channel attributes
|
|
201
|
+
* c) Kindly note the below event listener 'ChannelAttributesUpdated' expects type
|
|
202
|
+
* RtmChannelAttribute[] (array of objects [{key: 'valueOfKey', value: 'valueOfValue}])
|
|
203
|
+
* whereas the above listener 'AttributesUpdated' receives attributes in object form
|
|
204
|
+
* {[valueOfKey]: valueOfValue} of type RtmChannelAttribute
|
|
205
|
+
* d) Hence in this bridge the data should be modified to keep in sync with both the
|
|
206
|
+
* listeners for web and listener for native
|
|
207
|
+
*/
|
|
208
|
+
// this.channelEventsMap.get('ChannelAttributesUpdated')(attributes); //RN expect evt: any
|
|
209
|
+
});
|
|
210
|
+
|
|
184
211
|
return this.channelMap.get(channelId).join();
|
|
185
212
|
}
|
|
186
213
|
|
|
@@ -290,6 +317,40 @@ export default class RtmEngine {
|
|
|
290
317
|
return this.client.setLocalUserAttributes({...formattedAttributes});
|
|
291
318
|
}
|
|
292
319
|
|
|
320
|
+
async addOrUpdateLocalUserAttributes(attributes: RtmAttribute[]) {
|
|
321
|
+
let formattedAttributes: any = {};
|
|
322
|
+
attributes.map((attribute) => {
|
|
323
|
+
let key = Object.values(attribute)[0];
|
|
324
|
+
let value = Object.values(attribute)[1];
|
|
325
|
+
formattedAttributes[key] = value;
|
|
326
|
+
});
|
|
327
|
+
return this.client.addOrUpdateLocalUserAttributes({...formattedAttributes});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
addOrUpdateChannelAttributes(
|
|
331
|
+
channelId: string,
|
|
332
|
+
attributes: RtmChannelAttribute[],
|
|
333
|
+
option: ChannelAttributeOptions,
|
|
334
|
+
): Promise<void> {
|
|
335
|
+
/**
|
|
336
|
+
* The following piece of code is commented and not deleted
|
|
337
|
+
* to be used in future implementations of channel attributes
|
|
338
|
+
*/
|
|
339
|
+
|
|
340
|
+
// let formattedAttributes: any = {};
|
|
341
|
+
// attributes.map((attribute) => {
|
|
342
|
+
// let key = Object.values(attribute)[0];
|
|
343
|
+
// let value = Object.values(attribute)[1];
|
|
344
|
+
// formattedAttributes[key] = value;
|
|
345
|
+
// });
|
|
346
|
+
// return this.client.addOrUpdateChannelAttributes(
|
|
347
|
+
// channelId,
|
|
348
|
+
// {...formattedAttributes},
|
|
349
|
+
// option,
|
|
350
|
+
// );
|
|
351
|
+
return Promise.resolve(); // remove this line when functionality is added to the above function
|
|
352
|
+
}
|
|
353
|
+
|
|
293
354
|
async sendLocalInvitation(invitationProps: any) {
|
|
294
355
|
let invite = this.client.createLocalInvitation(invitationProps.uid);
|
|
295
356
|
this.localInvititations.set(invitationProps.uid, invite);
|
|
@@ -392,4 +453,20 @@ export default class RtmEngine {
|
|
|
392
453
|
getSdkVersion(callback: (version: string) => void) {
|
|
393
454
|
callback(VERSION);
|
|
394
455
|
}
|
|
456
|
+
|
|
457
|
+
addListener<EventType extends keyof RtmClientEvents>(
|
|
458
|
+
event: EventType,
|
|
459
|
+
listener: RtmClientEvents[EventType],
|
|
460
|
+
): Subscription {
|
|
461
|
+
if (event === 'ChannelAttributesUpdated') {
|
|
462
|
+
this.channelEventsMap.set(event, listener as callbackType);
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
remove: () => {
|
|
466
|
+
console.log(
|
|
467
|
+
'Use destroy method to remove all the event listeners from the RtcEngine instead.',
|
|
468
|
+
);
|
|
469
|
+
},
|
|
470
|
+
};
|
|
471
|
+
}
|
|
395
472
|
}
|