Repository navigation
Expand file tree
/
Copy pathclient.js
More file actions
105 lines (84 loc) · 3.01 KB
/
Copy pathclient.js
File metadata and controls
105 lines (84 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
if (Modernizr.getusermedia) {
var yourVideo = document.querySelector('#yours');
var theirVideo = document.querySelector('#theirs');
navigator.getUserMedia = navigator.getUserMedia || navigator.webKitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getUserMedia({ video: true, audio: false }, function (stream) {
yourVideo.src = window.URL.createObjectURL(stream);
if (Modernizr.peerconnection) {
startPeerConnection(stream);
} else {
console.log('No peer connection support');
}
}, function (error) {
console.log(error);
});
} else {
console.log('No user media support');
}
function startPeerConnection(stream) {
var configuration = {
// 'iceServers': [{ 'url': 'stun:stun.1.google.com:19302'}]
};
console.log(stream);
console.log("\n");
console.log("\n");
window.RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection ||
window.mozRTCPeerConnection;
var yourConnection = new RTCPeerConnection(configuration);
var theirConnection = new RTCPeerConnection(configuration);
console.log('yourConnection: ');
console.log(yourConnection);
console.log("\n");
console.log("\n");
console.log('theirConnection: ');
console.log(theirConnection);
console.log("\n");
console.log("\n");
yourConnection.addStream(stream);
theirConnection.onaddstream = function(e) {
console.log('onaddstream: ')
console.log(e);
console.log("\n");
console.log("\n");
theirVideo.src = window.URL.createObjectURL(e.stream);
};
yourConnection.onicecandidate = function (event) {
console.log('your onicecandidate: ');
console.log(event);
console.log("\n");
console.log("\n");
if (event.candidate) {
theirConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
}
};
theirConnection.onicecandidate = function (event) {
console.log('their onicecandidate:');
console.log(event);
console.log("\n");
console.log("\n");
if (event.candidate) {
yourConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
}
}
yourConnection.createOffer(function (offer) {
console.log('your offer: ');
console.log(offer);
console.log("\n");
console.log("\n");
yourConnection.setLocalDescription(offer);
theirConnection.setRemoteDescription(offer);
theirConnection.createAnswer(function (offer) {
console.log('their offer: ');
console.log(offer);
console.log("\n");
console.log("\n");
theirConnection.setLocalDescription(offer);
yourConnection.setRemoteDescription(offer);
}, function (error) {
console.log(error);
});
}, function (error) {
console.log(error);
});
}