agora-appbuilder-core 4.0.0-spl.24 → 4.0.0-spl.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agora-appbuilder-core",
3
- "version": "4.0.0-spl.24",
3
+ "version": "4.0.0-spl.25",
4
4
  "description": "React Native template for RTE app builder",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -17,6 +17,7 @@
17
17
  "@sentry/react-native": "2.4.3",
18
18
  "@sentry/tracing": "6.2.1",
19
19
  "@supersami/rn-foreground-service": "^1.1.1",
20
+ "@types/lodash": "^4.17.6",
20
21
  "agora-react-native-rtm": "1.5.1",
21
22
  "agora-rtc-sdk-ng": "4.16.1",
22
23
  "agora-rtm-sdk": "1.5.1",
@@ -26,6 +27,7 @@
26
27
  "exponential-backoff": "3.1.0",
27
28
  "fetch-retry": "^5.0.6",
28
29
  "graphql": "15.5.0",
30
+ "lodash": "^4.17.21",
29
31
  "nanoevents": "7.0.1",
30
32
  "nanoid": "4.0.0",
31
33
  "nosleep.js": "0.12.0",
@@ -6110,6 +6112,11 @@
6110
6112
  "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
6111
6113
  "dev": true
6112
6114
  },
6115
+ "node_modules/@types/lodash": {
6116
+ "version": "4.17.6",
6117
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.6.tgz",
6118
+ "integrity": "sha512-OpXEVoCKSS3lQqjx9GGGOapBeuW5eUboYHRlHP9urXPX25IKZ6AnP5ZRxtVf63iieUbsHxLn8NQ5Nlftc6yzAA=="
6119
+ },
6113
6120
  "node_modules/@types/mime": {
6114
6121
  "version": "3.0.1",
6115
6122
  "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
@@ -34130,6 +34137,11 @@
34130
34137
  "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
34131
34138
  "dev": true
34132
34139
  },
34140
+ "@types/lodash": {
34141
+ "version": "4.17.6",
34142
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.6.tgz",
34143
+ "integrity": "sha512-OpXEVoCKSS3lQqjx9GGGOapBeuW5eUboYHRlHP9urXPX25IKZ6AnP5ZRxtVf63iieUbsHxLn8NQ5Nlftc6yzAA=="
34144
+ },
34133
34145
  "@types/mime": {
34134
34146
  "version": "3.0.1",
34135
34147
  "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
@@ -17,6 +17,7 @@
17
17
  "@sentry/react-native": "2.4.3",
18
18
  "@sentry/tracing": "6.2.1",
19
19
  "@supersami/rn-foreground-service": "^1.1.1",
20
+ "@types/lodash": "^4.17.6",
20
21
  "agora-react-native-rtm": "1.5.1",
21
22
  "agora-rtc-sdk-ng": "4.16.1",
22
23
  "agora-rtm-sdk": "1.5.1",
@@ -26,6 +27,7 @@
26
27
  "exponential-backoff": "3.1.0",
27
28
  "fetch-retry": "^5.0.6",
28
29
  "graphql": "15.5.0",
30
+ "lodash": "^4.17.21",
29
31
  "nanoevents": "7.0.1",
30
32
  "nanoid": "4.0.0",
31
33
  "nosleep.js": "0.12.0",
@@ -6110,6 +6112,11 @@
6110
6112
  "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
6111
6113
  "dev": true
6112
6114
  },
6115
+ "node_modules/@types/lodash": {
6116
+ "version": "4.17.6",
6117
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.6.tgz",
6118
+ "integrity": "sha512-OpXEVoCKSS3lQqjx9GGGOapBeuW5eUboYHRlHP9urXPX25IKZ6AnP5ZRxtVf63iieUbsHxLn8NQ5Nlftc6yzAA=="
6119
+ },
6113
6120
  "node_modules/@types/mime": {
6114
6121
  "version": "3.0.1",
6115
6122
  "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
@@ -34130,6 +34137,11 @@
34130
34137
  "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
34131
34138
  "dev": true
34132
34139
  },
34140
+ "@types/lodash": {
34141
+ "version": "4.17.6",
34142
+ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.6.tgz",
34143
+ "integrity": "sha512-OpXEVoCKSS3lQqjx9GGGOapBeuW5eUboYHRlHP9urXPX25IKZ6AnP5ZRxtVf63iieUbsHxLn8NQ5Nlftc6yzAA=="
34144
+ },
34133
34145
  "@types/mime": {
34134
34146
  "version": "3.0.1",
34135
34147
  "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
@@ -57,6 +57,7 @@
57
57
  "@sentry/react-native": "2.4.3",
58
58
  "@sentry/tracing": "6.2.1",
59
59
  "@supersami/rn-foreground-service": "^1.1.1",
60
+ "@types/lodash": "^4.17.6",
60
61
  "agora-react-native-rtm": "1.5.1",
61
62
  "agora-rtc-sdk-ng": "4.16.1",
62
63
  "agora-rtm-sdk": "1.5.1",
@@ -66,6 +67,7 @@
66
67
  "exponential-backoff": "3.1.0",
67
68
  "fetch-retry": "^5.0.6",
68
69
  "graphql": "15.5.0",
70
+ "lodash": "^4.17.21",
69
71
  "nanoevents": "7.0.1",
70
72
  "nanoid": "4.0.0",
71
73
  "nosleep.js": "0.12.0",
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, {useEffect} from 'react';
2
2
  import {
3
3
  CustomizationApiInterface,
4
4
  customize,
@@ -39,6 +39,7 @@ export interface AppBuilderSdkApiInterface {
39
39
  createCustomization: (
40
40
  customization: CustomizationApiInterface,
41
41
  ) => CustomizationApiInterface;
42
+ clearState: (stateKey: 'join' | 'all') => Promise<void>;
42
43
  customEvents: typeof customEvents;
43
44
  on: <T extends keyof userEventsMapInterface>(
44
45
  userEventName: T,
@@ -81,6 +82,15 @@ export const AppBuilderSdkApi: AppBuilderSdkApiInterface = {
81
82
  muteVideo: async (state) => {
82
83
  return await SDKMethodEventsManager.emit('muteVideo', state);
83
84
  },
85
+ clearState: async (stateKey) => {
86
+ switch (stateKey) {
87
+ case 'all':
88
+ case 'join':
89
+ return await SDKMethodEventsManager.emit('clearState', stateKey);
90
+ default:
91
+ throw new Error('Invalid identifier');
92
+ }
93
+ },
84
94
  createCustomization: customize,
85
95
  on: (userEventName, cb) => {
86
96
  console.log('SDKEvents: Event Registered', userEventName);
@@ -8,6 +8,7 @@ import {
8
8
  } from './meeting-info/useMeetingInfo';
9
9
  import {CustomizationApiInterface} from 'customization-api';
10
10
  import {Unsubscribe} from 'nanoevents';
11
+ import {cloneDeep} from 'lodash';
11
12
 
12
13
  type extractPromises<T extends (...p: any) => any> = {
13
14
  res: Parameters<T>[0];
@@ -57,8 +58,8 @@ type SdkApiContextInterface = {
57
58
  onMuteAudio: (callback: _InternalSDKMethodEventsMap['muteAudio']) => void;
58
59
  onMuteVideo: (callback: _InternalSDKMethodEventsMap['muteVideo']) => void;
59
60
  clearState: (
60
- key: keyof _InternalSDKMethodEventsMap | 'enterRoom',
61
- param?: any,
61
+ key: keyof _InternalSDKMethodEventsMap | 'enterRoom' | 'all',
62
+ hard?: boolean,
62
63
  ) => void;
63
64
  };
64
65
 
@@ -80,7 +81,7 @@ const defaultMuteAllParticipantsListener = ((res, _, param) => {
80
81
  res();
81
82
  }) as _InternalSDKMethodEventsMap['muteAllParticipants'];
82
83
 
83
- const SdkApiInitState: SdkApiContextInterface = {
84
+ const SdkApiDefaultState: SdkApiContextInterface = {
84
85
  enterRoom: {
85
86
  set: () => {},
86
87
  },
@@ -100,6 +101,19 @@ const SdkApiInitState: SdkApiContextInterface = {
100
101
  onMuteAudio: (_) => {},
101
102
  clearState: () => {},
102
103
  };
104
+ const SdkApiInitState: SdkApiContextInterface = cloneDeep(SdkApiDefaultState);
105
+
106
+ export const clearStateGlobal = (
107
+ state: keyof SdkApiContextInterface | 'all',
108
+ ) => {
109
+ if (state === 'all') {
110
+ for (const key in SdkApiInitState)
111
+ SdkApiInitState[key] = cloneDeep(SdkApiDefaultState[key]);
112
+ } else {
113
+ //@ts-expect-error
114
+ SdkApiInitState[state] = cloneDeep(SdkApiDefaultState[state]);
115
+ }
116
+ };
103
117
 
104
118
  export const READ_ONLY_SdkApiInitState = SdkApiInitState;
105
119
 
@@ -111,9 +125,10 @@ export const SdkApiContext =
111
125
  let moduleEventsUnsub: any[] = [];
112
126
 
113
127
  type commonEventHandlers = {
114
- [K in keyof Omit<_InternalSDKMethodEventsMap, 'muteVideo' | 'muteAudio'>]?: (
115
- setter: (p: SdkApiContextInterface[K]) => void,
116
- ) => Unsubscribe;
128
+ [K in keyof Omit<
129
+ _InternalSDKMethodEventsMap,
130
+ 'muteVideo' | 'muteAudio' | 'flushQueue'
131
+ >]?: (setter: (p: SdkApiContextInterface[K]) => void) => Unsubscribe;
117
132
  };
118
133
 
119
134
  const commonEventHandlers: commonEventHandlers = {
@@ -209,6 +224,10 @@ const registerListener = () => {
209
224
  ),
210
225
  SDKMethodEventsManager.on('muteVideo', defaultMuteListener),
211
226
  SDKMethodEventsManager.on('muteAudio', defaultMuteListener),
227
+ SDKMethodEventsManager.on('clearState', (res, _, queue) => {
228
+ clearStateGlobal(queue);
229
+ res();
230
+ }),
212
231
  ];
213
232
  };
214
233
 
@@ -261,26 +280,31 @@ const SdkApiContextProvider: React.FC = (props) => {
261
280
  muteAudioListener.current = value;
262
281
  };
263
282
 
264
- const clearState: SdkApiContextInterface['clearState'] = (key) => {
283
+ const clearState: SdkApiContextInterface['clearState'] = (key, hard) => {
284
+ let fallthrough = false;
265
285
  switch (key) {
286
+ case 'all':
287
+ fallthrough = true;
266
288
  case 'join':
267
- setJoinState(SdkApiInitState.join);
268
- break;
289
+ setJoinState(hard ? SdkApiDefaultState.join : SdkApiInitState.join);
290
+ if (!fallthrough) break;
269
291
  case 'enterRoom':
270
292
  setEnterRoom(null);
271
- break;
293
+ if (!fallthrough) break;
272
294
  case 'customize':
273
- setUserCustomization(SdkApiInitState.customize);
274
- break;
295
+ setUserCustomization(
296
+ hard ? SdkApiDefaultState.customize : SdkApiInitState.customize,
297
+ );
298
+ if (!fallthrough) break;
275
299
  case 'microphoneDevice':
276
300
  setMicrophoneDeviceState({});
277
- break;
301
+ if (!fallthrough) break;
278
302
  case 'speakerDevice':
279
303
  setSpeakerDeviceState({});
280
- break;
304
+ if (!fallthrough) break;
281
305
  case 'cameraDevice':
282
306
  setCameraDeviceState({});
283
- break;
307
+ if (!fallthrough) break;
284
308
  case 'muteAllParticipants':
285
309
  setMuteAllParticipantsState((current) => {
286
310
  return {
@@ -288,12 +312,13 @@ const SdkApiContextProvider: React.FC = (props) => {
288
312
  promise: undefined,
289
313
  };
290
314
  });
315
+ if (!fallthrough) break;
291
316
  case 'muteVideo':
292
317
  setMuteVideoListener(defaultMuteListener);
293
- break;
318
+ if (!fallthrough) break;
294
319
  case 'muteAudio':
295
320
  setMuteVideoListener(defaultMuteListener);
296
- break;
321
+ if (!fallthrough) break;
297
322
  }
298
323
  };
299
324
 
@@ -353,6 +378,11 @@ const SdkApiContextProvider: React.FC = (props) => {
353
378
  SDKMethodEventsManager.on('muteAudio', (...args) => {
354
379
  muteAudioListener.current(...args);
355
380
  }),
381
+ SDKMethodEventsManager.on('clearState', (res, _, queue) => {
382
+ clearStateGlobal(queue);
383
+ clearState(queue, true);
384
+ res();
385
+ }),
356
386
  ];
357
387
 
358
388
  return () => {
@@ -14,9 +14,12 @@ export interface SdkMethodEvents {
14
14
  microphoneDevice: (deviceId: deviceId) => void;
15
15
  speakerDevice: (deviceId: deviceId) => void;
16
16
  cameraDevice: (deviceId: deviceId) => void;
17
- muteAllParticipants: (mute: boolean | ((currentMute: boolean) => boolean)) => void;
17
+ muteAllParticipants: (
18
+ mute: boolean | ((currentMute: boolean) => boolean),
19
+ ) => void;
18
20
  muteAudio: (mute: boolean | ((currentMute: boolean) => boolean)) => void;
19
21
  muteVideo: (mute: boolean | ((currentMute: boolean) => boolean)) => void;
22
+ clearState: (state: 'join' | 'all') => void;
20
23
  }
21
24
 
22
25
  type EventParameterHelper<T extends keyof SdkMethodEvents> = Parameters<
@@ -61,8 +64,22 @@ class SDKMethodEvents {
61
64
  event: T,
62
65
  ...params: EventParameterHelper<T>
63
66
  ) {
64
- if (this.emitCache[event]) {
65
- throw new Error(`Event: ${event} already in callstack`);
67
+ if (event === 'clearState') {
68
+ const param = params[0];
69
+ switch (param) {
70
+ case 'join':
71
+ case 'clearState':
72
+ delete this.emitCache[param];
73
+ delete this.emitCacheDisabled[param];
74
+ break;
75
+ case 'all':
76
+ this.reset();
77
+ default:
78
+ }
79
+ } else {
80
+ if (this.emitCache[event]) {
81
+ throw new Error(`Event: ${event} already in callstack`);
82
+ }
66
83
  }
67
84
 
68
85
  const result = await new Promise<EventReturnTypeHelper<T>>((res, rej) => {
@@ -92,6 +109,11 @@ class SDKMethodEvents {
92
109
  this.emitCacheDisabled[event] = true;
93
110
  return unsub;
94
111
  }
112
+
113
+ reset() {
114
+ this.emitCache = {};
115
+ this.emitCacheDisabled = {};
116
+ }
95
117
  }
96
118
 
97
119
  const SDKMethodEventsManager = new SDKMethodEvents();