Establishing peer-to-peer streams
When the setup_video()
function is called, and the stream is set up successfully, then it is added to peer_connection
using the peer_connection.addStream(local_stream)
call. This is then ready to be sent to the remote peer automatically once the full RTCPeerConnection is set up successfully.
// setup stream from the local camera function setup_video() { get_user_media( { "audio": true, // request access to local microphone "video": true // request access to local camera }, function (local_stream) { // success callback ... // add local stream to peer_connection ready to be sent to the remote peer peer_connection.addStream(local_stream); }, log_error // error callback ); }
Once the stream from the remote peer is received, then the peer_connection.onaddstream
handler is called. This uses the connect_stream_to_src()
method defined in the webrtc_polyfill.js
code to display the stream in the <video>
media...