-
Notifications
You must be signed in to change notification settings - Fork 68
/
background.js
28 lines (27 loc) · 898 Bytes
/
background.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
var desktopMediaRequestId = '';
chrome.runtime.onMessageExternal.addListener(function (msg, sender, sendResponse) {
console.log("Got new message ", msg);
if (!msg) {
return;
}
if (msg.type === 'PYCHAT_SCREEN_SHARE_PING') {
sendResponse({type: 'PYCHAT_SCREEN_SHARE_PING', data: 'success'});
} else if (msg.type === 'PYCHAT_SCREEN_SHARE_REQUEST') {
const sources = ['screen', 'window', 'tab', 'audio'];
desktopMediaRequestId = chrome.desktopCapture.chooseDesktopMedia(sources, sender.tab, function (streamId) {
msg.type = 'PYCHAT_SCREEN_SHARE_REQUEST';
if (streamId) {
msg.streamId = streamId;
msg.data = 'success';
} else {
msg.data = 'fail';
}
sendResponse(msg);
});
return true;
} else if (msg.type === 'PYCHAT_SCREEN_SHARE_CANCEL') {
if (desktopMediaRequestId) {
chrome.desktopCapture.cancelChooseDesktopMedia(desktopMediaRequestId);
}
}
});