Skip to content

Commit 569f292

Browse files
authored
Merge pull request #757 from AgoraIO-Community/release/4.1.8-4
Precall validation and SDK Event for waiting room request/grant
2 parents 4cfb926 + 49944fa commit 569f292

File tree

11 files changed

+105
-38
lines changed

11 files changed

+105
-38
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agora-appbuilder-core",
3-
"version": "4.1.8-3",
3+
"version": "4.1.8-4",
44
"description": "React Native template for RTE app builder",
55
"main": "index.js",
66
"files": [

template/defaultConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ const DefaultConfig = {
7777
CHAT_ORG_NAME: '',
7878
CHAT_APP_NAME: '',
7979
CHAT_URL: '',
80-
CLI_VERSION: '3.1.8-3',
81-
CORE_VERSION: '4.1.8-3',
80+
CLI_VERSION: '3.1.8-4',
81+
CORE_VERSION: '4.1.8-4',
8282
DISABLE_LANDSCAPE_MODE: false,
8383
STT_AUTO_START: false,
8484
CLOUD_RECORDING_AUTO_START: false,

template/src/atoms/Input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const styles = StyleSheet.create({
6060
// height: 60, //causes text cut off in android
6161
width: '100%',
6262
borderWidth: 1,
63-
paddingVertical: 21,
63+
paddingVertical: 12,
6464
paddingHorizontal: 16,
6565
borderColor: $config.INPUT_FIELD_BORDER_COLOR,
6666
color: $config.FONT_COLOR,
@@ -71,6 +71,7 @@ const styles = StyleSheet.create({
7171
...Platform.select({
7272
web: {
7373
outlineStyle: 'none',
74+
lineHeight: '26px',
7475
},
7576
}),
7677
},

template/src/components/precall/joinCallBtn.native.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface PreCallJoinCallBtnProps {
3333

3434
const JoinCallBtn = (props: PreCallJoinCallBtnProps) => {
3535
const {rtcProps} = useContext(PropsContext);
36-
const {setCallActive} = usePreCall();
36+
const {setCallActive, setIsNameIsEmpty} = usePreCall();
3737
const username = useGetName();
3838
const {isJoinDataFetched} = useRoomInfo();
3939
const joinRoomButton =
@@ -58,12 +58,17 @@ const JoinCallBtn = (props: PreCallJoinCallBtnProps) => {
5858
}, [rtcProps?.role]);
5959

6060
const onSubmit = () => {
61+
if (!username || (username && username?.trim() === '')) {
62+
setIsNameIsEmpty(true);
63+
return;
64+
}
65+
setIsNameIsEmpty(false);
6166
setCallActive(true);
6267
};
6368

6469
const title = buttonText;
6570
const onPress = () => onSubmit();
66-
const disabled = !isJoinDataFetched || username === '';
71+
const disabled = !isJoinDataFetched;
6772
return props?.render ? (
6873
props.render(onPress, title, disabled)
6974
) : (

template/src/components/precall/joinCallBtn.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface PreCallJoinCallBtnProps {
4242

4343
const JoinCallBtn = (props: PreCallJoinCallBtnProps) => {
4444
const {rtcProps} = useContext(PropsContext);
45-
const {setCallActive} = usePreCall();
45+
const {setCallActive, setIsNameIsEmpty} = usePreCall();
4646
const username = useGetName();
4747
const setUsername = useSetName();
4848
const {isJoinDataFetched} = useRoomInfo();
@@ -59,6 +59,11 @@ const JoinCallBtn = (props: PreCallJoinCallBtnProps) => {
5959
);
6060

6161
const onSubmit = () => {
62+
if (!username || (username && username?.trim() === '')) {
63+
setIsNameIsEmpty(true);
64+
return;
65+
}
66+
setIsNameIsEmpty(false);
6267
logger.log(
6368
LogSource.Internals,
6469
'PRECALL_SCREEN',
@@ -95,7 +100,7 @@ const JoinCallBtn = (props: PreCallJoinCallBtnProps) => {
95100

96101
const title = buttonText;
97102
const onPress = () => onSubmit();
98-
const disabled = !isJoinDataFetched || username?.trim() === '';
103+
const disabled = !isJoinDataFetched;
99104
return props?.render ? (
100105
props.render(onPress, title, disabled)
101106
) : (

template/src/components/precall/joinWaitingRoomBtn.native.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
5858
const waitingRoomUsersInCallText = useString(waitingRoomUsersInCall);
5959
let pollingTimeout = React.useRef(null);
6060
const {rtcProps} = useContext(PropsContext);
61-
const {setCallActive, callActive} = usePreCall();
61+
const {setCallActive, callActive, setIsNameIsEmpty} = usePreCall();
6262
const username = useGetName();
6363
const {isJoinDataFetched, isInWaitingRoom} = useRoomInfo();
6464
const {setRoomInfo} = useSetRoomInfo();
@@ -212,6 +212,11 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
212212
};
213213

214214
const onSubmit = () => {
215+
if (!username || (username && username?.trim() === '')) {
216+
setIsNameIsEmpty(true);
217+
return;
218+
}
219+
setIsNameIsEmpty(false);
215220
shouldWaitingRoomPoll = true;
216221
// Enter waiting rooom;
217222
setRoomInfo(prev => {
@@ -232,8 +237,8 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
232237
const title = buttonText;
233238
const onPress = () => onSubmit();
234239
const disabled = $config.ENABLE_WAITING_ROOM_AUTO_REQUEST
235-
? !hasHostJoined || isInWaitingRoom || username?.trim() === ''
236-
: isInWaitingRoom || username?.trim() === '';
240+
? !hasHostJoined || isInWaitingRoom
241+
: isInWaitingRoom;
237242
return props?.render ? (
238243
props.render(onPress, title, disabled)
239244
) : (

template/src/components/precall/joinWaitingRoomBtn.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import {
4545
waitingRoomHostNotJoined,
4646
waitingRoomUsersInCall,
4747
} from '../../language/default-labels/videoCallScreenLabels';
48+
import SDKEvents from '../../utils/SdkEvents';
49+
import isSDK from '../../utils/isSDK';
4850

4951
const audio = new Audio(
5052
'https://dl.dropboxusercontent.com/s/1cdwpm3gca9mlo0/kick.mp3',
@@ -69,7 +71,7 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
6971
const waitingRoomUsersInCallText = useString(waitingRoomUsersInCall);
7072
let pollingTimeout = React.useRef(null);
7173
const {rtcProps} = useContext(PropsContext);
72-
const {setCallActive, callActive} = usePreCall();
74+
const {setCallActive, callActive, setIsNameIsEmpty} = usePreCall();
7375
const username = useGetName();
7476
const setUsername = useSetName();
7577
const {isJoinDataFetched, isInWaitingRoom} = useRoomInfo();
@@ -150,6 +152,10 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
150152
});
151153

152154
if (approved) {
155+
if (isSDK()) {
156+
//emit SDKEvent waiting-room-approval-granted
157+
SDKEvents.emit('waiting-room-approval-granted');
158+
}
153159
setRoomInfo(prev => {
154160
return {
155161
...prev,
@@ -189,6 +195,10 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
189195
};
190196
});
191197
} else {
198+
if (isSDK()) {
199+
//emit SDKEvent waiting-room-approval-rejected
200+
SDKEvents.emit('waiting-room-approval-rejected');
201+
}
192202
setRoomInfo(prev => {
193203
return {
194204
...prev,
@@ -236,6 +246,11 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
236246
};
237247

238248
const onSubmit = () => {
249+
if (!username || (username && username?.trim() === '')) {
250+
setIsNameIsEmpty(true);
251+
return;
252+
}
253+
setIsNameIsEmpty(false);
239254
shouldWaitingRoomPoll = true;
240255
setUsername(username.trim());
241256
//setCallActive(true);
@@ -252,7 +267,10 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
252267

253268
// join request API to server, server will send RTM message to all hosts regarding request from this user,
254269
requestServerToJoinRoom();
255-
270+
if (isSDK()) {
271+
//emit SDKEvent waiting for approval
272+
SDKEvents.emit('waiting-room-approval-requested');
273+
}
256274
// Play a sound to avoid autoblocking in safari
257275
if (isWebInternal() || isMobileOrTablet()) {
258276
audio.volume = 0;
@@ -281,8 +299,8 @@ const JoinWaitingRoomBtn = (props: PreCallJoinWaitingRoomBtnProps) => {
281299
const title = buttonText;
282300
const onPress = () => onSubmit();
283301
const disabled = $config.ENABLE_WAITING_ROOM_AUTO_REQUEST
284-
? !hasHostJoined || isInWaitingRoom || username?.trim() === ''
285-
: isInWaitingRoom || username?.trim() === '';
302+
? !hasHostJoined || isInWaitingRoom
303+
: isInWaitingRoom;
286304
return props?.render ? (
287305
props.render(onPress, title, disabled)
288306
) : (

template/src/components/precall/textInput.tsx

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import React from 'react';
14-
import {TextStyle} from 'react-native';
14+
import {TextStyle, Text} from 'react-native';
1515
import TextInput from '../../atoms/TextInput';
1616
import {useString} from '../../utils/useString';
1717
import {useRoomInfo} from '../room-info/useRoomInfo';
@@ -25,6 +25,7 @@ import {
2525
precallNameInputPlaceholderText,
2626
precallYouAreJoiningAsHeading,
2727
} from '../../language/default-labels/precallScreenLabels';
28+
import {usePreCall} from './usePreCall';
2829

2930
export interface PreCallTextInputProps {
3031
labelStyle?: TextStyle;
@@ -39,30 +40,52 @@ const PreCallTextInput = (props?: PreCallTextInputProps) => {
3940
const username = useGetName();
4041
const setUsername = useSetName();
4142
const {isJoinDataFetched, isInWaitingRoom} = useRoomInfo();
43+
const {isNameIsEmpty, setIsNameIsEmpty} = usePreCall();
4244
const {isDesktop = false, isOnPrecall = false} = props;
4345

4446
return (
45-
<Input
46-
maxLength={maxInputLimit}
47-
label={isOnPrecall ? '' : isDesktop ? joiningAs : ''}
48-
labelStyle={
49-
props?.labelStyle
50-
? props.labelStyle
51-
: {
52-
fontFamily: ThemeConfig.FontFamily.sansPro,
53-
fontWeight: '400',
54-
fontSize: ThemeConfig.FontSize.small,
55-
lineHeight: ThemeConfig.FontSize.small,
56-
color: $config.FONT_COLOR,
57-
}
58-
}
59-
value={username}
60-
autoFocus
61-
onChangeText={text => setUsername(text ? text : '')}
62-
onSubmitEditing={() => {}}
63-
placeholder={isJoinDataFetched ? placeHolder : fetchingNamePlaceholder}
64-
editable={!isInWaitingRoom && isJoinDataFetched}
65-
/>
47+
<>
48+
<Input
49+
maxLength={maxInputLimit}
50+
label={isOnPrecall ? '' : isDesktop ? joiningAs : ''}
51+
labelStyle={
52+
props?.labelStyle
53+
? props.labelStyle
54+
: {
55+
fontFamily: ThemeConfig.FontFamily.sansPro,
56+
fontWeight: '400',
57+
fontSize: ThemeConfig.FontSize.small,
58+
lineHeight: ThemeConfig.FontSize.small,
59+
color: $config.FONT_COLOR,
60+
}
61+
}
62+
value={username}
63+
autoFocus
64+
onChangeText={text => {
65+
setUsername(text ? text : '');
66+
if (text && text.trim() === '') {
67+
setIsNameIsEmpty(true);
68+
} else {
69+
setIsNameIsEmpty(false);
70+
}
71+
}}
72+
onSubmitEditing={() => {}}
73+
placeholder={isJoinDataFetched ? placeHolder : fetchingNamePlaceholder}
74+
editable={!isInWaitingRoom && isJoinDataFetched}
75+
style={isNameIsEmpty ? {borderColor: $config.SEMANTIC_ERROR} : {}}
76+
/>
77+
{isNameIsEmpty && (
78+
<Text
79+
style={{
80+
color: $config.SEMANTIC_ERROR,
81+
fontFamily: ThemeConfig.FontFamily.sansPro,
82+
marginTop: 4,
83+
marginLeft: 4,
84+
}}>
85+
{'Name is required'}
86+
</Text>
87+
)}
88+
</>
6689
);
6790
};
6891

template/src/components/precall/usePreCall.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface PreCallContextInterface {
2929
setSpeakerAvailable: React.Dispatch<React.SetStateAction<boolean>>;
3030
isPermissionRequested: boolean;
3131
setIsPermissionRequested: React.Dispatch<React.SetStateAction<boolean>>;
32+
isNameIsEmpty: boolean;
33+
setIsNameIsEmpty: React.Dispatch<React.SetStateAction<boolean>>;
3234
}
3335

3436
const PreCallContext = createContext<PreCallContextInterface>({
@@ -42,6 +44,8 @@ const PreCallContext = createContext<PreCallContextInterface>({
4244
setSpeakerAvailable: () => {},
4345
isPermissionRequested: false,
4446
setIsPermissionRequested: () => {},
47+
isNameIsEmpty: false,
48+
setIsNameIsEmpty: () => {},
4549
});
4650

4751
interface PreCallProviderProps {
@@ -54,6 +58,7 @@ const PreCallProvider = (props: PreCallProviderProps) => {
5458
const roomInfo = useRoomInfo();
5559
const {deviceList} = useContext(DeviceContext);
5660
const setUsername = useSetName();
61+
const [isNameIsEmpty, setIsNameIsEmpty] = useState(false);
5762
const [isCameraAvailable, setCameraAvailable] = useState(false);
5863
const [isMicAvailable, setMicAvailable] = useState(false);
5964
const [isSpeakerAvailable, setSpeakerAvailable] = useState(false);
@@ -69,6 +74,8 @@ const PreCallProvider = (props: PreCallProviderProps) => {
6974
setSpeakerAvailable,
7075
isPermissionRequested,
7176
setIsPermissionRequested,
77+
isNameIsEmpty,
78+
setIsNameIsEmpty,
7279
};
7380

7481
useEffect(() => {

0 commit comments

Comments
 (0)