agora-appbuilder-core 4.0.27 → 4.0.28-beta-2

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 (83) hide show
  1. package/package.json +2 -2
  2. package/template/_package-lock.json +10 -7
  3. package/template/agora-rn-uikit/src/Reducer/UserOffline.ts +9 -0
  4. package/template/bridge/rtm/web/index.ts +44 -26
  5. package/template/customization-api/app-state.ts +1 -0
  6. package/template/customization-api/atoms.ts +8 -0
  7. package/template/customization-api/index.ts +1 -0
  8. package/template/customization-api/sub-components.ts +4 -1
  9. package/template/customization-api/temp.ts +1 -2
  10. package/template/customization-api/typeDefinition.ts +8 -0
  11. package/template/customization-api/types.ts +3 -0
  12. package/template/customization-api/utils.ts +10 -1
  13. package/template/defaultConfig.js +2 -2
  14. package/template/ios/HelloWorld.xcodeproj/project.pbxproj +102 -50
  15. package/template/ios/HelloWorld.xcodeproj/xcshareddata/xcschemes/ScreenSharing.xcscheme +95 -0
  16. package/template/ios/Podfile +1 -1
  17. package/template/ios/Podfile.lock +200 -44
  18. package/template/ios/ScreenSharing/SampleHandler.h +2 -6
  19. package/template/ios/ScreenSharing/SampleHandler.m +17 -48
  20. package/template/package-lock.json +10 -7
  21. package/template/package.json +1 -1
  22. package/template/src/AppWrapper.tsx +2 -2
  23. package/template/src/assets/selection.json +3491 -1
  24. package/template/src/atoms/ActionMenu.tsx +96 -113
  25. package/template/src/atoms/LinkButton.tsx +4 -3
  26. package/template/src/atoms/ToolbarItem.tsx +36 -22
  27. package/template/src/atoms/ToolbarPreset.tsx +18 -3
  28. package/template/src/components/Controls.tsx +72 -49
  29. package/template/src/components/CustomSidePanel.tsx +82 -0
  30. package/template/src/components/EventsConfigure.tsx +11 -27
  31. package/template/src/components/Navbar.tsx +51 -86
  32. package/template/src/components/NavbarMobile.tsx +27 -3
  33. package/template/src/components/PinnedVideo.tsx +9 -0
  34. package/template/src/components/RTMConfigure.tsx +69 -1
  35. package/template/src/components/Settings.tsx +6 -29
  36. package/template/src/components/chat/chatConfigure.native.tsx +123 -119
  37. package/template/src/components/chat/chatConfigure.tsx +59 -46
  38. package/template/src/components/chat-messages/useChatMessages.tsx +5 -4
  39. package/template/src/components/chat-ui/useChatUIControls.tsx +4 -1
  40. package/template/src/components/livestream/views/LiveStreamControls.tsx +2 -1
  41. package/template/src/components/participants/UserActionMenuOptions.tsx +10 -10
  42. package/template/src/components/virtual-background/VBButton.tsx +5 -7
  43. package/template/src/language/default-labels/videoCallScreenLabels.ts +9 -2
  44. package/template/src/language/i18nTypes.ts +1 -1
  45. package/template/src/pages/video-call/ActionSheet.native.tsx +110 -34
  46. package/template/src/pages/video-call/ActionSheet.tsx +109 -27
  47. package/template/src/pages/video-call/ActionSheetContent.tsx +67 -49
  48. package/template/src/pages/video-call/ActionSheetHandle.tsx +12 -2
  49. package/template/src/pages/video-call/SidePanelHeader.tsx +28 -2
  50. package/template/src/pages/video-call/VideoCallScreen.tsx +70 -16
  51. package/template/src/pages/video-call/VideoRenderer.tsx +1 -0
  52. package/template/src/rtm-events-api/Events.ts +37 -3
  53. package/template/src/rtm-events-api/LocalEvents.ts +1 -0
  54. package/template/src/rtm-events-api/types.ts +5 -0
  55. package/template/src/subComponents/ChatBubble.tsx +15 -1
  56. package/template/src/subComponents/ChatInput.tsx +18 -7
  57. package/template/src/subComponents/CopyJoinInfo.tsx +5 -13
  58. package/template/src/subComponents/LayoutIconButton.tsx +6 -14
  59. package/template/src/subComponents/LocalAudioMute.tsx +7 -11
  60. package/template/src/subComponents/LocalEndCall.tsx +6 -4
  61. package/template/src/subComponents/LocalSwitchCamera.tsx +5 -4
  62. package/template/src/subComponents/LocalVideoMute.tsx +10 -36
  63. package/template/src/subComponents/Recording.tsx +4 -10
  64. package/template/src/subComponents/ScreenShareNotice.tsx +3 -0
  65. package/template/src/subComponents/SidePanelEnum.tsx +6 -6
  66. package/template/src/subComponents/caption/CaptionContainer.tsx +2 -2
  67. package/template/src/subComponents/caption/CaptionIcon.tsx +21 -17
  68. package/template/src/subComponents/caption/TranscriptIcon.tsx +6 -3
  69. package/template/src/subComponents/chat/ChatActionMenu.tsx +3 -3
  70. package/template/src/subComponents/chat/ChatAttachment.tsx +107 -51
  71. package/template/src/subComponents/chat/ChatEmoji.tsx +8 -4
  72. package/template/src/subComponents/chat/ChatSendButton.tsx +52 -30
  73. package/template/src/subComponents/chat/ChatUploadStatus.tsx +22 -3
  74. package/template/src/subComponents/chat/ImagePopup.tsx +4 -4
  75. package/template/src/subComponents/livestream/controls/LocalRaiseHand.tsx +14 -25
  76. package/template/src/subComponents/screenshare/ScreenshareButton.tsx +8 -7
  77. package/template/src/subComponents/screenshare/ScreenshareConfigure.native.tsx +333 -163
  78. package/template/src/utils/common.tsx +22 -9
  79. package/template/src/utils/useEndCall.ts +6 -4
  80. package/template/src/utils/useFullScreen.native.ts +12 -0
  81. package/template/src/utils/useOrientation.tsx +46 -46
  82. package/template/src/utils/useSidePanel.tsx +2 -2
  83. package/template/src/utils/useString.ts +6 -4
@@ -1,8 +1,7 @@
1
1
  import React, {useContext} from 'react';
2
- import {Text, ViewStyle} from 'react-native';
2
+ import {ViewStyle} from 'react-native';
3
3
  import {useString} from '../utils/useString';
4
4
  import {ClientRoleType, PropsContext, ToggleState} from '../../agora-rn-uikit';
5
- import Styles from '../components/styles';
6
5
  import {isAndroid, isIOS, useLocalUserInfo, useRtc} from 'customization-api';
7
6
  import IconButton, {IconButtonProps} from '../atoms/IconButton';
8
7
  import {useScreenshare} from './screenshare/useScreenshare';
@@ -10,6 +9,7 @@ import {useToolbarMenu} from '../utils/useMenu';
10
9
  import ToolbarMenuItem from '../atoms/ToolbarMenuItem';
11
10
  import {useActionSheet} from '../utils/useActionSheet';
12
11
  import {toolbarItemSwitchCameraText} from '../language/default-labels/videoCallScreenLabels';
12
+ import {useToolbarProps} from '../atoms/ToolbarItem';
13
13
 
14
14
  export interface LocalSwitchCameraProps {
15
15
  render?: (onPress: () => void, isVideoEnabled: boolean) => JSX.Element;
@@ -20,6 +20,7 @@ export interface LocalSwitchCameraProps {
20
20
  }
21
21
 
22
22
  function LocalSwitchCamera(props: LocalSwitchCameraProps) {
23
+ const {label = null, onPress: onPressCustom = null} = useToolbarProps();
23
24
  const {isToolbarMenuItem} = useToolbarMenu();
24
25
  const {callbacks} = useContext(PropsContext);
25
26
  const {isScreenshareActive} = useScreenshare();
@@ -64,9 +65,9 @@ function LocalSwitchCamera(props: LocalSwitchCameraProps) {
64
65
  iconContainerStyle: iconContainerStyle,
65
66
  },
66
67
  disabled: disabled,
67
- onPress: onPress,
68
+ onPress: onPressCustom || onPress,
68
69
  btnTextProps: {
69
- text: showTitle ? switchCameraText?.replace(' ', '\n') : '',
70
+ text: showTitle ? label || switchCameraText?.replace(' ', '\n') : '',
70
71
  numberOfLines: 2,
71
72
  textStyle: {
72
73
  marginTop: 8,
@@ -9,26 +9,21 @@
9
9
  information visit https://appbuilder.agora.io.
10
10
  *********************************************
11
11
  */
12
- import React, {useContext, useEffect, useRef} from 'react';
12
+ import React, {useContext} from 'react';
13
13
  import {
14
14
  ToggleState,
15
15
  PermissionState,
16
- ImageIcon as UIKitImageIcon,
17
16
  ClientRoleType,
18
17
  PropsContext,
19
- RtcContext,
20
- DispatchContext,
21
18
  } from '../../agora-rn-uikit';
22
19
  import useMuteToggleLocal, {MUTE_LOCAL_TYPE} from '../utils/useMuteToggleLocal';
23
- import Styles from '../components/styles';
24
20
  import {useString} from '../utils/useString';
25
21
  import {useLocalUserInfo, useRoomInfo} from 'customization-api';
26
22
  import IconButton, {IconButtonProps} from '../atoms/IconButton';
27
- import ThemeConfig from '../theme';
28
23
  import {ImageIconProps} from '../atoms/ImageIcon';
29
24
  import useIsHandRaised from '../utils/useIsHandRaised';
30
25
  import {useScreenshare} from './screenshare/useScreenshare';
31
- import {isAndroid, isWebInternal} from '../utils/common';
26
+ import {isAndroid} from '../utils/common';
32
27
  import {isIOS} from '../utils/common';
33
28
  import {useVideoCall} from '../components/useVideoCall';
34
29
  import {useToolbarMenu} from '../utils/useMenu';
@@ -43,6 +38,7 @@ import {
43
38
  toolbarItemCameraTooltipText,
44
39
  } from '../language/default-labels/videoCallScreenLabels';
45
40
  import {LogSource, logger} from '../logger/AppBuilderLogger';
41
+ import {useToolbarProps} from '../atoms/ToolbarItem';
46
42
  /**
47
43
  * A component to mute / unmute the local video
48
44
  */
@@ -59,9 +55,9 @@ export interface LocalVideoMuteProps {
59
55
  }
60
56
 
61
57
  function LocalVideoMute(props: LocalVideoMuteProps) {
58
+ const {label = null, onPress: onPressCustom = null} = useToolbarProps();
59
+
62
60
  const {rtcProps} = useContext(PropsContext);
63
- const {isScreenshareActive} = useScreenshare();
64
- const {setShowStopScreenSharePopup} = useVideoCall();
65
61
  const {isToolbarMenuItem} = useToolbarMenu();
66
62
  const {
67
63
  data: {isHost},
@@ -71,7 +67,7 @@ function LocalVideoMute(props: LocalVideoMuteProps) {
71
67
  const isHandRaised = useIsHandRaised();
72
68
  const localMute = useMuteToggleLocal();
73
69
  const {showToolTip = false, disabled = false, showWarningIcon = true} = props;
74
- const {isOnActionSheet, isOnFirstRow, showLabel} = useActionSheet();
70
+ const {isOnActionSheet, showLabel} = useActionSheet();
75
71
  const {position} = useToolbar();
76
72
  const {
77
73
  rtcProps: {callActive},
@@ -95,23 +91,9 @@ function LocalVideoMute(props: LocalVideoMuteProps) {
95
91
  permissionDenied,
96
92
  },
97
93
  );
98
- if ((isAndroid() || isIOS()) && isScreenshareActive) {
99
- logger.log(
100
- LogSource.Internals,
101
- 'LOCAL_MUTE',
102
- 'Screenshare is active. To turn on video screenshare should be turn off',
103
- );
104
- setShowStopScreenSharePopup(true);
105
- } else {
106
- localMute(MUTE_LOCAL_TYPE.video);
107
- }
94
+ localMute(MUTE_LOCAL_TYPE.video);
108
95
  };
109
- //native screen share uses same local uid to publish the screenshare steam
110
- //so if screenshare active on native then its means local video is turned off
111
- const isVideoEnabled =
112
- (isAndroid() || isIOS()) && isScreenshareActive
113
- ? false
114
- : local.video === ToggleState.enabled;
96
+ const isVideoEnabled = local.video === ToggleState.enabled;
115
97
 
116
98
  const permissionDenied =
117
99
  local.permissionStatus === PermissionState.REJECTED ||
@@ -150,24 +132,16 @@ function LocalVideoMute(props: LocalVideoMuteProps) {
150
132
  hoverEffectStyle: props?.plainIconHoverEffect
151
133
  ? {backgroundColor: $config.ICON_BG_COLOR, borderRadius: 20}
152
134
  : {},
153
- onPress,
135
+ onPress: onPressCustom || onPress,
154
136
  iconProps,
155
137
  btnTextProps: {
156
- text: showLabel && callActive && !isMobileUA() ? videoLabel : '',
138
+ text: showLabel && callActive && !isMobileUA() ? label || videoLabel : '',
157
139
  textColor: $config.FONT_COLOR,
158
140
  },
159
141
  disabled: permissionDenied || disabled ? true : false,
160
142
  };
161
143
 
162
144
  if (isOnActionSheet) {
163
- // iconButtonProps.containerStyle = {
164
- // backgroundColor: $config.CARD_LAYER_2_COLOR,
165
- // width: 52,
166
- // height: 52,
167
- // borderRadius: 26,
168
- // justifyContent: 'center',
169
- // alignItems: 'center',
170
- // };
171
145
  const isAudience = rtcProps?.role == ClientRoleType.ClientRoleAudience;
172
146
  const isBroadCasting =
173
147
  rtcProps?.role == ClientRoleType.ClientRoleBroadcaster;
@@ -18,6 +18,7 @@ import ToolbarMenuItem from '../atoms/ToolbarMenuItem';
18
18
  import {useActionSheet} from '../utils/useActionSheet';
19
19
  import {useString} from '../utils/useString';
20
20
  import {toolbarItemRecordingText} from '../language/default-labels/videoCallScreenLabels';
21
+ import {useToolbarProps} from '../atoms/ToolbarItem';
21
22
 
22
23
  export interface RecordingButtonProps {
23
24
  showLabel?: boolean;
@@ -25,6 +26,7 @@ export interface RecordingButtonProps {
25
26
  }
26
27
 
27
28
  const Recording = (props: RecordingButtonProps) => {
29
+ const {label = null, onPress: onPressCustom = null} = useToolbarProps();
28
30
  const {isToolbarMenuItem} = useToolbarMenu();
29
31
  const {startRecording, inProgress, isRecordingActive} = useRecording();
30
32
  const recordingButton = useString<boolean>(toolbarItemRecordingText);
@@ -45,23 +47,15 @@ const Recording = (props: RecordingButtonProps) => {
45
47
  : $config.SECONDARY_ACTION_COLOR,
46
48
  },
47
49
  btnTextProps: {
48
- text: showLabel ? recordingButton(isRecordingActive) : '',
50
+ text: showLabel ? label || recordingButton(isRecordingActive) : '',
49
51
  textColor: $config.FONT_COLOR,
50
52
  },
51
- onPress,
53
+ onPress: onPressCustom || onPress,
52
54
  disabled: inProgress,
53
55
  containerStyle: inProgress ? {opacity: 0.6} : {},
54
56
  };
55
57
 
56
58
  if (isOnActionSheet) {
57
- // iconButtonProps.containerStyle = {
58
- // backgroundColor: $config.CARD_LAYER_2_COLOR,
59
- // width: 52,
60
- // height: 52,
61
- // borderRadius: 26,
62
- // justifyContent: 'center',
63
- // alignItems: 'center',
64
- // };
65
59
  iconButtonProps.btnTextProps.textStyle = {
66
60
  color: $config.FONT_COLOR,
67
61
  marginTop: 8,
@@ -24,6 +24,7 @@ import {
24
24
  videoRoomScreenshareOverlayText,
25
25
  videoRoomScreenshareStopSharingBtnText,
26
26
  } from '../language/default-labels/videoCallScreenLabels';
27
+ import {isAndroid, isIOS} from '../utils/common';
27
28
  /**
28
29
  *
29
30
  * @param uid - uid of the user
@@ -53,6 +54,8 @@ function ScreenShareNotice({uid, isMax}: {uid: UidType; isMax: boolean}) {
53
54
  </Text>
54
55
  {!isMax && currentLayout === getPinnedLayoutName() ? (
55
56
  <></>
57
+ ) : isAndroid() || isIOS() ? (
58
+ <></>
56
59
  ) : (
57
60
  <TouchableOpacity
58
61
  style={styles.btnContainer}
@@ -10,10 +10,10 @@
10
10
  *********************************************
11
11
  */
12
12
  export enum SidePanelType {
13
- None,
14
- Participants,
15
- Chat,
16
- Settings,
17
- Transcript,
18
- VirtualBackground,
13
+ None = 'None',
14
+ Participants = 'Participants',
15
+ Chat = 'Chat',
16
+ Settings = 'Settings',
17
+ Transcript = 'Transcript',
18
+ VirtualBackground = 'VirtualBackground',
19
19
  }
@@ -218,7 +218,7 @@ const CaptionsActionMenu = (props: CaptionsActionMenuProps) => {
218
218
  textColor: $config.FONT_COLOR,
219
219
  title: changeSpokenLangLabel + ' ',
220
220
  disabled: isLangChangeInProgress,
221
- callback: () => {
221
+ onPress: () => {
222
222
  setActionMenuVisible(false);
223
223
  setLanguagePopup(true);
224
224
  },
@@ -229,7 +229,7 @@ const CaptionsActionMenu = (props: CaptionsActionMenuProps) => {
229
229
  iconColor: $config.SECONDARY_ACTION_COLOR,
230
230
  textColor: $config.FONT_COLOR,
231
231
  title: hideCaptionLabel,
232
- callback: () => {
232
+ onPress: () => {
233
233
  setActionMenuVisible(false);
234
234
  setIsCaptionON(false);
235
235
  },
@@ -6,6 +6,7 @@ import LanguageSelectorPopup from './LanguageSelectorPopup';
6
6
  import useSTTAPI from './useSTTAPI';
7
7
  import {useString} from '../../utils/useString';
8
8
  import {toolbarItemCaptionText} from '../../language/default-labels/videoCallScreenLabels';
9
+ import {useToolbarProps} from '../../atoms/ToolbarItem';
9
10
 
10
11
  interface CaptionIconProps {
11
12
  plainIconHoverEffect?: boolean;
@@ -18,6 +19,8 @@ interface CaptionIconProps {
18
19
  }
19
20
 
20
21
  const CaptionIcon = (props: CaptionIconProps) => {
22
+ const {label: labelCustom = null, onPress: onPressCustom = null} =
23
+ useToolbarProps();
21
24
  const {
22
25
  showLabel = $config.ICON_TEXT,
23
26
  isOnActionSheet = false,
@@ -33,22 +36,23 @@ const CaptionIcon = (props: CaptionIconProps) => {
33
36
  const isDisabled = !isAuthorizedSTTUser();
34
37
  const captionLabel = useString<boolean>(toolbarItemCaptionText);
35
38
  const label = captionLabel(isCaptionON);
39
+ const onPress = () => {
40
+ if (isSTTError) {
41
+ setIsCaptionON(prev => !prev);
42
+ closeActionSheet();
43
+ return;
44
+ }
45
+ if (isSTTActive) {
46
+ // is lang popup has been shown once for any user in meeting
47
+ setIsCaptionON(prev => !prev);
48
+ closeActionSheet();
49
+ } else {
50
+ isFirstTimePopupOpen.current = true;
51
+ setLanguagePopup(true);
52
+ }
53
+ };
36
54
  const iconButtonProps: IconButtonProps = {
37
- onPress: () => {
38
- if (isSTTError) {
39
- setIsCaptionON(prev => !prev);
40
- closeActionSheet();
41
- return;
42
- }
43
- if (isSTTActive) {
44
- // is lang popup has been shown once for any user in meeting
45
- setIsCaptionON(prev => !prev);
46
- closeActionSheet();
47
- } else {
48
- isFirstTimePopupOpen.current = true;
49
- setLanguagePopup(true);
50
- }
51
- },
55
+ onPress: onPressCustom || onPress,
52
56
  disabled: isDisabled,
53
57
  iconProps: {
54
58
  name: isCaptionON ? 'captions-off' : 'captions',
@@ -64,8 +68,8 @@ const CaptionIcon = (props: CaptionIconProps) => {
64
68
  btnTextProps: {
65
69
  text: showLabel
66
70
  ? isOnActionSheet
67
- ? label?.replace(' ', '\n')
68
- : label
71
+ ? labelCustom || label?.replace(' ', '\n')
72
+ : labelCustom || label
69
73
  : '',
70
74
  textColor: $config.FONT_COLOR,
71
75
  numberOfLines: 2,
@@ -7,6 +7,7 @@ import {useCaption} from './useCaption';
7
7
  import useSTTAPI from './useSTTAPI';
8
8
  import {useString} from '../../utils/useString';
9
9
  import {toolbarItemTranscriptText} from '../../language/default-labels/videoCallScreenLabels';
10
+ import {useToolbarProps} from '../../atoms/ToolbarItem';
10
11
 
11
12
  interface TranscriptIconProps {
12
13
  plainIconHoverEffect?: boolean;
@@ -18,6 +19,8 @@ interface TranscriptIconProps {
18
19
  }
19
20
 
20
21
  const TranscriptIcon = (props: TranscriptIconProps) => {
22
+ const {label: labelCustom = null, onPress: onPressCustom = null} =
23
+ useToolbarProps();
21
24
  const {setSidePanel, sidePanel} = useSidePanel();
22
25
  const {
23
26
  showToolTip = false,
@@ -54,7 +57,7 @@ const TranscriptIcon = (props: TranscriptIconProps) => {
54
57
 
55
58
  const label = useString<boolean>(toolbarItemTranscriptText);
56
59
  const iconButtonProps: IconButtonProps = {
57
- onPress,
60
+ onPress: onPressCustom || onPress,
58
61
  iconProps: {
59
62
  name: 'transcript',
60
63
  iconBackgroundColor: isTranscriptON
@@ -70,8 +73,8 @@ const TranscriptIcon = (props: TranscriptIconProps) => {
70
73
  btnTextProps: {
71
74
  text: showLabel
72
75
  ? isOnActionSheet
73
- ? label(isTranscriptON)?.replace(' ', '\n')
74
- : label(isTranscriptON)
76
+ ? labelCustom || label(isTranscriptON)?.replace(' ', '\n')
77
+ : labelCustom || label(isTranscriptON)
75
78
  : '',
76
79
  textColor: $config.FONT_COLOR,
77
80
  numberOfLines: 2,
@@ -89,7 +89,7 @@ export const ChatActionMenu = (props: CaptionsActionMenuProps) => {
89
89
  iconColor: $config.SECONDARY_ACTION_COLOR,
90
90
  textColor: $config.FONT_COLOR,
91
91
  title: useString(chatActionMenuDownloadText)(),
92
- callback: () => {
92
+ onPress: () => {
93
93
  downloadAttachment(fileName, fileUrl);
94
94
  setActionMenuVisible(false);
95
95
  },
@@ -100,7 +100,7 @@ export const ChatActionMenu = (props: CaptionsActionMenuProps) => {
100
100
  iconColor: $config.SECONDARY_ACTION_COLOR,
101
101
  textColor: $config.FONT_COLOR,
102
102
  title: useString(chatActionMenuCopyLinkText)(),
103
- callback: () => {
103
+ onPress: () => {
104
104
  Clipboard.setString(fileUrl);
105
105
  setActionMenuVisible(false);
106
106
  },
@@ -111,7 +111,7 @@ export const ChatActionMenu = (props: CaptionsActionMenuProps) => {
111
111
  textColor: $config.SEMANTIC_ERROR,
112
112
  iconSize: 24,
113
113
  title: useString(chatActionMenuDeleteText)(),
114
- callback: () => {
114
+ onPress: () => {
115
115
  if (isLocal) {
116
116
  // confirm dialog : user is deleting for all
117
117
  setShowDeleteMessageModal(true);
@@ -7,6 +7,7 @@ import {useChatConfigure} from '../../components/chat/chatConfigure';
7
7
  import Toast from '../../../react-native-toast-message';
8
8
  import {
9
9
  File,
10
+ MAX_FILES_UPLOAD,
10
11
  MAX_UPLOAD_SIZE,
11
12
  UploadStatus,
12
13
  useChatUIControls,
@@ -19,6 +20,7 @@ import {
19
20
  chatUploadErrorFileTypeToastSubHeading,
20
21
  } from '../../language/default-labels/videoCallScreenLabels';
21
22
  import {useString} from '../../utils/useString';
23
+ import getUniqueID from '../../utils/getUniqueID';
22
24
 
23
25
  export interface ChatAttachmentButtonProps {
24
26
  render?: (onPress: () => void) => JSX.Element;
@@ -26,9 +28,15 @@ export interface ChatAttachmentButtonProps {
26
28
 
27
29
  export const ChatAttachmentButton = (props: ChatAttachmentButtonProps) => {
28
30
  const fileInputRef = React.useRef<HTMLInputElement | null>(null);
31
+
29
32
  const {data} = useRoomInfo();
30
- const {privateChatUser, setUploadStatus, setUploadedFiles, uploadStatus} =
31
- useChatUIControls();
33
+ const {
34
+ privateChatUser,
35
+ setUploadStatus,
36
+ setUploadedFiles,
37
+ uploadStatus,
38
+ uploadedFiles,
39
+ } = useChatUIControls();
32
40
  const {uploadAttachment} = useChatConfigure();
33
41
  const toastHeadingType = useString(chatUploadErrorToastHeading)();
34
42
  const toastHeadingSize = useString(chatUploadErrorFileSizeToastHeading)();
@@ -56,59 +64,102 @@ export const ChatAttachmentButton = (props: ChatAttachmentButtonProps) => {
56
64
  bmp: true,
57
65
  };
58
66
 
59
- const handleFileUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
60
- const selectedFile = e.target.files && e.target.files[0];
61
- const file = AgoraChat.utils.getFileUrl(e.target);
62
- const uploadedFileType = file.filetype.toLowerCase();
63
- const isImageUploaded = uploadedFileType in imageAllowedTypes;
64
- const isFileUploaded = uploadedFileType in fileAllowedTypes;
65
-
66
- if (file.data.size > MAX_UPLOAD_SIZE * 1024 * 1024) {
67
- Toast.show({
68
- leadingIconName: 'alert',
69
- type: 'error',
70
- text1: toastHeadingSize,
71
- text2: errorSubHeadingSize(MAX_UPLOAD_SIZE.toString()),
72
- visibilityTime: 3000,
73
- primaryBtn: null,
74
- secondaryBtn: null,
75
- });
76
- return;
77
- }
78
- if (!(isImageUploaded || isFileUploaded)) {
79
- // Toast.show({
80
- // leadingIconName: 'chat_attachment_unknown',
81
- // type: 'info',
82
- // text1: toastHeadingType,
83
- // text2: errorSubHeadingType(file.filetype),
84
- // visibilityTime: 3000,
85
- // primaryBtn: null,
86
- // secondaryBtn: null,
87
- // });
88
-
89
- return;
90
- }
67
+ const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
68
+ const files = e.target.files;
69
+
70
+ if (files) {
71
+ const fileArray = Array.from(files);
72
+ let localUploadCount = uploadedFiles.length; // to track uploads
73
+ const oversizedFileNames: string[] = []; // file names exceeding limit
74
+
75
+ for (const file of fileArray) {
76
+ if (localUploadCount >= MAX_FILES_UPLOAD) {
77
+ return;
78
+ }
79
+ // temporary input element as upload utils requires it
80
+ const tempInput = document.createElement('input');
81
+ tempInput.type = 'file';
82
+ tempInput.style.display = 'none';
83
+
84
+ const dataTransfer = new DataTransfer();
85
+ dataTransfer.items.add(file);
86
+ tempInput.files = dataTransfer.files;
87
+
88
+ const fileObj = AgoraChat.utils.getFileUrl(tempInput);
91
89
 
92
- if (!selectedFile) return;
93
-
94
- const uploadedFile: File = {
95
- file_name: file.filename,
96
- file_ext: uploadedFileType,
97
- file_url: '',
98
- file_length: 0,
99
- file_type: isImageUploaded ? ChatMessageType.IMAGE : ChatMessageType.FILE,
100
- file_obj: file,
101
- };
102
- // currently supporting only 1 upload
103
- // setUploadedFiles(prev => [...prev, uploadedFile]);
104
- setUploadedFiles(prev => [uploadedFile]);
105
-
106
- uploadAttachment(uploadedFile);
90
+ const uploadedFileType = fileObj.filetype.toLowerCase();
91
+ const isImageUploaded = uploadedFileType in imageAllowedTypes;
92
+ const isFileUploaded = uploadedFileType in fileAllowedTypes;
93
+
94
+ if (file.size > MAX_UPLOAD_SIZE * 1024 * 1024) {
95
+ oversizedFileNames.push(file.name);
96
+ continue;
97
+ }
98
+ if (!(isImageUploaded || isFileUploaded)) {
99
+ return;
100
+ }
101
+
102
+ const uploadedFile: File = {
103
+ file_id: getUniqueID(),
104
+ file_name: file.name,
105
+ file_ext: uploadedFileType,
106
+ file_url: '',
107
+ file_length: file.size,
108
+ file_type: isImageUploaded
109
+ ? ChatMessageType.IMAGE
110
+ : ChatMessageType.FILE,
111
+ file_obj: fileObj,
112
+ upload_status: UploadStatus.IN_PROGRESS,
113
+ };
114
+
115
+ localUploadCount++;
116
+ // Add the uploaded file to the state
117
+ setUploadedFiles(prev => [...prev, uploadedFile]);
118
+
119
+ try {
120
+ // Start uploading the file and wait for it to complete
121
+ await uploadAttachment(uploadedFile);
122
+ } catch (error) {
123
+ console.error(
124
+ 'Upload failed for file:',
125
+ uploadedFile.file_name,
126
+ error,
127
+ );
128
+ // Update the file status to FAILURE
129
+ setUploadedFiles(prev => {
130
+ const updatedFiles = prev.map(f =>
131
+ f.file_id === uploadedFile.file_id
132
+ ? {...f, upload_status: UploadStatus.FAILURE}
133
+ : f,
134
+ );
135
+ return updatedFiles;
136
+ });
137
+ }
138
+ }
139
+ // Show the toast notification for oversized files, if any
140
+ if (oversizedFileNames.length > 0) {
141
+ Toast.show({
142
+ leadingIconName: 'alert',
143
+ type: 'error',
144
+ text1: toastHeadingSize,
145
+ text2: errorSubHeadingSize(
146
+ MAX_UPLOAD_SIZE.toString(),
147
+ oversizedFileNames.join(', '),
148
+ ),
149
+ visibilityTime: 3000,
150
+ primaryBtn: null,
151
+ secondaryBtn: null,
152
+ });
153
+ }
154
+ }
107
155
  };
156
+
108
157
  const onPress = () => {
109
158
  fileInputRef.current.value = null;
110
159
  fileInputRef.current.click();
111
160
  };
161
+
162
+ const isMaxFilesUploaded = uploadedFiles.length >= MAX_FILES_UPLOAD;
112
163
  return props?.render ? (
113
164
  props.render(onPress)
114
165
  ) : (
@@ -120,6 +171,7 @@ export const ChatAttachmentButton = (props: ChatAttachmentButtonProps) => {
120
171
  style={{display: 'none'}}
121
172
  id={`file-input-`}
122
173
  ref={fileInputRef}
174
+ multiple
123
175
  />
124
176
  <IconButton
125
177
  hoverEffect={true}
@@ -127,7 +179,11 @@ export const ChatAttachmentButton = (props: ChatAttachmentButtonProps) => {
127
179
  backgroundColor: $config.ICON_BG_COLOR,
128
180
  borderRadius: 24,
129
181
  }}
130
- disabled={uploadStatus === UploadStatus.IN_PROGRESS ? true : false}
182
+ disabled={
183
+ uploadStatus === UploadStatus.IN_PROGRESS || isMaxFilesUploaded
184
+ ? true
185
+ : false
186
+ }
131
187
  iconProps={{
132
188
  iconType: 'plain',
133
189
  iconContainerStyle: {
@@ -136,7 +192,7 @@ export const ChatAttachmentButton = (props: ChatAttachmentButtonProps) => {
136
192
  iconSize: 24,
137
193
  name: 'chat_attachment',
138
194
  tintColor:
139
- uploadStatus === UploadStatus.IN_PROGRESS
195
+ uploadStatus === UploadStatus.IN_PROGRESS || isMaxFilesUploaded
140
196
  ? $config.SEMANTIC_NEUTRAL
141
197
  : $config.SECONDARY_ACTION_COLOR,
142
198
  }}
@@ -129,7 +129,8 @@ export interface ChatEmojiButtonProps {
129
129
  }
130
130
 
131
131
  export const ChatEmojiButton = (props: ChatEmojiButtonProps) => {
132
- const {setShowEmojiPicker} = useChatUIControls();
132
+ const {setShowEmojiPicker, uploadedFiles} = useChatUIControls();
133
+ const isBtnDisabled = uploadedFiles.length > 0;
133
134
  const onPress = () => {
134
135
  setShowEmojiPicker(prev => !prev);
135
136
  };
@@ -142,17 +143,20 @@ export const ChatEmojiButton = (props: ChatEmojiButtonProps) => {
142
143
  backgroundColor: $config.ICON_BG_COLOR,
143
144
  borderRadius: 24,
144
145
  }}
146
+ disabled={isBtnDisabled}
145
147
  iconProps={{
146
148
  iconType: 'plain',
147
149
  base64: false,
148
- hoverBase64: true,
150
+ hoverBase64: isBtnDisabled ? false : true,
149
151
  iconContainerStyle: {
150
152
  padding: 4,
151
153
  },
152
154
  iconSize: 24,
153
155
  name: 'chat_emoji',
154
- hoverIconName: 'chat_emoji_fill',
155
- tintColor: $config.SECONDARY_ACTION_COLOR,
156
+ hoverIconName: isBtnDisabled ? 'chat_emoji' : 'chat_emoji_fill',
157
+ tintColor: isBtnDisabled
158
+ ? $config.SEMANTIC_NEUTRAL
159
+ : $config.SECONDARY_ACTION_COLOR,
156
160
  }}
157
161
  onPress={onPress}
158
162
  />