-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground-script.js
More file actions
30 lines (25 loc) · 1 KB
/
background-script.js
File metadata and controls
30 lines (25 loc) · 1 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
// this background script is used to invoke desktopCapture API
// to capture screen-MediaStream.
var screenOptions = ['screen', 'window'];
chrome.runtime.onConnect.addListener(function (port) {
port.onMessage.addListener(portOnMessageHanlder);
// this one is called for each message from "content-script.js"
function portOnMessageHanlder(message) {
if(message == 'get-sourceId') {
chrome.desktopCapture.chooseDesktopMedia(screenOptions, port.sender.tab, onAccessApproved);
}
}
// on getting sourceId
// "sourceId" will be empty if permission is denied.
function onAccessApproved(sourceId) {
// if "cancel" button is clicked
if(!sourceId || !sourceId.length) {
return port.postMessage('PermissionDeniedError');
}
// "ok" button is clicked; share "sourceId" with the
// content-script which will forward it to the webpage
port.postMessage({
sourceId: sourceId
});
}
});