我的目标是连接webrtc
同行并分享他们的视频,但我无法在下面的代码中连接同行。
const [stream, setstream] = useState();
const myVideo = useRef();
const userVideo = useRef();
useEffect(() => {
navigator.mediaDevices
.getUserMedia({ video: true, audio: true })
.then((currentStream) => {
myVideo.current.srcObject = currentStream;
setstream(currentStream);
});
}, []);
var peer1 = new Peer({ initiator: true, stream: stream, wrtc: wrtc });
var peer2 = new Peer({ wrtc: wrtc });
peer1.on('signal', (data) => {
peer2.signal(data);
});
peer2.on('stream', (stream) => {
console.log('connected');
});
我知道这行不通,那么我该如何连接对等点id
呢?请帮我解决这个问题。