Closed Nirav-12 closed 1 year ago
could you pls provide your API call list?
this is code for host to join i am getting token from backend also if you need full code then please give your mail i will provide full code
const setupVideoSDKEngine = async () => {
if (Platform.OS === 'android') {
await getPermission();
}
try {
agoraEngineRef.current = createAgoraRtcEngine();
const agoraEngine = agoraEngineRef.current;
agoraEngine.registerEventHandler({
onJoinChannelSuccess: () => {
console.log('Host Successfully joined the channel ');
setIsJoined(true);
},
onUserOffline: (_connection, Uid) => {
console.log('Remote user left the channel. uid: host', Uid);
},
});
agoraEngine.initialize({
appId: appId,
channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting,
});
agoraEngine.setAudioScenario(AudioScenarioType.AudioScenarioChatroom);
agoraEngine.enableAudio();
agoraEngine.enableAudioVolumeIndication(500, 3, true);
agoraEngine.muteAllRemoteAudioStreams(false);
} catch (e) {
console.log(e);
}
};
const join = async (token, channelName) => {
console.log('join ============>>>>>>>>>>>>>>');
if (isJoined) {
return;
}
try {
agoraEngineRef.current?.setChannelProfile(
ChannelProfileType.ChannelProfileLiveBroadcasting,
);
agoraEngineRef.current?.startPreview();
agoraEngineRef.current?.joinChannel(token, channelName, Number(UserId), {
clientRoleType: ClientRoleType.ClientRoleBroadcaster,
});
setLoader(false);
} catch (e) {
console.log(e);
}
};
this is for listener side code
const setupVideoSDKEngine = async () => {
if (Platform.OS === 'android') {
await getPermission();
}
try {
agoraEngineRef.current = createAgoraRtcEngine();
const agoraEngine = agoraEngineRef.current;
agoraEngine.registerEventHandler({
onJoinChannelSuccess: (connection, elapsed) => {
console.log('onJoinChannelSuccess =============>>>>>>>>', connection);
setIsJoined(true);
},
onUserOffline: (_connection, Uid) => {
console.log('onUserOffline =========>>>>>>', _connection, Uid);
if (Uid === host_id) {
leave();
}
},
onClientRoleChanged: (connection, oldRole, newRole, newRoleOptions) => {
console.log(
'onClientRoleChanged =============>>>>>>>>',
connection,
oldRole,
newRole,
newRoleOptions,
);
},
});
agoraEngine.initialize({
appId: appId,
channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting,
});
agoraEngine.setAudioScenario(AudioScenarioType.AudioScenarioChatroom);
agoraEngine.enableAudioVolumeIndication(500, 3, true);
getTocken();
} catch (e) {
console.log(e);
}
};
////////////////
const join = async () => {
try {
agoraEngineRef.current?.setChannelProfile(
ChannelProfileType.ChannelProfileLiveBroadcasting,
);
var channeloptions = new ChannelMediaOptions();
channeloptions.audienceLatencyLevel =
AudienceLatencyLevelType.AudienceLatencyLevelLowLatency;
agoraEngineRef.current?.updateChannelMediaOptions(channeloptions);
agoraEngineRef.current?.joinChannel(
tocken,
channel_name,
Number(UserId),
{
clientRoleType: ClientRoleType.ClientRoleAudience,
},
);
} catch (e) {
console.log('error ============>>>>>>>>>join', e);
}
};
///////////////
const makeSpeaker = async () => {
const tockenVal = await getRenewTocken(1);
console.log('tockenVal----------------->>>>>>>>', tockenVal);
agoraEngineRef.current?.renewToken(tockenVal);
console.log('MAKE SPEAKER PRESSED');
agoraEngineRef.current?.setClientRole(ClientRoleType.ClientRoleBroadcaster);
agoraEngineRef.current?.enableAudio();
setAudio(true);
setIsSpeaker(true);
};
const makeAudience = async () => {
const tockenVal = await getRenewTocken(2);
console.log('tockenVal----------------->>>>>>>>', tockenVal);
agoraEngineRef.current?.renewToken(tockenVal);
agoraEngineRef.current?.setClientRole(ClientRoleType.ClientRoleAudience);
setAudio(false);
setIsSpeaker(false);
};``
is it working using updateChannelMediaOptions to change the client role?
btw, which version of our SDK you are using?
Thank you for your support and time @LichKing-2234 actually problem is was my side as
agoraEngineRef.current?.disableAudio();
agoraEngineRef.current?.enableAudio();
i was using this method to mute and unmute host which was the problem as solution to this i have started using below method
agoraEngineRef.current?.enableLocalAudio(false);
agoraEngineRef.current?.enableLocalAudio(true);
Whole scenario goes as follow
(Host) create channel as Channel Profile as LiveBroadcasting and join using Client Role Broadcaster.
(A)user join same channel created by Host with Client Role Audience.
(B)user join same channel created by Host with Client Role Audience.
when (A)user change role from Client Role Audience to Client Role Broadcaster and then enabling audio. NOW (B) user is able to listen but Initial Broadcaster(Host) is not able to listen to (A)user.