• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3<head><title>Loopback test</title></head>
4<body>
5  <video id="remoteVideo" width="1280" height="720" autoplay muted></video>
6<script>
7var localStream, localPeerConnection, remotePeerConnection;
8var remoteVideo = document.getElementById("remoteVideo");
9
10function start() {
11  navigator.getUserMedia = navigator.getUserMedia ||
12    navigator.webkitGetUserMedia;
13  navigator.getUserMedia(
14    {
15      audio:false,
16      video:{
17        "mandatory": {
18          "minWidth": "1280",
19          "minHeight": "720",
20        }
21      }
22    },
23    gotLocalStream,
24    gotError);
25}
26
27function gotLocalStream(stream) {
28  localStream = stream;
29  var servers = null;
30
31  localPeerConnection = new webkitRTCPeerConnection(servers);
32  localPeerConnection.onicecandidate = gotLocalIceCandidate;
33
34  remotePeerConnection = new webkitRTCPeerConnection(servers);
35  remotePeerConnection.onicecandidate = gotRemoteIceCandidate;
36  remotePeerConnection.onaddstream = gotRemoteStream;
37
38  localPeerConnection.addStream(localStream);
39  localPeerConnection.createOffer(gotLocalDescription, function(error) {});
40}
41
42function gotError(error) {
43  console.log("navigator.getUserMedia error: ", error);
44}
45
46function gotRemoteStream(event) {
47  remoteVideo.srcObject = event.stream;
48}
49
50function gotLocalDescription(description) {
51  localPeerConnection.setLocalDescription(description);
52  remotePeerConnection.setRemoteDescription(description);
53  remotePeerConnection.createAnswer(gotRemoteDescription, function(error) {});
54}
55
56function gotRemoteDescription(description) {
57  remotePeerConnection.setLocalDescription(description);
58  localPeerConnection.setRemoteDescription(description);
59}
60
61function gotLocalIceCandidate(event) {
62  if (event.candidate)
63    remotePeerConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
64}
65
66function gotRemoteIceCandidate(event) {
67  if (event.candidate)
68    localPeerConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
69}
70
71window.onload=start;
72</script>
73</body>
74</html>
75