Skip to content

Commit

Permalink
fix: add listenUserJoinOrLeave NMS-15612
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Sep 15, 2023
1 parent 979c69a commit 4029ab8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function JoinMultipleChannel() {
/**
* Step 1: initRtcEngine
*/
useInitRtcEngine(enableVideo);
useInitRtcEngine(enableVideo, false);

const [channelId2, setChannelId2] = useState<string>('');
const [token2] = useState<string>('');
Expand Down
18 changes: 13 additions & 5 deletions example/src/examples/hook/hooks/useInitRtcEngine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import Config from '../../../config/agora.config';
import * as log from '../../../utils/log';
import { askMediaAccess } from '../../../utils/permissions';

const useInitRtcEngine = (enableVideo: boolean) => {
const useInitRtcEngine = (
enableVideo: boolean,
listenUserJoinOrLeave: boolean = true
) => {
const [appId] = useState(Config.appId);
const [channelId, setChannelId] = useState(Config.channelId);
const [token] = useState(Config.token);
Expand Down Expand Up @@ -159,16 +162,20 @@ const useInitRtcEngine = (enableVideo: boolean) => {
engine.current.addListener('onError', onError);
engine.current.addListener('onJoinChannelSuccess', onJoinChannelSuccess);
engine.current.addListener('onLeaveChannel', onLeaveChannel);
engine.current.addListener('onUserJoined', onUserJoined);
engine.current.addListener('onUserOffline', onUserOffline);
if (listenUserJoinOrLeave) {
engine.current.addListener('onUserJoined', onUserJoined);
engine.current.addListener('onUserOffline', onUserOffline);
}

const engineCopy = engine.current;
return () => {
engineCopy.removeListener('onError', onError);
engineCopy.removeListener('onJoinChannelSuccess', onJoinChannelSuccess);
engineCopy.removeListener('onLeaveChannel', onLeaveChannel);
engineCopy.removeListener('onUserJoined', onUserJoined);
engineCopy.removeListener('onUserOffline', onUserOffline);
if (listenUserJoinOrLeave) {
engineCopy.removeListener('onUserJoined', onUserJoined);
engineCopy.removeListener('onUserOffline', onUserOffline);
}
};
}, [
engine,
Expand All @@ -178,6 +185,7 @@ const useInitRtcEngine = (enableVideo: boolean) => {
onLeaveChannel,
onUserJoined,
onUserOffline,
listenUserJoinOrLeave,
]);

return {
Expand Down

0 comments on commit 4029ab8

Please sign in to comment.