var constraints = {video: true}; function successCallback(stream) { var video = document.querySelector("video"); video.src = window.URL.createObjectURL(stream); } function errorCallback(error) { console.log("navigator.getUserMedia error: ", error); } navigator.getUserMedia(constraints, successCallback, errorCallback);
{ "mandatory": { "width": { "min": 480 } }, "optional": [ { "width": { "min": 720 } }, { "frameRate": 60 }, { "facingMode": "user" } ] }
var constraints = { video: { mandatory: { chromeMediaSource: 'screen' } } }; navigator.webkitGetUserMedia(constraints, gotStream);
pc = new RTCPeerConnection(configuration); pc.onaddstream = gotRemoteStream; pc.addStream(localStream); // from getUserMedia pc.createOffer(gotOffer); function gotOffer(desc) { pc.setLocalDescription(desc); sendOffer(desc); } function gotAnswer(desc) { pc.setRemoteDescription(desc); } function gotRemoteStream(e) { attachMediaStream(remoteVideo, e.stream); }
pc = new RTCPeerConnection(configuration); pc.ondatachannel = function (event) { receiveChannel = event.channel; receiveChannel.onmessage = function (event) { document.querySelector("div#receive").innerHTML = event.data; }; }; sendChannel = pc.createDataChannel("sendDataChannel", {reliable: false}); document.querySelector("button#send").onclick = function () { var data = document.querySelector("textarea#send").value; sendChannel.send(data); };
pc.createOffer(gotOffer); function gotOffer(desc) { pc.setLocalDescription(desc); sendOffer(desc); } function gotAnswer(desc) { pc.setRemoteDescription(desc); }
pc = new RTCPeerConnection(configuration);
pc = new RTCPeerConnection(configuration); pc.createOffer(gotOffer)
pc = new RTCPeerConnection(configuration); pc.createOffer(gotOffer) function gotOffer(description) { pc.setLocalDescription(description); sendOffer(description); }
function gotOffer(description) { pc.setLocalDescription(description); sendOffer(description); } pc.onicecandidate = function (event) { sendCandidate(event.candidate); }
function gotAnswer(desc) { pc.setRemoteDescription(desc); }
pc.onicecandidate = function (event) { sendCandidate(event.candidate); }
function gotIceCandidate (message) { pc.addIceCandidate(new RTCIceCandidate({ sdpMLineIndex: message.label, candidate: message.candidate })); }
var webrtc = new WebRTC({ localVideoEl: 'localVideo', remoteVideosEl: 'remoteVideos', autoRequestMedia: true }); webrtc.on('readyToCall', function () { webrtc.joinRoom('My room name'); });
var peer = new Peer('someid'); peer.on('connection', function(conn) { conn.on('data', function(data){ // Will print 'hi!' console.log(data); }); }); // Connecting peer var peer = new Peer('anotherid'); var conn = peer.connect('someid'); conn.on('open', function(){ conn.send('hi!'); });