agora-appbuilder-core 3.0.0 → 3.0.1

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.
Files changed (28) hide show
  1. package/package.json +1 -1
  2. package/template/customization-api/app-state.ts +6 -1
  3. package/template/customization-api/utils.ts +1 -1
  4. package/template/src/app-state/useLocalUserInfo.ts +3 -0
  5. package/template/src/app-state/useMessages.ts +3 -0
  6. package/template/src/components/chat-ui/useChatUIControl.tsx +3 -0
  7. package/template/src/components/meeting-info/useMeetingInfo.tsx +3 -0
  8. package/template/src/rtm-events-api/Events.ts +41 -30
  9. package/template/src/subComponents/SelectDevice.tsx +3 -2
  10. package/template/src/subComponents/recording/useRecording.tsx +3 -1
  11. package/template/src/subComponents/screenshare/ScreenshareConfigure.tsx +1 -1
  12. package/template/src/utils/common.tsx +18 -2
  13. package/template/src/utils/isMobileOrTablet.native.ts +4 -0
  14. package/template/src/utils/isMobileOrTablet.ts +4 -0
  15. package/template/src/utils/useCreateMeeting.ts +3 -0
  16. package/template/src/utils/useIsAttendee.ts +12 -18
  17. package/template/src/utils/useIsAudioEnabled.ts +4 -0
  18. package/template/src/utils/useIsHost.ts +4 -0
  19. package/template/src/utils/useIsPSTN.ts +2 -1
  20. package/template/src/utils/useIsScreenShare.ts +1 -1
  21. package/template/src/utils/useIsVideoEnabled.ts +4 -0
  22. package/template/src/utils/useJoinMeeting.ts +3 -1
  23. package/template/src/utils/useLayout.tsx +3 -1
  24. package/template/src/utils/useMuteToggleLocal.ts +3 -0
  25. package/template/src/utils/useRemoteEndCall.ts +3 -0
  26. package/template/src/utils/useRemoteMute.ts +3 -0
  27. package/template/src/utils/useSidePanel.tsx +3 -0
  28. package/template/src/utils/useUserName.ts +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agora-appbuilder-core",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "React Native template for RTE app builder",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -7,8 +7,13 @@ import {RtcContext, RenderContext} from '../agora-rn-uikit';
7
7
  // commented for v1 release
8
8
  //import {default as DeviceContext} from '../src/components/DeviceContext';
9
9
  //import {default as StorageContext} from '../src/components/StorageContext';
10
-
10
+ /**
11
+ * The RTC app state exposes the internal RtcEngine object as well as dispatch interface to perform various actions.
12
+ */
11
13
  export const useRtc = createHook(RtcContext);
14
+ /**
15
+ * The Render app state governs the information necessary to render each user content view displayed in the videocall screen.
16
+ */
12
17
  export const useRender = createHook(RenderContext);
13
18
  export {useLocalUserInfo} from '../src/app-state/useLocalUserInfo';
14
19
 
@@ -25,6 +25,6 @@ export {default as useIsVideoEnabled} from '../src/utils/useIsVideoEnabled';
25
25
  export {useHistory, useParams} from '../src/components/Router';
26
26
 
27
27
  //export common function
28
- export {isWeb, isIOS, isAndroid, isDestop} from '../src/utils/common';
28
+ export {isWeb, isIOS, isAndroid, isDesktop} from '../src/utils/common';
29
29
  export {default as isMobileOrTablet} from '../src/utils/isMobileOrTablet';
30
30
  export {useLocalUid} from '../agora-rn-uikit';
@@ -1,6 +1,9 @@
1
1
  import {useLocalUid} from '../../agora-rn-uikit';
2
2
  import {useRender} from 'customization-api';
3
3
 
4
+ /**
5
+ * The LocalUserInfo app state contains the local user information like uid, audio and video mute states etc.
6
+ */
4
7
  export const useLocalUserInfo = () => {
5
8
  const localUid = useLocalUid();
6
9
  const {renderList} = useRender();
@@ -23,6 +23,9 @@ export interface messageInterface {
23
23
  >;
24
24
  }
25
25
 
26
+ /**
27
+ * The Messages app state governs the chat messages.
28
+ */
26
29
  export const useMessages: () => messageInterface = () => {
27
30
  const {
28
31
  deleteChatMessage: deleteMessage,
@@ -61,6 +61,9 @@ const ChatUIControlProvider = (props: ChatUIControlProviderProps) => {
61
61
  );
62
62
  };
63
63
 
64
+ /**
65
+ * The ChatUIControl app state governs the chat ui.
66
+ */
64
67
  const useChatUIControl = createHook(ChatUIControlContext);
65
68
 
66
69
  export {ChatUIControlProvider, useChatUIControl};
@@ -62,6 +62,9 @@ const MeetingInfoProvider = (props: MeetingInfoProviderProps) => {
62
62
  </MeetingInfoContext.Provider>
63
63
  );
64
64
  };
65
+ /**
66
+ * The MeetingInfo app state contains information about the active meeting.
67
+ */
65
68
  const useMeetingInfo = createHook(MeetingInfoContext);
66
69
 
67
70
  export {MeetingInfoProvider, useMeetingInfo};
@@ -34,8 +34,8 @@ class Events {
34
34
  /**
35
35
  * Persists the data in the local attributes of the user
36
36
  *
37
- * @param {string} evt to be stored in rtm Attribute key
38
- * @param {string} payload to be stored in rtm Attribute value
37
+ * @param {String} evt to be stored in rtm Attribute key
38
+ * @param {String} payload to be stored in rtm Attribute value
39
39
  * @api private
40
40
  */
41
41
  private _persist = async (evt: string, payload: string) => {
@@ -53,7 +53,10 @@ class Events {
53
53
  };
54
54
 
55
55
  /**
56
+ * event type validator.
56
57
  *
58
+ * @api private
59
+ * @returns {boolean}
57
60
  */
58
61
  private _validateEvt = (evt: string): boolean => {
59
62
  if (typeof evt !== 'string') {
@@ -67,6 +70,12 @@ class Events {
67
70
  return true;
68
71
  };
69
72
 
73
+ /**
74
+ * event listener validator
75
+ *
76
+ * @api private
77
+ * @returns {boolean}
78
+ */
70
79
  private _validateListener = (listener: EventCallback): boolean => {
71
80
  if (typeof listener !== 'function') {
72
81
  throw Error(
@@ -77,13 +86,13 @@ class Events {
77
86
  };
78
87
 
79
88
  /**
80
- * Sets the local attribute of user if persist level is 2 or 3.
81
- * If param 'to' is not provided, message is sent in the channel.
82
- * If param 'to' is provided message is sent to that individual.
83
- * If param 'to' is an array of uids is provided then message is sent to all the individual uids in loop.
89
+ * Sets the local attribute of user if persist level is 2 or 3.
90
+ * If param 'toUid' is not provided, message is sent in the channel.
91
+ * If param 'toUid' is provided message is sent to that individual.
92
+ * If param 'toUid' is an array of uids is provided then message is sent to all the individual uids in loop.
84
93
  *
85
- * @param {any} rtmPayload payload to be sent across
86
- * @param {toUid} to uid or uids[] of user
94
+ * @param {Object} rtmPayload payload to be sent across
95
+ * @param {ReceiverUid} toUid uid or uids[] of user
87
96
  * @api private
88
97
  */
89
98
  private _send = async (rtmPayload: any, toUid?: ReceiverUid) => {
@@ -142,16 +151,16 @@ class Events {
142
151
  };
143
152
 
144
153
  /**
145
- * Listens for a specified event.
146
- * Adds a listener function to the specified event.
154
+ * Listen on a new event by eventName and listener.
147
155
  * When the specified event happens, the Events API triggers the callback that you pass.
148
- * The listener will not be added if it is a duplicate.
156
+ * The listener will not be added/listened if it is a duplicate.
149
157
  *
150
- * @param {String} eventName Name of the event to attach the listener to.
158
+ * @param {String} eventName Name of the event. It must be a unique string.
151
159
  * @param {Function} listener Method to be called when the event is emitted.
160
+ * @returns {Function} Returns function, call it and this listener will be removed from event
152
161
  * @api public
153
162
  */
154
- on = (eventName: string, listener: EventCallback) => {
163
+ on = (eventName: string, listener: EventCallback): Function => {
155
164
  try {
156
165
  if (!this._validateEvt(eventName) || !this._validateListener(listener))
157
166
  return;
@@ -160,54 +169,57 @@ class Events {
160
169
  EventUtils.removeListener(eventName, listener, this.source);
161
170
  };
162
171
  } catch (error) {
163
- console.log('custom-events-on error: ', error);
172
+ console.log('CUSTOM_EVENT_API on error: ', error);
164
173
  }
165
174
  };
166
175
 
167
176
  /**
168
- * Removes a listener function from the specified event if eventName and listener function both are provided.
169
- * Removes all listeners from a specified event if listener function is not provided.
170
- * If you do not specify an event then all listeners will be removed.
171
- * That means every event will be emptied.
177
+ * Listen off an event by eventName and listener
178
+ * or listen off events by eventName, when if only eventName argument is passed.
179
+ * or listen off all events, when if no arguments are passed.
172
180
  *
173
181
  * @param {String} eventName Name of the event to remove the listener from.
174
- * @param {Function} listener Method to remove from the event.
182
+ * @param {Function} listener Listener to remove from the event.
175
183
  * @api public
176
184
  */
177
185
  off = (eventName?: string, listener?: EventCallback) => {
178
186
  try {
179
187
  if (listener) {
180
188
  if (this._validateListener(listener) && this._validateEvt(eventName)) {
189
+ // listen off an event by eventName and listener
181
190
  EventUtils.removeListener(eventName, listener, this.source);
182
191
  }
183
192
  } else if (eventName) {
193
+ // listen off events by name, when if only name is passed.
184
194
  if (this._validateEvt(eventName)) {
185
195
  EventUtils.removeAllListeners(eventName, this.source);
186
196
  }
187
197
  } else {
198
+ // listen off all events, that means every event will be emptied.
188
199
  EventUtils.removeAll(this.source);
189
200
  }
190
201
  } catch (error) {
191
- console.log('custom-events-off error: ', error);
202
+ console.log('CUSTOM_EVENT_API off error: ', error);
192
203
  }
193
204
  };
194
205
 
195
206
  /**
196
- * This method sends p2p or channel message depending upon the 'to' value.
197
- * - If 'to' is provided this method sends p2p message.
198
- * - If 'to' is empty this method sends channel message.
207
+ * This method sends p2p or channel message depending upon the 'receiver' value.
208
+ * - If 'receiver' is provided this method sends p2p message.
209
+ * - If 'receiver' is empty this method sends channel message.
199
210
  *
200
211
  *
201
- * @param {String} eventName Name of the event to register on which listeners are added
202
- * @param {String} payload . NOTICE: value bytelength has MAX_SIZE 32kb limit.
203
- * @param {ReceiverUid} receiver uid or uid array. The default mode is to send a message in channel.
212
+ * @param {String} eventName Name of the event to send.
213
+ * @param {String} payload (optional) Additional data to be sent along with the event.
214
+ * @param {Enum} persistLevel (optional) set different levels of persistance. Default value is Level 1
215
+ * @param {ReceiverUid} receiver (optional) uid or uid array. Default mode sends message in channel.
204
216
  * @api public
205
217
  * */
206
218
  send = async (
207
219
  eventName: string = '',
208
220
  payload: string = '',
209
- persistLevel: EventPersistLevel,
210
- receiver?: ReceiverUid,
221
+ persistLevel: EventPersistLevel = EventPersistLevel.LEVEL1,
222
+ receiver: ReceiverUid = -1,
211
223
  ) => {
212
224
  if (!this._validateEvt(eventName)) return;
213
225
 
@@ -226,11 +238,10 @@ class Events {
226
238
  persistLevel === EventPersistLevel.LEVEL2 ||
227
239
  persistLevel === EventPersistLevel.LEVEL3
228
240
  ) {
229
- console.log('CUSTOM_EVENT_API: Event lifecycle: persist', persistLevel);
230
241
  try {
231
242
  await this._persist(eventName, persistValue);
232
243
  } catch (error) {
233
- console.log('custom-events-persist error: ', error);
244
+ console.log('CUSTOM_EVENT_API persist error: ', error);
234
245
  }
235
246
  }
236
247
  try {
@@ -111,8 +111,9 @@ const SelectDevice = () => {
111
111
  const [isPickerDisabled] = useSelectDevice();
112
112
  //commented for v1 release
113
113
  // const settingScreenInfoMessage = useString('settingScreenInfoMessage')();
114
- const settingScreenInfoMessage =
115
- 'Video and Audio sharing is disabled for attendees. Raise hand to request permission to share.';
114
+ const settingScreenInfoMessage = $config.AUDIO_ROOM
115
+ ? 'Audio sharing is disabled for attendees. Raise hand to request permission to share.'
116
+ : 'Video and Audio sharing is disabled for attendees. Raise hand to request permission to share.';
116
117
  return (
117
118
  <View>
118
119
  <View style={{marginTop: 15}}></View>
@@ -224,7 +224,9 @@ const RecordingProvider = (props: RecordingProviderProps) => {
224
224
  </RecordingContext.Provider>
225
225
  );
226
226
  };
227
-
227
+ /**
228
+ * The Recording app state governs the App Builder cloud recording functionality.
229
+ */
228
230
  const useRecording = createHook(RecordingContext);
229
231
 
230
232
  export {RecordingProvider, useRecording};
@@ -163,7 +163,7 @@ export const ScreenshareConfigure = (props: {children: React.ReactNode}) => {
163
163
  if (isRecordingActive) {
164
164
  executeRecordingQuery(isActive);
165
165
  }
166
- console.log('supriya screenshare query executed');
166
+ console.log('screenshare query executed');
167
167
  try {
168
168
  // @ts-ignore
169
169
  await rtc.RtcEngine.startScreenshare(
@@ -29,17 +29,33 @@ const shouldAuthenticate: boolean =
29
29
  //for our internal usage don't check Platform - electron and web will same kind ui checks. thats why we have isWeb for external usage
30
30
  const isWebInternal = () => ReactNativePlatform.OS === 'web';
31
31
 
32
+ /**
33
+ * Checks whether the application is running as a web app and returns true/false.
34
+ * @returns function
35
+ */
32
36
  const isWeb = () => Platform === 'web' && ReactNativePlatform.OS === 'web';
33
37
 
38
+ /**
39
+ * Checks whether the application is running as an android app and returns true/false.
40
+ * @returns function
41
+ */
34
42
  const isAndroid = () =>
35
43
  //@ts-ignore
36
44
  Platform === 'native' && ReactNativePlatform.OS === 'android';
37
45
 
46
+ /**
47
+ * Checks whether the application is running as an iOS app and returns true/false.
48
+ * @returns function
49
+ */
38
50
  //@ts-ignore
39
51
  const isIOS = () => Platform === 'native' && ReactNativePlatform.OS === 'ios';
40
52
 
53
+ /**
54
+ * Checks whether the application is running as an electron desktop app and returns true/false.
55
+ * @returns function
56
+ */
41
57
  //@ts-ignore
42
- const isDestop = () => Platform === 'electron';
58
+ const isDesktop = () => Platform === 'electron';
43
59
 
44
60
  const isArray = (data: any[]) =>
45
61
  data && Array.isArray(data) && data.length ? true : false ? true : false;
@@ -49,7 +65,7 @@ export {
49
65
  isIOS,
50
66
  isWebInternal,
51
67
  isWeb,
52
- isDestop,
68
+ isDesktop,
53
69
  shouldAuthenticate,
54
70
  isArray,
55
71
  isValidReactComponent,
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Checks whether the application is running as a web application on a mobile or tablet device and returns true/false.
3
+ * @returns function
4
+ */
1
5
  const isMobileOrTablet = () => {
2
6
  return true;
3
7
  };
@@ -4,6 +4,10 @@ declare global {
4
4
  }
5
5
  }
6
6
 
7
+ /**
8
+ * Checks whether the application is running as a web application on a mobile or tablet device and returns true/false.
9
+ * @returns function
10
+ */
7
11
  const isMobileOrTablet = () => {
8
12
  let check = false;
9
13
  (function (a) {
@@ -27,6 +27,9 @@ const CREATE_CHANNEL = gql`
27
27
  }
28
28
  }
29
29
  `;
30
+ /**
31
+ * Returns an asynchronous function to create a meeting with the given options.
32
+ */
30
33
  export default function useCreateMeeting() {
31
34
  const [createChannel, {error}] = useMutation(CREATE_CHANNEL);
32
35
  const {setMeetingInfo} = useSetMeetingInfo();
@@ -9,28 +9,22 @@
9
9
  information visit https://appbuilder.agora.io.
10
10
  *********************************************
11
11
  */
12
- import {useMeetingInfo} from '../components/meeting-info/useMeetingInfo';
13
12
  import {useLiveStreamDataContext} from '../components/contexts/LiveStreamDataContext';
14
13
  import {UidType} from '../../agora-rn-uikit';
14
+ import {useVideoMeetingData} from '../components/contexts/VideoMeetingDataContext';
15
15
 
16
+ /**
17
+ * Returns a function that checks whether the given uid is an attendee and returns true/false
18
+ * @returns function
19
+ */
16
20
  function useIsAttendee() {
17
- if ($config.EVENT_MODE) {
18
- const {audienceUids} = useLiveStreamDataContext();
19
- const isAttendee = (uid: UidType) => {
20
- return audienceUids.filter((audienceUid) => audienceUid === uid).length
21
- ? true
22
- : false;
23
- };
24
- return isAttendee;
25
- } else {
26
- const {
27
- data: {isHost},
28
- } = useMeetingInfo();
29
- const isAttendee = (uid: UidType) => {
30
- return !isHost ? true : false;
31
- };
32
- return isAttendee;
33
- }
21
+ const {audienceUids: lsAudienceUids} = useLiveStreamDataContext();
22
+ const {attendeeUids: vmAudienceUids} = useVideoMeetingData();
23
+ const isAttendee = (uid: UidType) => {
24
+ const attUidsData = $config.EVENT_MODE ? lsAudienceUids : vmAudienceUids;
25
+ return attUidsData.filter((attId) => attId === uid).length ? true : false;
26
+ };
27
+ return isAttendee;
34
28
  }
35
29
 
36
30
  export default useIsAttendee;
@@ -13,6 +13,10 @@ import {useRender} from 'customization-api';
13
13
  import {UidType} from '../../agora-rn-uikit';
14
14
  import {ToggleState} from '../../agora-rn-uikit/src/Contexts/PropsContext';
15
15
 
16
+ /**
17
+ * Returns a function that checks the audio state for a given uid and returns true/false
18
+ * @returns function
19
+ */
16
20
  function useIsAudioEnabled() {
17
21
  const {renderList} = useRender();
18
22
  /**
@@ -13,6 +13,10 @@ import {UidType} from '../../agora-rn-uikit';
13
13
  import {useLiveStreamDataContext} from '../components/contexts/LiveStreamDataContext';
14
14
  import {useVideoMeetingData} from '../components/contexts/VideoMeetingDataContext';
15
15
 
16
+ /**
17
+ * Returns a function that checks whether the given uid is a host and returns true/false
18
+ * @returns function
19
+ */
16
20
  function useIsHost() {
17
21
  const {hostUids: liveStreamHostUids} = useLiveStreamDataContext();
18
22
  const {hostUids: videoMeetingHostUids} = useVideoMeetingData();
@@ -11,8 +11,9 @@
11
11
  */
12
12
  import {useRender} from 'customization-api';
13
13
  import {UidType} from '../../agora-rn-uikit';
14
+
14
15
  /**
15
- * This hook will return the function to check whether the current user is a PSTN user or not
16
+ * Returns a function that checks whether the given uid is a PSTN user and returns true/false
16
17
  * @returns function
17
18
  */
18
19
  function useIsPSTN() {
@@ -13,7 +13,7 @@ import {UidType} from '../../agora-rn-uikit';
13
13
  import {useScreenContext} from '../components/contexts/ScreenShareContext';
14
14
 
15
15
  /**
16
- * This hook will return the function to check whether the screen is shared or not
16
+ * This hook will return the function which take UID and return true if screensharing active on the UID
17
17
  * @returns function
18
18
  */
19
19
  function useIsScreenShare() {
@@ -12,6 +12,10 @@
12
12
  import {useRender} from 'customization-api';
13
13
  import {UidType, ToggleState} from '../../agora-rn-uikit';
14
14
 
15
+ /**
16
+ * Returns a function that checks the video state for a given uid and returns true/false
17
+ * @returns function
18
+ */
15
19
  function useIsVideoEnabled() {
16
20
  const {renderList} = useRender();
17
21
 
@@ -50,7 +50,9 @@ const JOIN_CHANNEL_PHRASE = gql`
50
50
  }
51
51
  }
52
52
  `;
53
-
53
+ /**
54
+ * Returns an asynchronous function to join a meeting with the given phrase.
55
+ */
54
56
  export default function useJoinMeeting() {
55
57
  const {store} = useContext(StorageContext);
56
58
  const {setMeetingInfo} = useSetMeetingInfo();
@@ -34,7 +34,9 @@ const LayoutProvider = (props: LayoutProviderProps) => {
34
34
  </LayoutContext.Provider>
35
35
  );
36
36
  };
37
-
37
+ /**
38
+ * The Layout app state governs the video call screen content display layout.
39
+ */
38
40
  const useLayout = createHook(LayoutContext);
39
41
 
40
42
  export {LayoutProvider, useLayout};
@@ -16,6 +16,9 @@ export enum MUTE_LOCAL_TYPE {
16
16
  audio,
17
17
  video,
18
18
  }
19
+ /**
20
+ * Returns an asynchronous function to toggle muted state of the given track type for the local user.
21
+ */
19
22
  function useMuteToggleLocal() {
20
23
  const {RtcEngine, dispatch} = useRtc();
21
24
  const local = useLocalUserInfo();
@@ -4,6 +4,9 @@ import useIsPSTN from './useIsPSTN';
4
4
  import {UidType} from '../../agora-rn-uikit';
5
5
  import events, {EventPersistLevel} from '../rtm-events-api';
6
6
 
7
+ /**
8
+ * Returns a function to end the call for a remote user with the given uid.
9
+ */
7
10
  const useRemoteEndCall = () => {
8
11
  const {
9
12
  data: {isHost},
@@ -20,6 +20,9 @@ export enum MUTE_REMOTE_TYPE {
20
20
  audio,
21
21
  video,
22
22
  }
23
+ /**
24
+ * Returns an asynchronous function to toggle muted state of the given track type for a remote user with the given uid or if no uid provided, mutes everyone else in the meeting.
25
+ */
23
26
  function useRemoteMute() {
24
27
  const {
25
28
  data: {isHost},
@@ -36,6 +36,9 @@ const SidePanelProvider = (props: SidePanelProviderProps) => {
36
36
  );
37
37
  };
38
38
 
39
+ /**
40
+ * The Side panel app state governs the side panel.
41
+ */
39
42
  const useSidePanel = createHook(SidePanelContext);
40
43
 
41
44
  export {SidePanelProvider, useSidePanel};
@@ -1,6 +1,9 @@
1
1
  import useSetName from './useSetName';
2
2
  import useGetName from './useGetName';
3
3
 
4
+ /**
5
+ * The UserName app state governs the local user's display name.
6
+ */
4
7
  export default function useUserName(): [
5
8
  string,
6
9
  React.Dispatch<React.SetStateAction<string>>,