WebRTC video streaming is working in firefox but not in chrome

前端 未结 1 655
醉话见心
醉话见心 2020-12-22 08:49

I am making a simple video-calling app using webRTC. Everything is working as expected in firefox. But in chrome and opera the remote-stream is not showing up on any side(ca

相关标签:
1条回答
  • 2020-12-22 09:07

    Try to request user media before creating peer connection:

    useEffect(() => {
      const getUserMedia = async () => {
          const mediaConstraints = {
            video: true,
            audio: true,
          };
    
          try {
            const stream = await navigator.mediaDevices.getUserMedia(
              mediaConstraints,
            );
    
            localVideo.current.srcObject = stream;
          } catch (error) {
            console.error(error);
          }
        };
    
        getUserMedia();
      }, []);
    

    Also, the onnegotiationneeded event fires twice in the your code (on caller and callee side). You should create offer only on the caller side.

    https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onnegotiationneeded

    0 讨论(0)
提交回复
热议问题