
WebRTC is a new front in the long war for an open and unencumbered web
navigator.getUserMedia()
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);
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);
audioCapture
and videoCapture
permissions// Success callback when requesting audio input stream function gotStream(stream) { var audioContext = new webkitAudioContext(); // 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.webkitGetUserMedia( {audio:true}, gotStream);
Make sure to enable Web Audio Input in about:flags!
Be sure to enable screen capture support in getUserMedia!
var constraints = { video: { mandatory: { chromeMediaSource: 'screen' } } }; navigator.webkitGetUserMedia(constraints, gotStream);
v=0 o=- 7614219274584779017 2 IN IP4 127.0.0.1 s=- t=0 0 a=group:BUNDLE audio video a=msid-semantic: WMS m=audio 1 RTP/SAVPF 111 103 104 0 8 107 106 105 13 126 c=IN IP4 0.0.0.0 a=rtcp:1 IN IP4 0.0.0.0 a=ice-ufrag:W2TGCZw2NZHuwlnf a=ice-pwd:xdQEccP40E+P0L5qTyzDgfmW ...
Want to know what all this SDP gobbledygook actually means?
Take a look at the IETF examples.
{ 'type':'candidate', 'label':1, 'id':'video', 'candidate':'a=candidate:1274936569 1 udp 1845501695 2.96.35.15 63579 typ srflx raddr 192.168.0.3 rport 63579 generation 0\r\n' } ... { 'type':'candidate', 'label':0, 'id':'audio', 'candidate':'a=candidate:3802297132 1 udp 2113937151 192.168.0.3 63579 typ host generation 0\r\n' }
var pc = new webkitRTCPeerConnection(servers, {optional: [{RtpDataChannels: true}]}); 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); };
Voice is just another JS application
Lets you use the same code in all browsers:
WebRTC and HTML5 could enable the same transformation for real-time communications that the original browser did for information.