In my experience, what Konga Raju advised didn't work. I couldn't send an "updated offer" and have the video streaming actually happen.
I found that this sequence of events works for my case, in which I wish to stream video from peer 1 to peer 2.
- set up some way for the peers to exchange messages. (The variance in how people accomplish this is what makes different WebRTC code samples so incommensurable, sadly.)
- On each side, set up handlers for the important signalling events. (Some folks have reported that you need to create these handlers at special times, but I haven't found that to be the case.
) There are 3 basic events:
- an ice candidate sent from the other side ==> call
addIceCandidate with it
- an offer message ==>
SetRemoteDescription & make an answer & send it
- an answer message ===>
SetRemoteDescription
- On each side, create the peerconnection object with the event handlers we care about: onicecandidate, onremovestream, onaddstream, etc.
- ice candidate pops out of the peerconnection object ===> send it to other side
- When both peers are present and all the handlers are in place, peer 1 gets a trigger message of some kind to start video capture (the
getUserMedia call)
- Once
getUserMedia succeeds, we have a stream. Call addStream on the peer connection object.
- Then peer 1 makes an offer
- Due to the handlers we set up earlier, peer 2 sends an answer
- Concurrently with this (and rather opaquely), the peer connection object starts producing ice candidates. They get sent back and forth between the two peers and handled (steps 2 & 3 above)
- Streaming starts by itself, opaquely, as a result of 2 conditions:
- offer/answer exchange
- ice candidates received, exchanged, and handled
I haven't found a way to add video after step 9. When I want to change something, I go back to step 3.