-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
100 lines (90 loc) · 3.16 KB
/
index.html
File metadata and controls
100 lines (90 loc) · 3.16 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
<head>
<title>TobyCall</title>
<script src="https://cdn.jsdelivr.net/npm/peerjs@0.3.20/dist/peer.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1 class="judul">Welcome to TobyCall</h1>
<div>
<div class="dot"></span>
<h2 class="status">Not Connected</h2>
</div>
<h3 class="idDisplay"></h3>
<button class="connectButton">Connect to Peer</button>
</body>
<script>
//Handle browser prefixes
navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
var localStream = null;
// Get access to microphone
navigator.getUserMedia (
{video: false, audio: true},
// Success callback
function success(localAudioStream) {
localStream = localAudioStream
console.log(localStream)
// playStream(localStream)
},
// Failure callback
function error(err) {
console.log(err)
alert("Audio input device error. Please refresh the website.")
}
)
var me = new Peer({
config: {'iceServers': [
{ url: 'stun:stun.l.google.com:19302' },
{ url: 'turn:165.22.105.219:65432', username: 'peerjs', credential: 'h2olo2' }
]}
}); //use default PeerJS cloud
me.on('open', function() {
console.log('My PeerJS ID is:', me.id);
$(".idDisplay")[0].innerHTML = me.id;
$(".status")[0].innerHTML = "Awaiting Connection"
$(".dot")[0].style.backgroundColor = 'gold'
});
var conn = null;
function connect(connId){
console.log("connecting to id ",connId)
conn = me.call(connId, localStream);
console.log("outgoing stream ",conn)
conn.on('stream', function(stream) {
playStream(stream)
$(".status")[0].innerHTML = "Connected to Peer"
$(".dot")[0].style.backgroundColor = 'aquamarine'
});
conn.on('close',()=>{
$(".status")[0].innerHTML = "Awaiting Connection"
$(".dot")[0].style.backgroundColor = 'gold'
})
}
$(".connectButton").click(
()=>{
var connId = prompt("Enter partner ID")
connect(connId)
}
)
me.on('call', function(incoming) {
alert("ada yang call lu")
conn = incoming
conn.answer(localStream)
console.log("incoming stream ",conn)
conn.on('stream', function(stream) {
playStream(stream)
});
conn.on('close',()=>{
$(".status")[0].innerHTML = "Awaiting Connection"
$(".dot")[0].style.backgroundColor = 'gold'
})
$(".status")[0].innerHTML = "Connected to Peer"
$(".dot")[0].style.backgroundColor = 'aquamarine'
});
function playStream(stream) {
console.log("play stream")
var audio = $('<audio autoplay />').appendTo('body');
console.log("created")
//audio[0].src = (URL || webkitURL || mozURL).createObjectURL(stream);
audio[0].srcObject = stream;
}
</script>