├── enable-screen-capturing-old ├── icon.png ├── enable-screen-capturing.xpi ├── install.rdf ├── README.md └── bootstrap.js ├── enable-screen-capturing ├── test │ └── test-index.js ├── package.json ├── content-script.js ├── README.md └── index.js ├── enable-screen-capturing-old2 ├── test │ └── test-index.js ├── package.json ├── content-script.js ├── FirefoxScreenAddon.js ├── README.md └── index.js └── README.md /enable-screen-capturing-old/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/Firefox-Extensions/master/enable-screen-capturing-old/icon.png -------------------------------------------------------------------------------- /enable-screen-capturing-old/enable-screen-capturing.xpi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muaz-khan/Firefox-Extensions/master/enable-screen-capturing-old/enable-screen-capturing.xpi -------------------------------------------------------------------------------- /enable-screen-capturing/test/test-index.js: -------------------------------------------------------------------------------- 1 | var main = require("../"); 2 | 3 | exports["test main"] = function(assert) { 4 | assert.pass("Unit test running!"); 5 | }; 6 | 7 | exports["test main async"] = function(assert, done) { 8 | assert.pass("async Unit test running!"); 9 | done(); 10 | }; 11 | 12 | require("sdk/test").run(exports); 13 | -------------------------------------------------------------------------------- /enable-screen-capturing-old2/test/test-index.js: -------------------------------------------------------------------------------- 1 | var main = require("../"); 2 | 3 | exports["test main"] = function(assert) { 4 | assert.pass("Unit test running!"); 5 | }; 6 | 7 | exports["test main async"] = function(assert, done) { 8 | assert.pass("async Unit test running!"); 9 | done(); 10 | }; 11 | 12 | require("sdk/test").run(exports); 13 | -------------------------------------------------------------------------------- /enable-screen-capturing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Enable Screen Capturing in Firefox", 3 | "name": "enable-screen-capturing", 4 | "id": "{3ef085b0-fe60-11df-8cff-0800200c9a66}", 5 | "version": "1.2.001", 6 | "description": "This firefox extension enables screen capturing support in Firefox for https://www.webrtc-experiment.com pages.", 7 | "main": "index.js", 8 | "author": "Muaz Khan ", 9 | "engines": { 10 | "firefox": ">=38.0a1" 11 | }, 12 | "license": "MIT", 13 | "permissions": { 14 | "unsafe-content-script": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /enable-screen-capturing-old2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Enable Screen Capturing in Firefox", 3 | "name": "enable-screen-capturing", 4 | "id": "{3ef085b0-fe60-11df-8cff-0800200c9a66}", 5 | "version": "1.1.001", 6 | "description": "This firefox extension enables screen capturing support in Firefox for https://www.webrtc-experiment.com pages.", 7 | "main": "index.js", 8 | "author": "Muaz Khan ", 9 | "engines": { 10 | "firefox": ">=38.0a1" 11 | }, 12 | "license": "MIT", 13 | "permissions": { 14 | "unsafe-content-script": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /enable-screen-capturing/content-script.js: -------------------------------------------------------------------------------- 1 | // Muaz Khan - www.MuazKhan.com 2 | // MIT License - www.WebRTC-Experiment.com/licence 3 | // Github - github.com/muaz-khan/Firefox-Extensions 4 | 5 | // window.postMessage({ enableScreenCapturing: true }, "*"); 6 | 7 | window.addEventListener("message", function(event) { 8 | // do NOT allow external domains 9 | // via: https://github.com/muaz-khan/Firefox-Extensions/issues/11 10 | if (event.source !== document.defaultView) return; 11 | 12 | var addonMessage = event.data; 13 | 14 | // this content-script is used to check whether screen capturing is enabled for your own domain or not. 15 | if(addonMessage && addonMessage.checkIfScreenCapturingEnabled) { 16 | self.port.on('is-screen-capturing-enabled-response', function(response) { 17 | window.postMessage(response, '*'); 18 | }); 19 | 20 | self.port.emit('is-screen-capturing-enabled'); 21 | } 22 | }, false); 23 | -------------------------------------------------------------------------------- /enable-screen-capturing-old/install.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | muazkh@gmail.com 5 | 2 6 | Screen Capturing in Firefox 7 | Firefox extension to enable screen capturing 8 | 1.0 9 | true 10 | Muaz Khan 11 | https://www.webrtc-experiment.com/ 12 | icon.png 13 | 14 | 15 | {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 16 | 33.0 17 | 100000.* 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /enable-screen-capturing-old/README.md: -------------------------------------------------------------------------------- 1 | # Enable Screen Capturing using [Firefox Extensions API](https://github.com/muaz-khan/Firefox-Extensions) 2 | 3 | Enable screen capturing using Firefox (for https://www.webrtc-experiment.com demos only): 4 | 5 | * [enable-screen-capturing.xpi](https://www.webrtc-experiment.com/store/firefox-extension/enable-screen-capturing.xpi) 6 | 7 | # To Install 8 | 9 | 1. type `about:config` into the URL bar in Firefox 10 | 2. in the Search box type `xpinstall.signatures.required` 11 | 3. double-click the preference, or right-click and select **"Toggle"**, to set it to `false`. 12 | 13 | To use in your own domains: 14 | 15 | Modify `bootstrap.js` file, line 18: 16 | 17 | ```javascript 18 | ['yourDomain.com', 'www.yourDomain.com'].forEach(function(domain) { 19 | if (values.indexOf(domain) === -1) { 20 | values.push(domain); 21 | addon_domains.push(domain); 22 | } 23 | }); 24 | ``` 25 | 26 | And modify `install.rdf` for you extension information (name, URL, icon etc.) 27 | 28 | ## Credits 29 | 30 | [Muaz Khan](https://github.com/muaz-khan): 31 | 32 | 1. Personal Webpage: http://www.muazkhan.com 33 | 2. Email: muazkh@gmail.com 34 | 3. Twitter: https://twitter.com/muazkh and https://twitter.com/WebRTCWeb 35 | 4. Google+: https://plus.google.com/+WebRTC-Experiment 36 | 37 | ## License 38 | 39 | [Firefox-Extensions](https://github.com/muaz-khan/Firefox-Extensions) are released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](https://plus.google.com/+MuazKhan). 40 | -------------------------------------------------------------------------------- /enable-screen-capturing-old2/content-script.js: -------------------------------------------------------------------------------- 1 | // Muaz Khan - www.MuazKhan.com 2 | // MIT License - www.WebRTC-Experiment.com/licence 3 | // Github - github.com/muaz-khan/Firefox-Extensions 4 | 5 | // window.postMessage({ enableScreenCapturing: true, domains: ["www.firefox.com"] }, "*"); 6 | 7 | window.addEventListener("message", function(event) { 8 | var addonMessage = event.data; 9 | 10 | if(addonMessage && addonMessage.enableScreenCapturing && addonMessage.domains && addonMessage.domains.length) { 11 | var confirmMessage = 'Current webpage requested to enable WebRTC Screen Capturing for following domains:\n'; 12 | confirmMessage += JSON.stringify(addonMessage.domains, null, '\t') + '\n\n'; 13 | confirmMessage += 'Please confirm to enable "permanent" screen capturing for above domains.'; 14 | 15 | if(window.confirm(confirmMessage)) { 16 | self.port.emit('installation-confirmed', addonMessage.domains); 17 | 18 | // tell webpage that user confirmed screen capturing & its enabled for his domains. 19 | window.postMessage({ 20 | enabledScreenCapturing: true, 21 | domains: addonMessage.domains 22 | }, '*'); 23 | } 24 | else { 25 | // tell webpage that user denied/rejected screen capturing for his domains. 26 | window.postMessage({ 27 | enabledScreenCapturing: false, 28 | domains: addonMessage.domains, 29 | reason: 'user-rejected' 30 | }, '*'); 31 | } 32 | } 33 | 34 | if(addonMessage && addonMessage.checkIfScreenCapturingEnabled && addonMessage.domains && addonMessage.domains.length) { 35 | self.port.on('is-screen-capturing-enabled-response', function(response) { 36 | window.postMessage(response, '*'); 37 | }); 38 | 39 | self.port.emit('is-screen-capturing-enabled', addonMessage.domains); 40 | } 41 | }, false); 42 | -------------------------------------------------------------------------------- /enable-screen-capturing-old/bootstrap.js: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. 4 | * taken from: HenrikJoreteg/getScreenMedia/firefox-extension-sample 5 | * original source: https://hg.mozilla.org/users/blassey_mozilla.com/screenshare-whitelist/ 6 | */ 7 | var addon_domains = []; // list of domains the addon added 8 | var allowed_domains_pref = 'media.getusermedia.screensharing.allowed_domains'; 9 | var enable_screensharing_pref = 'media.getusermedia.screensharing.enabled'; 10 | 11 | function startup(data, reason) { 12 | if (reason === APP_STARTUP) { 13 | return; 14 | } 15 | var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 16 | var values = prefs.getCharPref(allowed_domains_pref).split(','); 17 | 18 | ['webrtc-experiment.com', 'www.webrtc-experiment.com'].forEach(function(domain) { 19 | if (values.indexOf(domain) === -1) { 20 | values.push(domain); 21 | addon_domains.push(domain); 22 | } 23 | }); 24 | 25 | if(prefs.getBoolPref(enable_screensharing_pref) == false) { 26 | prefs.setBoolPref(enable_screensharing_pref, 1); 27 | } 28 | prefs.setCharPref(allowed_domains_pref, values.join(',')); 29 | } 30 | 31 | function shutdown(data, reason) { 32 | if (reason === APP_SHUTDOWN) { 33 | return; 34 | } 35 | var prefs = Components.classes["@mozilla.org/preferences-service;1"] 36 | .getService(Components.interfaces.nsIPrefBranch); 37 | var values = prefs.getCharPref(allowed_domains_pref).split(','); 38 | values = values.filter(function(value) { 39 | return addon_domains.indexOf(value) === -1; 40 | }); 41 | prefs.setCharPref(allowed_domains_pref, values.join(',')); 42 | } 43 | 44 | function install(data, reason) {} 45 | 46 | function uninstall(data, reason) {} 47 | -------------------------------------------------------------------------------- /enable-screen-capturing-old2/FirefoxScreenAddon.js: -------------------------------------------------------------------------------- 1 | // Muaz Khan - www.MuazKhan.com 2 | // MIT License - www.WebRTC-Experiment.com/licence 3 | // Github - github.com/muaz-khan/Firefox-Extensions 4 | 5 | // FirefoxScreenAddon.checkIfScreenCapturingEnabled(domains, callback); 6 | // FirefoxScreenAddon.enableScreenCapturing(domains, callback); 7 | 8 | var FirefoxScreenAddon = (function() { 9 | return { 10 | checkIfScreenCapturingEnabled: function(domains, callback) { 11 | var isCallbackFired = false; 12 | 13 | // ask addon to check if screen capturing enabled for specific domains 14 | window.postMessage({ 15 | checkIfScreenCapturingEnabled: true, 16 | domains: domains 17 | }, "*"); 18 | 19 | // watch addon's response 20 | // addon will return "isScreenCapturingEnabled=true|false" 21 | window.addEventListener("message", function(event) { 22 | if(!isCallbackFired) return; 23 | 24 | var addonMessage = event.data; 25 | if(!addonMessage || typeof addonMessage.isScreenCapturingEnabled === 'undefined') return; 26 | 27 | isCallbackFired = true; 28 | callback(addonMessage); 29 | }, false); 30 | }, 31 | enableScreenCapturing: function(domains, callback) { 32 | var isCallbackFired = false; 33 | 34 | // request addon to enable screen capturing for your domains 35 | window.postMessage({ 36 | enableScreenCapturing: true, 37 | domains: domains 38 | }, "*"); 39 | 40 | // watch addon's response 41 | // addon will return "enabledScreenCapturing=true" for success 42 | // else "enabledScreenCapturing=false" for failure (i.e. user rejection) 43 | window.addEventListener("message", function(event) { 44 | if(!isCallbackFired) return; 45 | 46 | var addonMessage = event.data; 47 | if(!addonMessage || typeof addonMessage.enabledScreenCapturing === 'undefined') return; 48 | 49 | isCallbackFired = true; 50 | callback(addonMessage); 51 | }, false); 52 | } 53 | }; 54 | })(); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Firefox doesn't need add-ons in order to do screen sharing, since Firefox 52 already. [More info](https://wiki.mozilla.org/Screensharing) 2 | 3 | # This repository is discontinued from September 01, 2017. 4 | 5 | ---- 6 | 7 | # [Firefox Extensions](https://github.com/muaz-khan/Firefox-Extensions) 8 | 9 | > Enable screen capturing in Firefox for both localhost/127.0.0.1 and `https://www.webrtc-experiment.com` pages. 10 | 11 | ## Install from Firefox Addons Store 12 | 13 | * [https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/](https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/) 14 | 15 | ## Simplest Demo 16 | 17 | Try this demo after installing above addon: 18 | 19 | * [https://www.webrtc-experiment.com/getScreenId/](https://www.webrtc-experiment.com/getScreenId/) 20 | 21 | ## Wanna Deploy it Yourself? 22 | 23 | 1. Open [`index.js`](https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/index.js) 24 | 2. Go to line 7 25 | 3. Replace `arrayOfMyOwnDomains` array with your own list of domains 26 | 27 | ```javascript 28 | // replace your own domains with below array 29 | var arrayOfMyOwnDomains = ['webrtc-experiment.com', 'www.webrtc-experiment.com', 'localhost', '127.0.0.1']; 30 | ``` 31 | 32 | ## How to Deploy? 33 | 34 | 1) Signup here: 35 | 36 | * https://addons.mozilla.org/en-US/firefox/users/register 37 | 38 | 2) Use unique-addon-name here: 39 | 40 | * https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/package.json#L3 41 | 42 | 3) Add your own domains here: 43 | 44 | * https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/index.js#L7 45 | 46 | 4) Make XPI of the directory. 47 | 48 | ``` 49 | [sudo] npm install jpm --global 50 | 51 | jpm run -b nightly # test in Firefox Nightly without making the XPI 52 | 53 | jpm xpi # it will create xpi file 54 | ``` 55 | 56 | 5) Submit the XPI here: 57 | 58 | * https://addons.mozilla.org/en-US/developers/addon/submit/1 59 | 60 | Follow all steps. Read them carefully. This is hard/tough step to follow. Select valid browsers. E.g. Firefox 38 to Firefox 45. And submit your addon for "review". 61 | 62 | It will take 2-3 hours for a Mozilla guy to review your addon. Then it will be available to public. 63 | 64 | ## License 65 | 66 | [Firefox-Extensions](https://github.com/muaz-khan/Firefox-Extensions) are released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](http://www.MuazKhan.com/). 67 | -------------------------------------------------------------------------------- /enable-screen-capturing-old2/README.md: -------------------------------------------------------------------------------- 1 | # [Firefox Extensions](https://github.com/muaz-khan/Firefox-Extensions) 2 | 3 | > Enable screen capturing in Firefox for both localhost/127.0.0.1 and `https://www.webrtc-experiment.com` pages. 4 | 5 | ## Install from Firefox Addons Store 6 | 7 | * [https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/](https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/) 8 | 9 | ## How to reuse same addon for your own domains? 10 | 11 | Means that, you **don't need to publish your own addon**, you can reuse above link in your own domains/applications! 12 | 13 | You should copy/paste following code in your own webpage/domain (HTML/PHP/Python/etc.): 14 | 15 | ```javascript 16 | // request addon to enable screen capturing for your domains 17 | window.postMessage({ 18 | enableScreenCapturing: true, 19 | domains: ["www.yourdomain.com", "yourdomain.com"] 20 | }, "*"); 21 | 22 | // watch addon's response 23 | // addon will return "enabledScreenCapturing=true" for success 24 | // else "enabledScreenCapturing=false" for failure (i.e. user rejection) 25 | window.addEventListener("message", function(event) { 26 | var addonMessage = event.data; 27 | 28 | if(!addonMessage || typeof addonMessage.enabledScreenCapturing === 'undefined') return; 29 | 30 | if(addonMessage.enabledScreenCapturing === true) { 31 | // addonMessage.domains === [array-of-your-domains] 32 | alert(JSON.stringify(addonMessage.domains) + ' are enabled for screen capturing.'); 33 | } 34 | else { 35 | // reason === 'user-rejected' 36 | alert(addonMessage.reason); 37 | } 38 | }, false); 39 | ``` 40 | 41 | ## Simplest Demo 42 | 43 | Try this demo after installing above addon: 44 | 45 | * [https://www.webrtc-experiment.com/getScreenId/](https://www.webrtc-experiment.com/getScreenId/) 46 | 47 | ## Wanna Deploy it Yourself? 48 | 49 | 1. Open [`index.js`](https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/index.js) 50 | 2. Go to line 7 51 | 3. Replace `arrayOfMyOwnDomains` array with your own list of domains 52 | 53 | ```javascript 54 | // replace your own domains with below array 55 | var arrayOfMyOwnDomains = ['webrtc-experiment.com', 'www.webrtc-experiment.com', 'localhost', '127.0.0.1']; 56 | ``` 57 | 58 | ## How to Deploy? 59 | 60 | 1) Signup here: 61 | 62 | * https://addons.mozilla.org/en-US/firefox/users/register 63 | 64 | 2) Use unique-addon-name here: 65 | 66 | * https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/package.json#L3 67 | 68 | 3) Add your own domains here: 69 | 70 | * https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/index.js#L7 71 | 72 | 4) Make XPI of the directory. 73 | 74 | ``` 75 | [sudo] npm install jpm --global 76 | 77 | jpm run -b nightly # test in Firefox Nightly without making the XPI 78 | 79 | jpm xpi # it will create xpi file 80 | ``` 81 | 82 | 5) Submit the XPI here: 83 | 84 | * https://addons.mozilla.org/en-US/developers/addon/submit/1 85 | 86 | Follow all steps. Read them carefully. This is hard/tough step to follow. Select valid browsers. E.g. Firefox 38 to Firefox 45. And submit your addon for "review". 87 | 88 | It will take 2-3 hours for a Mozilla guy to review your addon. Then it will be available to public. 89 | 90 | ## License 91 | 92 | [Firefox-Extensions](https://github.com/muaz-khan/Firefox-Extensions) are released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](http://www.MuazKhan.com/). 93 | -------------------------------------------------------------------------------- /enable-screen-capturing/README.md: -------------------------------------------------------------------------------- 1 | # Firefox doesn't need add-ons in order to do screen sharing, since Firefox 52 already. [More info](https://wiki.mozilla.org/Screensharing) 2 | 3 | # This repository is discontinued from September 01, 2017. 4 | 5 | ---- 6 | 7 | # [Firefox Extensions](https://github.com/muaz-khan/Firefox-Extensions) 8 | 9 | > Enable screen capturing in Firefox for both localhost/127.0.0.1 and `https://www.webrtc-experiment.com` pages. 10 | > 11 | > You have to deploy this addon on Firefox addons-store, yourselves. 12 | 13 | ## Install from Firefox Addons Store 14 | 15 | * [https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/](https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/) 16 | 17 | ### Check if screen capturing is enabled for your domains: 18 | 19 | ```javascript 20 | // ask addon to check if screen capturing enabled for specific domains 21 | window.postMessage({ 22 | checkIfScreenCapturingEnabled: true 23 | }, "*"); 24 | 25 | // watch addon's response 26 | // addon will return "isScreenCapturingEnabled=true|false" 27 | window.addEventListener("message", function(event) { 28 | if (event.source !== window) return; 29 | 30 | var addonMessage = event.data; 31 | 32 | if(!addonMessage || typeof addonMessage.isScreenCapturingEnabled === 'undefined') return; 33 | 34 | if(addonMessage.isScreenCapturingEnabled === true) { 35 | alert(JSON.stringify(addonMessage.domains) + '\n are enabled for screen capturing.'); 36 | } 37 | else { 38 | alert(JSON.stringify(addonMessage.domains) + '\n are NOT enabled for screen capturing.'); 39 | } 40 | }, false); 41 | ``` 42 | 43 | ### Insights: 44 | 45 | Your requests to addon: `checkIfScreenCapturingEnabled`: ask addon to check if screen is already enabled for specific domains. 46 | 47 | Addon responses: 48 | 49 | 1. `isScreenCapturingEnabled` - Here `true` means domain is already enabled for specific domains. 50 | 2. `domains` - list of same domains that are enabled for screen capturing. 51 | 52 | ## Simplest Demo 53 | 54 | Try this demo after installing above addon: 55 | 56 | * [https://www.webrtc-experiment.com/getScreenId/](https://www.webrtc-experiment.com/getScreenId/) 57 | 58 | ## Wanna Deploy it Yourself? 59 | 60 | 1. Open [`index.js`](https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/index.js) 61 | 2. Go to line 7 62 | 3. Replace `arrayOfMyOwnDomains` array with your own list of domains 63 | 64 | ```javascript 65 | // replace your own domains with below array 66 | var arrayOfMyOwnDomains = ['webrtc-experiment.com', 'www.webrtc-experiment.com', 'localhost', '127.0.0.1']; 67 | ``` 68 | 69 | ## How to Deploy? 70 | 71 | 1) Signup here: 72 | 73 | * https://addons.mozilla.org/en-US/firefox/users/register 74 | 75 | 2) Use unique-addon-name here: 76 | 77 | * https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/package.json#L3 78 | 79 | 3) Add your own domains here: 80 | 81 | * https://github.com/muaz-khan/Firefox-Extensions/blob/master/enable-screen-capturing/index.js#L7 82 | 83 | 4) Make XPI of the directory. 84 | 85 | ``` 86 | [sudo] npm install jpm --global 87 | 88 | jpm run -b nightly # test in Firefox Nightly without making the XPI 89 | 90 | jpm xpi # it will create xpi file 91 | ``` 92 | 93 | 5) Submit the XPI here: 94 | 95 | * https://addons.mozilla.org/en-US/developers/addon/submit/1 96 | 97 | Follow all steps. Read them carefully. This is hard/tough step to follow. Select valid browsers. E.g. Firefox 38 to Firefox 45. And submit your addon for "review". 98 | 99 | It will take 2-3 hours for a Mozilla AMO reviewer to review your addon. Then it will be available to public. 100 | 101 | ## License 102 | 103 | [Firefox-Extensions](https://github.com/muaz-khan/Firefox-Extensions) are released under [MIT licence](https://www.webrtc-experiment.com/licence/) . Copyright (c) [Muaz Khan](http://www.MuazKhan.com/). 104 | -------------------------------------------------------------------------------- /enable-screen-capturing-old2/index.js: -------------------------------------------------------------------------------- 1 | // Muaz Khan - www.MuazKhan.com 2 | // MIT License - www.WebRTC-Experiment.com/licence 3 | // Github - github.com/muaz-khan/Firefox-Extensions 4 | 5 | var prefService = require('sdk/preferences/service'); 6 | 7 | var configToReferListOfAllowedDomains = 'media.getusermedia.screensharing.allowed_domains'; 8 | var configToEnableScreenCapturing = 'media.getusermedia.screensharing.enabled'; 9 | 10 | // replace your own domains with below array 11 | var arrayOfMyOwnDomains = ['webrtc-experiment.com', 'www.webrtc-experiment.com', 'localhost', '127.0.0.1']; 12 | 13 | // e.g. if 127.0.0.1 or localhost is already allowed by anyone else 14 | var listOfSimilarAlreadyAllowedDomains = []; 15 | 16 | // if(prefService.has(configToEnableScreenCapturing)) {} 17 | // this flag is enabled by default since Firefox version 37 or 38. 18 | // it maybe get removed in version 47-48. (As far as I can assume) 19 | // i.e. screen capturing will always be allowed to list of allowed_domains. 20 | prefService.set(configToEnableScreenCapturing, true); 21 | 22 | function addMyOwnDomains() { 23 | var existingDomains = prefService.get(configToReferListOfAllowedDomains).split(','); 24 | arrayOfMyOwnDomains.forEach(function(domain) { 25 | if (existingDomains.indexOf(domain) === -1) { 26 | existingDomains.push(domain); 27 | } 28 | 29 | // else { } 30 | else if (existingDomains.indexOf(domain) !== -1) { 31 | // Seems domain is already in the list. 32 | // Keep it when this addon is uninstalled. 33 | listOfSimilarAlreadyAllowedDomains.push(domain); 34 | } 35 | }); 36 | prefService.set(configToReferListOfAllowedDomains, existingDomains.join(',')); 37 | } 38 | addMyOwnDomains(); 39 | 40 | // below code handles addon-uninstall 41 | function removeMyDomainOnUnInstall() { 42 | var externalDomains = []; 43 | 44 | prefService.get(configToReferListOfAllowedDomains).split(',').forEach(function(domain) { 45 | // Skip Others Domains 46 | if (arrayOfMyOwnDomains.indexOf(domain) === -1) { 47 | // if its NOT mine, keep it. 48 | externalDomains.push(domain); 49 | } else if (listOfSimilarAlreadyAllowedDomains.indexOf(domain) !== -1) { 50 | // seems that localhost/127.0.0.1 are already added by external users 51 | externalDomains.push(domain); 52 | } 53 | }); 54 | 55 | prefService.set(configToReferListOfAllowedDomains, externalDomains.join(',')); 56 | } 57 | 58 | var { 59 | when: unload 60 | } = require("sdk/system/unload"); 61 | 62 | // By AMO policy global preferences must be changed back to their original value 63 | unload(function() { 64 | // remove only my own domains 65 | removeMyDomainOnUnInstall(); 66 | }); 67 | 68 | /* 69 | * connect with webpage using postMessage 70 | * a webpage can use following API to enable screen capturing for his domains 71 | * window.postMessage({ enableScreenCapturing: true, domains: ["www.firefox.com"] }, "*"); 72 | * 73 | * current firefox user is always asked to confirm whether he is OK to enable screen capturing for requested domains. 74 | */ 75 | var tabs = require("sdk/tabs"); 76 | var mod = require("sdk/page-mod"); 77 | var self = require("sdk/self"); 78 | 79 | var pageMod = mod.PageMod({ 80 | include: ["*"], 81 | contentScriptFile: "./../content-script.js", 82 | contentScriptWhen: "start", // or "ready" 83 | onAttach: function(worker) { 84 | worker.port.on("installation-confirmed", function(domains) { 85 | // make sure that this addon's self-domains (i.e. "arrayOfMyOwnDomains") 86 | // are not included in the "listOfSimilarAlreadyAllowedDomains" array. 87 | removeMyDomainOnUnInstall(); 88 | 89 | arrayOfMyOwnDomains = arrayOfMyOwnDomains.concat(domains); 90 | addMyOwnDomains(); 91 | }); 92 | 93 | worker.port.on("is-screen-capturing-enabled", function(domains) { 94 | var isScreenCapturingEnabled = false; 95 | 96 | prefService.get(configToReferListOfAllowedDomains).split(',').forEach(function(domain) { 97 | if(domains.indexOf(domain) !== -1) { 98 | isScreenCapturingEnabled = true; 99 | } 100 | }); 101 | 102 | worker.port.emit('is-screen-capturing-enabled-response', { 103 | isScreenCapturingEnabled: isScreenCapturingEnabled, 104 | domains: domains 105 | }); 106 | }); 107 | } 108 | }); 109 | -------------------------------------------------------------------------------- /enable-screen-capturing/index.js: -------------------------------------------------------------------------------- 1 | // Muaz Khan - www.MuazKhan.com 2 | // MIT License - www.WebRTC-Experiment.com/licence 3 | // Github - github.com/muaz-khan/Firefox-Extensions 4 | 5 | var prefService = require('sdk/preferences/service'); 6 | 7 | var configToReferListOfAllowedDomains = 'media.getusermedia.screensharing.allowed_domains'; 8 | var configToEnableScreenCapturing = 'media.getusermedia.screensharing.enabled'; 9 | 10 | // replace your own domains with below array 11 | var arrayOfMyOwnDomains = ['webrtc-experiment.com', 'www.webrtc-experiment.com', 'rtcmulticonnection.herokuapp.com', 'localhost', '127.0.0.1']; 12 | // Patterns to match the websites that may check whether ther add-on is installed. 13 | // See https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/util_match-pattern 14 | var patternsOfMyDomains = ['*.webrtc-experiment.com', '*.rtcmulticonnection.herokuapp.com', /https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?\/.*/]; 15 | 16 | // e.g. if 127.0.0.1 or localhost is already allowed by anyone else 17 | var listOfSimilarAlreadyAllowedDomains = []; 18 | 19 | // if(prefService.has(configToEnableScreenCapturing)) {} 20 | // this flag is enabled by default since Firefox version 37 or 38. 21 | // it maybe get removed in version 47-48. (As far as I can assume) 22 | // i.e. screen capturing will always be allowed to list of allowed_domains. 23 | prefService.set(configToEnableScreenCapturing, true); 24 | 25 | function addMyOwnDomains() { 26 | var existingDomains = prefService.get(configToReferListOfAllowedDomains).split(','); 27 | arrayOfMyOwnDomains.forEach(function(domain) { 28 | if (existingDomains.indexOf(domain) === -1) { 29 | existingDomains.push(domain); 30 | } 31 | 32 | // else { } 33 | else if (existingDomains.indexOf(domain) !== -1) { 34 | // Seems domain is already in the list. 35 | // Keep it when this addon is uninstalled. 36 | listOfSimilarAlreadyAllowedDomains.push(domain); 37 | } 38 | }); 39 | prefService.set(configToReferListOfAllowedDomains, existingDomains.join(',')); 40 | } 41 | addMyOwnDomains(); 42 | 43 | // below code handles addon-uninstall 44 | function removeMyDomainOnUnInstall() { 45 | var externalDomains = []; 46 | 47 | prefService.get(configToReferListOfAllowedDomains).split(',').forEach(function(domain) { 48 | // Skip Others Domains 49 | if (arrayOfMyOwnDomains.indexOf(domain) === -1) { 50 | // if its NOT mine, keep it. 51 | externalDomains.push(domain); 52 | } else if (listOfSimilarAlreadyAllowedDomains.indexOf(domain) !== -1) { 53 | // seems that localhost/127.0.0.1 are already added by external users 54 | externalDomains.push(domain); 55 | } 56 | }); 57 | 58 | prefService.set(configToReferListOfAllowedDomains, externalDomains.join(',')); 59 | } 60 | 61 | var { 62 | when: unload 63 | } = require("sdk/system/unload"); 64 | 65 | // By AMO policy global preferences must be changed back to their original value 66 | unload(function() { 67 | // remove only my own domains 68 | removeMyDomainOnUnInstall(); 69 | }); 70 | 71 | var tabs = require("sdk/tabs"); 72 | var mod = require("sdk/page-mod"); 73 | var self = require("sdk/self"); 74 | 75 | var pageMod = mod.PageMod({ 76 | include: patternsOfMyDomains, 77 | contentScriptFile: "./../content-script.js", 78 | contentScriptWhen: "start", // or "ready" 79 | onAttach: function(worker) { 80 | // webpages can verify if their domains are REALLY enabled or not. 81 | worker.port.on("is-screen-capturing-enabled", function() { 82 | var isScreenCapturingEnabled = false; 83 | 84 | var arrayOfEnabledDomains = []; 85 | 86 | prefService.get(configToReferListOfAllowedDomains).split(',').forEach(function(domain) { 87 | if(arrayOfMyOwnDomains.indexOf(domain) !== -1) { 88 | // maybe we need to check whether all of, my own, domains are enabled? 89 | isScreenCapturingEnabled = true; 90 | 91 | // we will pass this to the webpage 92 | // so webpage can understand which domain is enabled; and which is NOT. 93 | arrayOfEnabledDomains.push(domain); 94 | } 95 | }); 96 | 97 | worker.port.emit('is-screen-capturing-enabled-response', { 98 | isScreenCapturingEnabled: isScreenCapturingEnabled, 99 | 100 | // pass only those domains that are enabled for screen capturing 101 | // however those domains MUST be our own 102 | domains: arrayOfEnabledDomains 103 | }); 104 | }); 105 | } 106 | }); 107 | --------------------------------------------------------------------------------