Created
April 26, 2012 12:52
-
-
Save makevoid/2499357 to your computer and use it in GitHub Desktop.
usermedia and webrtc chrome test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script type="text/javascript"> | |
| function onFailSoHard() { | |
| console.log("fail") | |
| } | |
| function sendSignalingChannel(message) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('POST', path, true); | |
| xhr.send(message); | |
| } | |
| function receiveSignalingChannel (message) { | |
| // call this whenever we get a message on the signaling channel | |
| peer_connection.signalingChannel(message); | |
| } | |
| function loadVideo() { | |
| navigator.webkitGetUserMedia('video', function(stream) { | |
| var video = document.getElementById("video") | |
| video.src = window.webkitURL.createObjectURL(stream) | |
| peer_connection.sendStream(stream) | |
| peer_connection.addStream(stream); | |
| peer_connection.onaddstream = function (event) { | |
| // (videoElement is some <video> element) | |
| document.getElementById("video2").src = URL.createObjectURL(event.stream); | |
| }; | |
| }, onFailSoHard) | |
| } | |
| // webkitPeerConnection -> Chrome | |
| // webkitDeprecatedPeerConnection -> Canary | |
| var peer_connection = new webkitDeprecatedPeerConnection('STUN localhost:3000', sendSignalingChannel); | |
| window.peer_connection = peer_connection | |
| </script> | |
| <style> | |
| video { | |
| width: 300px; | |
| height: 300px; | |
| } | |
| </style> | |
| </head> | |
| <body onload="loadVideo()"> | |
| <video autoplay id="video" /> | |
| <video autoplay id="video2" /> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment