cleaning
This commit is contained in:
@ -1,41 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var dataSources = ['screen', 'window'];
|
||||
var desktopMediaRequestId = '';
|
||||
|
||||
chrome.runtime.onConnect.addListener(function(port) {
|
||||
port.onMessage.addListener(function(msg) {
|
||||
if (msg.type === 'SS_UI_REQUEST') {
|
||||
requestScreenSharing(port, msg);
|
||||
}
|
||||
|
||||
if (msg.type === 'SS_UI_CANCEL') {
|
||||
cancelScreenSharing(msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function requestScreenSharing(port, msg) {
|
||||
// https://developer.chrome.com/extensions/desktopCapture
|
||||
// params:
|
||||
// - 'dataSources' Set of sources that should be shown to the user.
|
||||
// - 'targetTab' Tab for which the stream is created.
|
||||
// - 'streamId' String that can be passed to getUserMedia() API
|
||||
desktopMediaRequestId =
|
||||
chrome.desktopCapture.chooseDesktopMedia(dataSources, port.sender.tab,
|
||||
function(streamId) {
|
||||
if (streamId) {
|
||||
msg.type = 'SS_DIALOG_SUCCESS';
|
||||
msg.streamId = streamId;
|
||||
} else {
|
||||
msg.type = 'SS_DIALOG_CANCEL';
|
||||
}
|
||||
port.postMessage(msg);
|
||||
});
|
||||
}
|
||||
|
||||
function cancelScreenSharing() {
|
||||
if (desktopMediaRequestId) {
|
||||
chrome.desktopCapture.cancelChooseDesktopMedia(desktopMediaRequestId);
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// https://chromeextensionsdocs.appspot.com/apps/content_scripts#host-page-communication
|
||||
// - 'content_script' and execution env are isolated from each other
|
||||
// - In order to communicate we use the DOM (window.postMessage)
|
||||
//
|
||||
// app.js | |content-script.js | |background.js
|
||||
// window.postMessage|------->|port.postMessage |----->| port.onMessage
|
||||
// | window | | port |
|
||||
// webkitGetUserMedia|<------ |window.postMessage|<-----| port.postMessage
|
||||
//
|
||||
|
||||
var port = chrome.runtime.connect(chrome.runtime.id);
|
||||
|
||||
port.onMessage.addListener(function(msg) {
|
||||
window.postMessage(msg, '*');
|
||||
});
|
||||
|
||||
window.addEventListener('message', function(event) {
|
||||
// We only accept messages from ourselves
|
||||
if (event.source !== window) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.data.type && ((event.data.type === 'SS_UI_REQUEST') ||
|
||||
(event.data.type === 'SS_UI_CANCEL'))) {
|
||||
port.postMessage(event.data);
|
||||
}
|
||||
}, false);
|
||||
|
||||
window.postMessage({ type: 'SS_PING', text: 'start' }, '*');
|
Binary file not shown.
Before Width: | Height: | Size: 6.8 KiB |
@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "Screensharing Extension",
|
||||
"description": "Screensharing Extension for my app",
|
||||
"version": "1.0.0",
|
||||
"manifest_version": 2,
|
||||
"icons": {
|
||||
"128": "icon.png"
|
||||
},
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://dev.pschneider.fr/*"],
|
||||
"js": ["content-script.js"]
|
||||
}
|
||||
],
|
||||
"permissions": [
|
||||
"desktopCapture",
|
||||
"https://dev.pschneider.fr/*"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user