agora-appbuilder-core 4.0.13 → 4.0.15

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 (71) hide show
  1. package/package.json +1 -1
  2. package/template/_package-lock.json +1364 -1576
  3. package/template/android/app/src/main/assets/fonts/icomoon.ttf +0 -0
  4. package/template/customization-api/sub-components.ts +6 -4
  5. package/template/customization-api/types.ts +0 -6
  6. package/template/defaultConfig.js +0 -3
  7. package/template/global.d.ts +0 -3
  8. package/template/ios/Podfile.lock +0 -10
  9. package/template/package-lock.json +1364 -1576
  10. package/template/package.json +0 -4
  11. package/template/src/SDKAppWrapper.tsx +8 -2
  12. package/template/src/app-state/useMessages.ts +9 -49
  13. package/template/src/assets/font-styles.css +125 -289
  14. package/template/src/assets/fonts/icomoon.ttf +0 -0
  15. package/template/src/assets/selection.json +1 -1
  16. package/template/src/atoms/ActionMenu.tsx +2 -5
  17. package/template/src/atoms/CustomIcon.tsx +1 -17
  18. package/template/src/atoms/ImageIcon.tsx +3 -19
  19. package/template/src/atoms/Popup.tsx +4 -13
  20. package/template/src/atoms/ToolbarPreset.tsx +57 -6
  21. package/template/src/auth/AuthProvider.tsx +0 -5
  22. package/template/src/auth/config.ts +3 -12
  23. package/template/src/components/Chat.tsx +1 -7
  24. package/template/src/components/ChatContext.ts +0 -12
  25. package/template/src/components/CommonStyles.ts +2 -2
  26. package/template/src/components/Controls.tsx +57 -29
  27. package/template/src/components/Leftbar.tsx +4 -4
  28. package/template/src/components/Navbar.tsx +54 -29
  29. package/template/src/components/NavbarMobile.tsx +23 -33
  30. package/template/src/components/PinnedVideo.tsx +1 -1
  31. package/template/src/components/RTMConfigure.tsx +0 -1
  32. package/template/src/components/SdkApiContext.tsx +4 -1
  33. package/template/src/components/chat-messages/useChatMessages.tsx +607 -411
  34. package/template/src/components/chat-ui/useChatUIControls.tsx +0 -53
  35. package/template/src/components/meeting-info-invite/MeetingInfoGridTile.tsx +1 -4
  36. package/template/src/components/participants/Participant.tsx +1 -0
  37. package/template/src/components/precall/joinWaitingRoomBtn.native.tsx +1 -6
  38. package/template/src/components/precall/joinWaitingRoomBtn.tsx +1 -6
  39. package/template/src/components/room-info/useRoomInfo.tsx +5 -5
  40. package/template/src/language/default-labels/videoCallScreenLabels.ts +6 -86
  41. package/template/src/pages/VideoCall.tsx +4 -3
  42. package/template/src/pages/video-call/ActionSheetContent.tsx +32 -3
  43. package/template/src/pages/video-call/VideoCallScreenWrapper.tsx +12 -22
  44. package/template/src/pages/video-call/VideoComponent.tsx +11 -5
  45. package/template/src/pages/video-call/index.ts +0 -8
  46. package/template/src/subComponents/ChatBubble.tsx +32 -252
  47. package/template/src/subComponents/ChatContainer.tsx +4 -14
  48. package/template/src/subComponents/ChatInput.ios.tsx +184 -0
  49. package/template/src/subComponents/ChatInput.tsx +100 -276
  50. package/template/src/subComponents/RemoteMutePopup.tsx +131 -12
  51. package/template/src/subComponents/caption/CaptionContainer.tsx +2 -6
  52. package/template/src/subComponents/recording/useRecording.tsx +1 -3
  53. package/template/src/utils/SdkMethodEvents.ts +1 -0
  54. package/template/src/utils/common.tsx +17 -0
  55. package/template/src/utils/index.tsx +0 -30
  56. package/template/src/utils/useEndCall.ts +0 -7
  57. package/template/src/utils/useJoinRoom.ts +7 -33
  58. package/template/android/link-assets-manifest.json +0 -13
  59. package/template/ios/link-assets-manifest.json +0 -13
  60. package/template/src/atoms/InlinePopup.tsx +0 -185
  61. package/template/src/components/chat/chatConfigure.native.tsx +0 -488
  62. package/template/src/components/chat/chatConfigure.tsx +0 -473
  63. package/template/src/subComponents/ChatInput.native.tsx +0 -269
  64. package/template/src/subComponents/chat/ChatActionMenu.tsx +0 -224
  65. package/template/src/subComponents/chat/ChatAttachment.native.tsx +0 -234
  66. package/template/src/subComponents/chat/ChatAttachment.tsx +0 -145
  67. package/template/src/subComponents/chat/ChatEmoji.native.tsx +0 -75
  68. package/template/src/subComponents/chat/ChatEmoji.tsx +0 -181
  69. package/template/src/subComponents/chat/ChatSendButton.tsx +0 -141
  70. package/template/src/subComponents/chat/ChatUploadStatus.tsx +0 -65
  71. package/template/src/subComponents/chat/ImagePopup.tsx +0 -400
@@ -1,473 +0,0 @@
1
- import {createHook} from 'customization-implementation';
2
- import React, {createContext, useState, useEffect} from 'react';
3
- import AgoraChat from 'agora-chat';
4
- import {useRoomInfo} from '../room-info/useRoomInfo';
5
-
6
- import {UidType, useContent} from 'customization-api';
7
- import {
8
- ChatMessageType,
9
- ChatOption,
10
- SDKChatType,
11
- useChatMessages,
12
- } from '../chat-messages/useChatMessages';
13
- import {timeNow} from '../../rtm/utils';
14
- import StorageContext from '../StorageContext';
15
- import {
16
- File,
17
- UploadStatus,
18
- useChatUIControls,
19
- } from '../../components/chat-ui/useChatUIControls';
20
- import {logger, LogSource} from '../../logger/AppBuilderLogger';
21
-
22
- export interface FileObj {
23
- url: string;
24
- filename: string;
25
- filetype: string;
26
- data: File;
27
- }
28
-
29
- interface chatConfigureContextInterface {
30
- open: boolean;
31
- setOpen: React.Dispatch<React.SetStateAction<boolean>>;
32
- sendChatSDKMessage: (option: ChatOption, messageStatusCallback?: any) => void;
33
- deleteChatUser: () => void;
34
- downloadAttachment: (fileName: string, fileUrl: string) => void;
35
- uploadAttachment: (fileObj: object) => void;
36
- deleteAttachment: (
37
- msgId: string,
38
- recallFromUser?: string,
39
- chatType?: SDKChatType,
40
- ) => void;
41
- }
42
-
43
- export const chatConfigureContext =
44
- createContext<chatConfigureContextInterface>({
45
- open: false,
46
- setOpen: () => {},
47
- sendChatSDKMessage: () => {},
48
- deleteChatUser: () => {},
49
- downloadAttachment: () => {},
50
- uploadAttachment: () => {},
51
- deleteAttachment: () => {},
52
- });
53
-
54
- const ChatConfigure = ({children}) => {
55
- const [open, setOpen] = useState(false);
56
- const {data} = useRoomInfo();
57
- const connRef = React.useRef(null);
58
- const {defaultContent} = useContent();
59
- const {privateChatUser, setUploadStatus, setUploadedFiles, uploadedFiles} =
60
- useChatUIControls();
61
- const defaultContentRef = React.useRef(defaultContent);
62
- const {
63
- addMessageToPrivateStore,
64
- showMessageNotification,
65
- addMessageToStore,
66
- removeMessageFromPrivateStore,
67
- removeMessageFromStore,
68
- } = useChatMessages();
69
- const {store} = React.useContext(StorageContext);
70
-
71
- React.useEffect(() => {
72
- defaultContentRef.current = defaultContent;
73
- }, [defaultContent]);
74
-
75
- let newConn = null;
76
-
77
- useEffect(() => {
78
- const initializeChatSDK = async () => {
79
- try {
80
- const CHAT_APP_KEY = `${$config.CHAT_ORG_NAME}#${$config.CHAT_APP_NAME}`;
81
- // Initializes the Web client.
82
- newConn = new AgoraChat.connection({
83
- appKey: CHAT_APP_KEY,
84
- });
85
- // Logs into Agora Chat.
86
- const result = await newConn.open({
87
- user: data.uid.toString(),
88
- agoraToken: data.chat.user_token,
89
- });
90
- logger.debug(
91
- LogSource.Internals,
92
- 'CHAT',
93
- `Logged in User ${data.uid} to Agora Chat Server`,
94
- );
95
-
96
- // event listener for messages
97
- newConn.addEventHandler('connection&message', {
98
- // app is connected to chat server
99
- onConnected: () => {
100
- console.log('%cChatSDK: connected to chat server', 'color: blue');
101
- },
102
-
103
- onFileMessage: message => {
104
- const fileUrl =
105
- message.ext?.from_platform === 'native'
106
- ? message.url
107
- : message.ext.file_url;
108
- if (message.chatType === SDKChatType.GROUP_CHAT) {
109
- showMessageNotification(
110
- message.ext.file_name,
111
- message.from,
112
- false,
113
- message.type,
114
- );
115
-
116
- addMessageToStore(Number(message.from), {
117
- msg: '',
118
- createdTimestamp: message.time,
119
- msgId: message.id,
120
- isDeleted: false,
121
- type: ChatMessageType.FILE,
122
- url: fileUrl,
123
- ext: message.ext.file_ext,
124
- fileName: message.ext.file_name,
125
- });
126
- }
127
- if (message.chatType === SDKChatType.SINGLE_CHAT) {
128
- showMessageNotification(
129
- message.ext.file_name,
130
- message.from,
131
- true,
132
- message.type,
133
- );
134
- addMessageToPrivateStore(
135
- Number(message.from),
136
- {
137
- msg: '',
138
- createdTimestamp: message.time,
139
- msgId: message.id,
140
- isDeleted: false,
141
- type: ChatMessageType.FILE,
142
- url: fileUrl,
143
- ext: message.ext.file_ext,
144
- fileName: message.ext.file_name,
145
- },
146
- false,
147
- );
148
- }
149
- },
150
- onImageMessage: message => {
151
- const fileUrl =
152
- message.ext?.from_platform === 'native'
153
- ? message.url
154
- : message.ext.file_url;
155
-
156
- if (message.chatType === SDKChatType.GROUP_CHAT) {
157
- showMessageNotification(
158
- message.ext.file_name,
159
- message.from,
160
- false,
161
- message.type,
162
- );
163
- addMessageToStore(Number(message.from), {
164
- msg: '',
165
- createdTimestamp: message.time,
166
- msgId: message.id,
167
- isDeleted: false,
168
- type: ChatMessageType.IMAGE,
169
- thumb: fileUrl + '&thumbnail=true',
170
- url: fileUrl,
171
- fileName: message.ext?.file_name,
172
- });
173
- }
174
- if (message.chatType === SDKChatType.SINGLE_CHAT) {
175
- // show to notifcation- privat msg received
176
- showMessageNotification(
177
- message.ext.file_name,
178
- message.from,
179
- true,
180
- message.type,
181
- );
182
- // this is remote user messages
183
- addMessageToPrivateStore(
184
- Number(message.from),
185
- {
186
- msg: '',
187
- createdTimestamp: message.time,
188
- msgId: message.id,
189
- isDeleted: false,
190
- type: ChatMessageType.IMAGE,
191
- thumb: fileUrl + '&thumbnail=true',
192
- url: fileUrl,
193
- fileName: message.ext?.file_name,
194
- },
195
- false,
196
- );
197
- }
198
- },
199
- // text message is recieved
200
- onTextMessage: message => {
201
- console.log(
202
- '%cChatSDK: received msg: %s. from: %s',
203
- 'color: blue',
204
- JSON.stringify(message, null, 2),
205
- defaultContentRef.current[message.from]?.name,
206
- );
207
-
208
- if (message.chatType === SDKChatType.GROUP_CHAT) {
209
- // show to notifcation- group msg received
210
- showMessageNotification(
211
- message.msg,
212
- message.from,
213
- false,
214
- message.type,
215
- );
216
- addMessageToStore(Number(message.from), {
217
- msg: message.msg.replace(/^(\n)+|(\n)+$/g, ''),
218
- createdTimestamp: message.time,
219
- msgId: message.id,
220
- isDeleted: false,
221
- type: ChatMessageType.TXT,
222
- });
223
- }
224
-
225
- if (message.chatType === SDKChatType.SINGLE_CHAT) {
226
- // show to notifcation- privat msg received
227
- showMessageNotification(
228
- message.msg,
229
- message.from,
230
- true,
231
- message.type,
232
- );
233
- // this is remote user messages
234
- addMessageToPrivateStore(
235
- Number(message.from),
236
- {
237
- msg: message.msg.replace(/^(\n)+|(\n)+$/g, ''),
238
- createdTimestamp: message.time,
239
- msgId: message.id,
240
- isDeleted: false,
241
- type: ChatMessageType.TXT,
242
- },
243
- false,
244
- );
245
- }
246
- },
247
-
248
- onRecallMessage: message => {
249
- const isGroupChat = message.to === data.chat.group_id;
250
- if (isGroupChat) {
251
- removeMessageFromStore(message.mid, true);
252
- } else {
253
- removeMessageFromPrivateStore(message.mid, true);
254
- }
255
- },
256
- // on token expired
257
- onTokenExpired: () => {
258
- console.log('%cChatSDK: token has expired', 'color: blue');
259
- },
260
- onError: error => {
261
- console.log('%cChatSDK: error', 'color: blue', error);
262
- },
263
- });
264
- connRef.current = newConn;
265
- logger.debug(LogSource.Internals, 'CHAT', 'Initialized Chat SDK');
266
- } catch (error) {
267
- console.log(
268
- '%cChatSDK: initialization error: %s',
269
- 'color: red',
270
- JSON.stringify(error, null, 2),
271
- );
272
- logger.error(
273
- LogSource.Internals,
274
- 'CHAT',
275
- 'Initialization Error Chat SDK',
276
- error,
277
- );
278
- }
279
- };
280
-
281
- // initializing chat sdk
282
- initializeChatSDK();
283
- return () => {
284
- newConn.close();
285
- logger.debug(
286
- LogSource.Internals,
287
- 'CHAT',
288
- `Logging out User ${data.uid} from Agora Chat Server`,
289
- );
290
- };
291
- }, []);
292
-
293
- const sendChatSDKMessage = (
294
- option: ChatOption,
295
- messageStatusCallback?: any,
296
- ) => {
297
- if (connRef.current) {
298
- //TODO thumb and url of actual image uploaded available in file upload complete
299
- const localFileUrl = option?.ext?.file_url || '';
300
- //@ts-ignore
301
- const msg = AgoraChat.message.create(option);
302
- connRef.current
303
- .send(msg)
304
- .then(res => {
305
- console.log(
306
- '%cChatSDK: Send msg success: %s',
307
- 'color: blue',
308
- JSON.stringify(res, null, 2),
309
- );
310
- // update local messagre store
311
- const messageData = {
312
- msg: option.msg.replace(/^(\n)+|(\n)+$/g, ''),
313
- createdTimestamp: timeNow(),
314
- msgId: res?.serverMsgId,
315
- isDeleted: false,
316
- type: option.type,
317
- thumb: option?.ext?.file_url + '&thumbnail=true',
318
- url: option?.ext?.file_url,
319
- ext: option?.ext?.file_ext,
320
- fileName: option?.ext?.file_name,
321
- };
322
- //todo chattype as per natue type
323
- // this is local user messages
324
- if (option.chatType === SDKChatType.SINGLE_CHAT) {
325
- addMessageToPrivateStore(Number(option.to), messageData, true);
326
- } else {
327
- addMessageToStore(Number(option.from), messageData);
328
- }
329
- })
330
- .catch(error => {
331
- logger.debug(
332
- LogSource.Internals,
333
- 'CHAT',
334
- 'Failed sending chat message',
335
- error,
336
- );
337
- });
338
- }
339
- };
340
-
341
- const deleteChatUser = async () => {
342
- const groupID = data.chat.group_id;
343
- const userID = data.uid;
344
- const isChatGroupOwner = data.chat.is_group_owner;
345
- // owner exit user > 1 , dont call delete
346
- // ower exit user = 1, delete ,
347
- // member exit user > 1 delete ,
348
- // member exit user = 1 , owner needs to be deleted
349
- try {
350
- const response = await fetch(
351
- `${$config.BACKEND_ENDPOINT}/v1/${data.channel}/chat/${groupID}/users/${userID}/${isChatGroupOwner}`,
352
- {
353
- method: 'DELETE',
354
- headers: {
355
- 'Content-Type': 'application/json',
356
- authorization: store.token ? `Bearer ${store.token}` : '',
357
- },
358
- },
359
- );
360
- const res = await response.json();
361
- sessionStorage.removeItem('user_id');
362
- logger.debug(
363
- LogSource.Internals,
364
- 'CHAT',
365
- `User ${userID} deleted from Chat Server`,
366
- );
367
- return res;
368
- } catch (error) {
369
- logger.debug(
370
- LogSource.Internals,
371
- 'CHAT',
372
- `Failed deleting User ${userID} from Chat Server`,
373
- error,
374
- );
375
- }
376
- };
377
-
378
- const downloadAttachment = (fileName: string, fileUrl: string) => {
379
- const anchor = document.createElement('a');
380
- anchor.href = fileUrl;
381
- anchor.target = '_blank';
382
- anchor.download = fileName;
383
- anchor.click();
384
- anchor.remove();
385
- };
386
-
387
- const uploadAttachment = uploadFiles => {
388
- const {file_type, file_length, file_name, file_url, file_obj, file_ext} =
389
- uploadFiles;
390
- const CHAT_APP_KEY = `${$config.CHAT_ORG_NAME}#${$config.CHAT_APP_NAME}`;
391
- const uploadObj = {
392
- onFileUploadProgress: (data: ProgressEvent) => {
393
- console.log('Chat-SDK: upload inprogress', data);
394
- setUploadStatus(UploadStatus.IN_PROGRESS);
395
- },
396
- onFileUploadComplete: (data: any) => {
397
- console.log('Chat-SDK: upload success', data);
398
- const url = `${data.uri}/${data.entities[0].uuid}?em-redirect=true&share-secret=${data.entities[0]['share-secret']}`;
399
- //TODO: handle for multiple uploads
400
- setUploadedFiles(prev => {
401
- return [{...prev[0], file_url: url}];
402
- });
403
- setUploadStatus(UploadStatus.SUCCESS);
404
- },
405
- onFileUploadError: (error: any) => {
406
- console.log('Chat-SDK: upload error', error);
407
- logger.error(LogSource.Internals, 'CHAT', 'Attachment upload failed');
408
- setUploadStatus(UploadStatus.FAILURE);
409
- },
410
- onFileUploadCanceled: () => {
411
- //setUploadStatus(UploadStatus.NOT_STARTED);
412
- },
413
- accessToken: data?.chat?.user_token,
414
- appKey: CHAT_APP_KEY,
415
- file: file_obj,
416
- apiUrl: $config.CHAT_URL,
417
- };
418
-
419
- try {
420
- AgoraChat.utils.uploadFile(uploadObj);
421
- } catch (error) {
422
- logger.debug(
423
- LogSource.Internals,
424
- 'CHAT',
425
- 'Attachment upload failed',
426
- error,
427
- );
428
- console.error(error);
429
- }
430
- };
431
-
432
- const deleteAttachment = (
433
- msgId: string,
434
- recallFromUser: string,
435
- chatType: SDKChatType,
436
- ) => {
437
- const option = {mid: msgId, to: recallFromUser, chatType};
438
- if (connRef.current) {
439
- connRef.current
440
- .recallMessage(option)
441
- .then(res => {
442
- console.log('recall success', res);
443
- })
444
- .catch(err => {
445
- logger.debug(
446
- LogSource.Internals,
447
- 'CHAT',
448
- 'Chat Message Reacalled Failed',
449
- err,
450
- );
451
- });
452
- }
453
- };
454
-
455
- return (
456
- <chatConfigureContext.Provider
457
- value={{
458
- open,
459
- setOpen,
460
- sendChatSDKMessage,
461
- deleteChatUser,
462
- downloadAttachment,
463
- uploadAttachment,
464
- deleteAttachment,
465
- }}>
466
- {children}
467
- </chatConfigureContext.Provider>
468
- );
469
- };
470
-
471
- export const useChatConfigure = createHook(chatConfigureContext);
472
-
473
- export default ChatConfigure;