On Github Snesi / webRTCPresentation
Created by David G. Shannon / @davidgshannon
WIFI:
HTTPS
Three APIs that allow p2p browser communication
navigator.getUserMedia()
// Mr. Browser: Qué quieres captar? var constraints = {video: true}; // Mr. Browser: Qué hago una vez te lo dé? function successCallback(stream) { var video = document.querySelector("video"); video.src = window.URL.createObjectURL(stream); } // Mr. Browser: Qué hago si no puedo dartelo? function errorCallback(error) { console.log("navigator.getUserMedia error: ", error); } // Mr. Browser: Pídeme lo que quieres amorsito navigator.getUserMedia(constraints, successCallback, errorCallback);
// Success callback when requesting audio input stream function gotStream(stream) { var audioContext = new AudioContext(); // Create an AudioNode from the stream var mediaStreamSource = audioContext.createMediaStreamSource(stream); // Connect it to the destination or any other node for processing! mediaStreamSource.connect(audioContext.destination); } navigator.getUserMedia({audio:true}, gotStream);
pc = new RTCPeerConnection(null); pc.onaddstream = gotRemoteStream; pc.addStream(localStream); pc.createOffer(gotOffer); function gotOffer(desc) { pc.setLocalDescription(desc); sendOffer(desc); } function gotAnswer(desc) { pc.setRemoteDescription(desc); } function gotRemoteStream(e) { attachMediaStream(remoteVideo, e.stream); }