mediaStreamTracks
即使roomState
更改为连接后,我也无法获取本地和远程参与者的信息。但是,我注意到它们在重新连接后变得可用。请告知我在连接到房间后如何访问mediaStreamTracks
本地和远程参与者。
要重现该错误,请尝试在此repo的 Room 组件中使用以下代码。
// Below function is from room component of this repo
import useRoomState from '../../hooks/useRoomState/useRoomState';
import useVideoContext from '../useVideoContext/useVideoContext';
export default function Room() {
const { room } = useVideoContext();
const {
room: { localParticipant },
} = useVideoContext();
const [participants, setParticipants] = useState(Array.from(room.participants.values()));
const roomState = useRoomState();
useEffect(() => {
if(roomState === 'connected'){
localParticipant.tracks.forEach(track => {
if (track.kind === 'data' ) {
return;
}
console.log(track.mediaStreamTrack) // Getting undefined!!
}
participants.forEach(participant => {
participant.tracks.forEach(track => {
if (track.kind === 'data') {
return;
}
console.log(track.mediaStreamTrack) // Getting undefined!!
}
}
}, [roomState]);
}