-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera Preview is not opening and showing empty white screen #848
Comments
@SuyashAmeta You should call enableVideo before call startPreview |
@guoxianzhe Its still not showing the camera preview in host and just displaying the empty white screen but in audience my photo is showing. |
@SuyashAmeta Did you render your local view with RtcSurfaceView? |
@guoxianzhe I have added the below code for local view with RtcSurfaceView agoraEngineRef.current.setupLocalVideo({ |
@SuyashAmeta make a state that tracks whether the host has joined the channel successfully. Then render the RtcSurfaceView when this state is set to true. 1.) Make a state 2.) Set it to true once the channel is joined successfully. 3.) Use this state to render RtcSurfaceView. These changes will fix your issue. |
When I am using the App ID, channel name, token and UID but agora is not opening the camera preview when joined as a host.
import React,{ useEffect, useState, useRef } from "react";
import { useNavigation } from '@react-navigation/native'
import {
View,
Text,
TextInput,
FlatList,
TouchableOpacity,
PermissionsAndroid,
Platform } from 'react-native';
import Icon from "react-native-vector-icons/Ionicons";
import {
createAgoraRtcEngine,
ChannelProfileType,
ClientRoleType,
IRtcEngine,
RtcSurfaceView,
RtcConnection,
IRtcEngineEventHandler,
} from 'react-native-agora';
import { Ionicons } from '@expo/vector-icons';
import Gift from "../../shared/assets/images/icons/gift.svg"
import More from "../../shared/assets/images/icons/more.svg"
import ChatBubble from "../../shared/assets/images/icons/chatbubble.svg"
import People from "../../shared/assets/images/icons/people.svg"
import Polls from "../../shared/assets/images/icons/polls.svg"
import QA from "../../shared/assets/images/icons/qa.svg"
import OpinionBottomSheet from "./opinions";
import GiftsBottomSheet from "./gifts";
import { liveStreamStyles } from "./style";
const appId = '*******************************';
const getPermission = async () => {
if (Platform.OS === 'android') {
await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
PermissionsAndroid.PERMISSIONS.CAMERA,
]);
}
}
export default function LiveStreamScreen() {
const token = '*********';
const channelName = ';
const uid = **************;
const navigation = useNavigation()
const agoraEngineRef = useRef();
const eventHandler = useRef();
const [remoteUid, setRemoteUid] = useState(null);
const giftBottomSheetRef = useRef(null);
const opinionBottomSheetRef = useRef(null);
const [chatMessages, setChatMessages] = useState([
{ id: "1", name: "Ravi Ranjan", message: "When is the movie releasing?" },
{ id: "2", name: "Isha Singh", message: "Your hair is so curly and shiny!!!!!" },
{ id: "3", name: "Isha Singh", message: "Sent a gift 🌹" },
]);
//Handle Gift button press
const handleGiftButtonPress = () => {
if(giftBottomSheetRef.current){
giftBottomSheetRef.current.expand();
}
};
//Handle More button press
const handleMoreButtonPress = () => { };
//Handle QA button press
const handleQAButtonPress = () => { };
//Handle People button press
const handlePeopleButtonPress = () => { };
//Handle ChatBubble button press
const handleChatBubbleButtonPress = () => { };
//Handle Polls button press
const handlePollsButtonPress = () => {
if(opinionBottomSheetRef.current){
opinionBottomSheetRef.current.expand();
}
};
useEffect(() => {
(async function init() {
await getPermission();
})();
}, []);
useEffect(() => {
agoraEngineRef.current = createAgoraRtcEngine();
const agoraEngine = agoraEngineRef.current;
agoraEngine.initialize({appId});
agoraEngineRef.current?.startPreview();
agoraEngine.enableVideo();
});
eventHandler.current = {
onJoinChannelSuccess: () => {
console.log('Successfully joined channel: ' + channelName);
//setIsJoined(true);
},
onUserJoined: (_connection, uid) => {
console.log('Remote user ' + uid + ' has joined', _connection);
setRemoteUid(uid)
//setRemoteUid(uid);
},
onUserOffline: (_connection, uid) => {
console.log('Remote user ' + uid + ' has left the channel', _connection);
navigation.goBack();
//setRemoteUid(0);
},
onError: (err, msg) => {
console.log("error occured", err, msg)
}
};
agoraEngine.registerEventHandler(eventHandler.current);
}, [])
return (
{remoteUid && <RtcSurfaceView
canvas={{
uid: remoteUid
}}
/>}
{/* Chat Messages /}
<FlatList
data={chatMessages}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
{item.name}
{item.message}
)}
style={liveStreamStyles.chatList}/>
{/ Action Buttons /}
{/ Comment Input /}
<TextInput
style={liveStreamStyles.commentInput}
placeholder="Type comments here..."
placeholderTextColor="#ccc"
onSubmitEditing={(event) => handleSendComment(event.nativeEvent.text)}
/>
{/ Announcement */}
Announcement
New Q/A has been added by the actor, go and add your poll.
);
}
The text was updated successfully, but these errors were encountered: