forked from gsathya/screen-share
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreciever.js
More file actions
39 lines (32 loc) · 1.05 KB
/
reciever.js
File metadata and controls
39 lines (32 loc) · 1.05 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
var peer = new Peer({ key: 'lwjd5qra8257b9', debug: 3, config: {'iceServers': [
{ url: 'stun:stun.l.google.com:19302' } // Pass in optional STUN and TURN server for maximum network compatibility
]}});
peer.on('open', function(){
document.getElementById("my-peer-id").innerHTML = peer.id;
});
// Receiving a call
peer.on('call', function(call){
// Answer the call automatically (instead of prompting user) for demo purposes
call.answer();
answerCall(call);
});
function endCall(){
console.log("Call ended");
}
function answerCall(call) {
// Hang up on an existing call if present
if (window.existingCall) {
window.existingCall.close();
}
// Wait for stream on the call, then set peer video display
call.on('stream', function(stream){
console.log("Received local stream");
var video = document.querySelector("video");
video.src = URL.createObjectURL(stream);
window.localstream = stream;
stream.onended = function() { console.log("Ended"); };
});
// UI stuff
window.existingCall = call;
call.on('close', endCall);
}