-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
92 lines (76 loc) · 2.29 KB
/
app.js
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
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function gotStream(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"); };
}
function getUserMediaError() {
console.log("getUserMedia() failed.");
}
function onAccessApproved(id) {
if (!id) {
console.log("Access rejected.");
return;
}
navigator.webkitGetUserMedia({
audio:false,
video: {
mandatory: {
chromeMediaSource: "desktop",
chromeMediaSourceId: id,
googLeakyBucket: true,
maxWidth: window.screen.width,
maxHeight: window.screen.height,
maxFrameRate: 60
}
},
}, gotStream, getUserMediaError);
}
var pending_request_id = null;
document.querySelector('#start').addEventListener('click', function(e) {
pending_request_id = chrome.desktopCapture.chooseDesktopMedia(
["window"], onAccessApproved);
});
document.querySelector('#cancel').addEventListener('click', function(e) {
if (pending_request_id != null) {
chrome.desktopCapture.cancelChooseDesktopMedia(pending_request_id);
}
});
function init() {
if (typeof Peer == 'function') {
// PeerJS object
var peer = new Peer({ key: 'lwjd5qra8257b9', debug: 3});
peer.on('open', function(){
console.log("My ID - ", peer.id);
});
peer.on('error', function(err){
consoel.log("ERROR: ", err.message);
});
function makeCall() {
var id = document.getElementById("their-id").value;
var call = peer.call(id, window.localStream);
step3(call);
};
function callEnded() {
console.log("call ended");
};
function step3 (call) {
// Hang up on an existing call if present
// if (window.existingCall) {
// window.existingCall.close();
// }
// UI stuff
window.existingCall = call;
call.on('close', callEnded);
};
var callButton = document.getElementById("call");
callButton.addEventListener('click', makeCall);
} else {
setTimeout(init, 100);
}
};
init();