Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using the simple-peer and socket.io libraries in a react project, to transmit a video stream and display it to all connected devices in a websocket room, I can receive the stream on the other devices when the stream starts but it does not show in the video

if i print the stream value in the receptorPeer event (useEffect) it normally returns the stream
I tried to update the video using the stream directly from the `.then` of getUserMedia and it works normally (but it only displays the video for the user who started the camera, obviously), being that it's the same value, the same stream

What I have tried:

front-end

// when the user starts a transmission this is executed

const initiatorPeer = new SimplePeer({
  initiator: true,
  stream
})

initiatorPeer.on('signal', (data) => {
  socket.emit('stream', data)
})

// here it identifies when a stream is started and in theory it was to change the video

useEffect(() => {
  const receptorPeer = new SimplePeer()

  socket.on('stream', (data) => {
    receptorPeer.signal(data)
  })

  receptorPeer.on('stream', stream => {
    console.log(stream) //returns stream normally
    videoRef.current!.srcObject = stream
  })
}, [])


back-end

socket.on('stream', data => {
  server.io.to('meet').emit('stream', data)
})
Posted
Updated 13-Feb-23 11:22am
v7

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900