-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
99 lines (91 loc) · 3.15 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Peer</title>
<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>
</head>
<body>
<h1>Консультант</h1>
<p>
<h3>ID: <span id="myid"></span></h3>
</p>
<input id="otherPeerId" type="text" placeholder="otherPeerId">
<button id="btn-call">Вызов</button>
<br>
<video id=myVideo muted="muted" width="400px" height="auto" autoplay style="display: none;" controls></video>
<div id=callinfo></div>
<video id=remVideo width="400px" height="auto" autoplay controls style="display: none;"></video>
<script>
var callOptions = {
'iceServers': [
{ url: 'stun:stun01.sipphone.com' },
{ url: 'stun:stun.ekiga.net' },
{ url: 'stun:stun.fwdnet.net' },
{ url: 'stun:stun.ideasip.com' },
{ url: 'stun:stun.iptel.org' },
{ url: 'stun:stun.rixtelecom.se' },
{ url: 'stun:stun.schlund.de' },
{ url: 'stun:stun.l.google.com:19302' },
{ url: 'stun:stun1.l.google.com:19302' },
{ url: 'stun:stun2.l.google.com:19302' },
{ url: 'stun:stun3.l.google.com:19302' },
{ url: 'stun:stun4.l.google.com:19302' },
{ url: 'stun:stunserver.org' },
{ url: 'stun:stun.softjoys.com' },
{ url: 'stun:stun.voiparound.com' },
{ url: 'stun:stun.voipbuster.com' },
{ url: 'stun:stun.voipstunt.com' },
{ url: 'stun:stun.voxgratia.org' },
{ url: 'stun:stun.xten.com' },
{
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]'
},
{
url: 'turn:192.158.29.39:3478?transport=udp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
},
{
url: 'turn:192.158.29.39:3478?transport=tcp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
}
]
};
var peer = new Peer({ config: callOptions });
peer.on('open', function (peerID) {
document.getElementById('myid').innerHTML = peerID;
});
var peercall;
peer.on('call', function (call) {
peercall = call;
peercall.answer();
setTimeout(function () {
var video = document.getElementById('remVideo');
video.srcObject = peercall.remoteStream;
video.onloadedmetadata = function (e) {
video.play();
video.style.display = 'block';
};
}, 1500);
});
document.getElementById('btn-call').addEventListener('click', function callToNode() {
var peerId = document.getElementById('otherPeerId').value;
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then(function (mediaStream) {
var video = document.getElementById('myVideo');
peercall = peer.call(peerId, mediaStream);
video.srcObject = mediaStream;
video.onloadedmetadata = function (e) {
video.play();
video.style.display = 'block';
};
}).catch(function (err) {
console.log(err.name + ": " + err.message);
});
});
</script>
</body>