0

My aim is connecting webrtc peers and sharing their video, but I'm not able to connect peers in the below code.

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');
});

I know this will not work so how can I connect peers with id? Please help me in this problem.

rmlockerd
  • 3,776
  • 2
  • 15
  • 25
titan
  • 45
  • 6

1 Answers1

1

The first example in the PeerJS API documentation shows how to connect two peers. I would recommend you start there; if you get stuck again, don't hesitate to update your question and I'll try assist you further.

I would have written this in a comment, but I don't have enough reputation.

Henrik Klev
  • 322
  • 1
  • 11