<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
οnlοad=
"loadVideo()"
>
<video
autoplay
id=
"video"
/>
<video
autoplay
id=
"video2"
/>
</body>
</html>