2014-02-06 16:44:24 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<head>
|
2014-02-07 17:25:20 +00:00
|
|
|
<script src="=WEBRTCAPIJS="> </script>
|
2014-02-06 16:44:24 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script>
|
|
|
|
var channel = 'msfsinn3rtest123';
|
|
|
|
var websocket = new WebSocket('ws://wsnodejs.jit.su:80');
|
|
|
|
|
|
|
|
websocket.onopen = function() {
|
|
|
|
websocket.push(JSON.stringify({
|
|
|
|
open: true,
|
|
|
|
channel: channel
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
websocket.push = websocket.send;
|
|
|
|
websocket.send = function(data) {
|
|
|
|
websocket.push(JSON.stringify({
|
|
|
|
data: data,
|
|
|
|
channel: channel
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
var peer = new PeerConnection(websocket);
|
|
|
|
|
|
|
|
peer.onStreamAdded = function(e) {
|
|
|
|
var video = e.mediaElement;
|
|
|
|
video.setAttribute('width', 600);
|
|
|
|
video.setAttribute('controls', true);
|
|
|
|
document.body.appendChild(video);
|
|
|
|
video.play();
|
|
|
|
};
|
|
|
|
|
|
|
|
peer.onStreamEnded = function(e) {
|
|
|
|
var video = e.mediaElement;
|
|
|
|
if (video) {
|
|
|
|
video.style.opacity = 0;
|
|
|
|
setTimeout(function() {
|
|
|
|
video.parentNode.removeChild(video);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
console.debug("onload");
|
|
|
|
getUserMedia(function(stream) {
|
|
|
|
peer.addStream(stream);
|
|
|
|
console.debug("broadcasting");
|
|
|
|
peer.startBroadcasting();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function getUserMedia(callback) {
|
|
|
|
var hints = {audio:true,video:{
|
|
|
|
optional: [],
|
|
|
|
mandatory: {
|
|
|
|
minWidth: 1280,
|
|
|
|
minHeight: 720,
|
|
|
|
maxWidth: 1920,
|
|
|
|
maxHeight: 1080,
|
|
|
|
minAspectRatio: 1.77
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
|
|
|
|
navigator.getUserMedia(hints,function(stream) {
|
|
|
|
var video = document.createElement('video');
|
|
|
|
video.src = URL.createObjectURL(stream);
|
|
|
|
video.controls = true;
|
2014-02-07 17:25:20 +00:00
|
|
|
video.muted = false;
|
2014-02-07 17:35:57 +00:00
|
|
|
video.volume = 0.2;
|
2014-02-06 16:44:24 +00:00
|
|
|
|
|
|
|
peer.onStreamAdded({
|
|
|
|
mediaElement: video,
|
|
|
|
userid: 'self',
|
|
|
|
stream: stream
|
|
|
|
});
|
|
|
|
|
|
|
|
callback(stream);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|