Permalink
Browse files

getScreenId.js is NO-MORE-FUNCTIONAL.

  • Loading branch information...
muaz-khan committed Oct 10, 2015
1 parent 7038df0 commit ca3370c9f0908bed5678fead7147ec5fc7b49d71
Showing with 130 additions and 6 deletions.
  1. +4 −0 README.md
  2. +126 −6 index.html
View
@@ -1,3 +1,7 @@
> Note: Starting from Chrome 45, this demo is NO-MORE functional.
>
> Please don't use `getScreenId.js` in any of your domains until a new hack is added.
# `getScreenId.js` / [LIVE Demo](https://www.webrtc-experiment.com/getScreenId/)
## Hacking to use single chrome-extension on any domain!
View
@@ -95,6 +95,18 @@ <h1>
</section>
<script>
function intallFirefoxScreenCapturingExtension() {
InstallTrigger.install({
'Foo': {
// URL: 'https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/',
URL: 'https://addons.mozilla.org/firefox/downloads/file/355418/enable_screen_capturing_in_firefox-1.0.006-fx.xpi?src=cb-dl-hotness',
toString: function() {
return this.URL;
}
}
});
}
document.getElementById('capture-screen').onclick = function() {
this.disabled = true;
@@ -117,21 +129,129 @@ <h1>
});
};
</script>
<script>
// todo: need to check exact chrome browser because opera also uses chromium framework
var isChrome = !!navigator.webkitGetUserMedia;
// DetectRTC.js - https://github.com/muaz-khan/WebRTC-Experiment/tree/master/DetectRTC
// Below code is taken from RTCMultiConnection-v1.8.js (http://www.rtcmulticonnection.org/changes-log/#v1.8)
var DetectRTC = {};
(function () {
var screenCallback;
DetectRTC.screen = {
chromeMediaSource: 'screen',
getSourceId: function(callback) {
if(!callback) throw '"callback" parameter is mandatory.';
screenCallback = callback;
window.postMessage('get-sourceId', '*');
},
isChromeExtensionAvailable: function(callback) {
if(!callback) return;
if(DetectRTC.screen.chromeMediaSource == 'desktop') return callback(true);
// ask extension if it is available
window.postMessage('are-you-there', '*');
setTimeout(function() {
if(DetectRTC.screen.chromeMediaSource == 'screen') {
callback(false);
}
else callback(true);
}, 2000);
},
onMessageCallback: function(data) {
if (!(typeof data == 'string' || !!data.sourceId)) return;
console.log('chrome message', data);
// "cancel" button is clicked
if(data == 'PermissionDeniedError') {
DetectRTC.screen.chromeMediaSource = 'PermissionDeniedError';
if(screenCallback) return screenCallback('PermissionDeniedError');
else throw new Error('PermissionDeniedError');
}
// extension notified his presence
if(data == 'rtcmulticonnection-extension-loaded') {
if(document.getElementById('install-button')) {
document.getElementById('install-button').parentNode.innerHTML = '<strong>Great!</strong> <a href="https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk" target="_blank">Google chrome extension</a> is installed.';
}
DetectRTC.screen.chromeMediaSource = 'desktop';
}
// extension shared temp sourceId
if(data.sourceId) {
DetectRTC.screen.sourceId = data.sourceId;
if(screenCallback) screenCallback( DetectRTC.screen.sourceId );
}
},
getChromeExtensionStatus: function (callback) {
if (!!navigator.mozGetUserMedia) return callback('not-chrome');
var extensionid = 'ajhifddimkapgcifgcodmmfdlknahffk';
var image = document.createElement('img');
image.src = 'chrome-extension://' + extensionid + '/icon.png';
image.onload = function () {
DetectRTC.screen.chromeMediaSource = 'screen';
window.postMessage('are-you-there', '*');
setTimeout(function () {
if (!DetectRTC.screen.notInstalled) {
callback('installed-enabled');
}
}, 2000);
};
image.onerror = function () {
DetectRTC.screen.notInstalled = true;
callback('not-installed');
};
}
};
// check if desktop-capture extension installed.
if(window.postMessage && isChrome) {
DetectRTC.screen.isChromeExtensionAvailable();
}
})();
DetectRTC.screen.getChromeExtensionStatus(function(status) {
if(status == 'installed-enabled') {
if(document.getElementById('install-button')) {
document.getElementById('install-button').parentNode.innerHTML = '<strong>Great!</strong> <a href="https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk" target="_blank">Google chrome extension</a> is installed.';
}
DetectRTC.screen.chromeMediaSource = 'desktop';
}
});
window.addEventListener('message', function (event) {
if (event.origin != window.location.origin) {
return;
}
DetectRTC.screen.onMessageCallback(event.data);
});
console.log('current chromeMediaSource', DetectRTC.screen.chromeMediaSource);
</script>
<section class="experiment">
<h2>Prerequisites</h2>
<ol>
<li>
Chrome?
<a href="https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk" target="_blank">Install chrome extension</a>.
<button onclick="!!navigator.webkitGetUserMedia && !!window.chrome && !!chrome.webstore && !!chrome.webstore.install && chrome.webstore.install('https://chrome.google.com/webstore/detail/ajhifddimkapgcifgcodmmfdlknahffk', function() {location.reload();})" id="install-button" style="padding: 0;background: none;height: 61px;vertical-align: middle;cursor:pointer;">
<img src="https://www.webrtc-experiment.com/images/btn-install-chrome-extension.png" alt="Add to Chrome">
</button>
/ <a href="https://github.com/muaz-khan/Chrome-Extensions/tree/master/desktopCapture">Source Code</a>
<a href="https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk" target="_blank">Store</a>
/ <a href="https://github.com/muaz-khan/Chrome-Extensions/tree/master/desktopCapture">Source Code</a>
/
<button onclick="!!navigator.webkitGetUserMedia && !!window.chrome && !!chrome.webstore && !!chrome.webstore.install && chrome.webstore.install('https://chrome.google.com/webstore/detail/ajhifddimkapgcifgcodmmfdlknahffk', function() {location.reload();})" id="install-button" style="font-size:inherit; padding-bottom:0;">Click to Install</button>
</li>
<li>
Firefox? <a href="https://www.webrtc-experiment.com/store/firefox-extension/enable-screen-capturing.xpi">Install Firefox Extension</a> / <a href="https://github.com/muaz-khan/Firefox-Extensions/tree/master/enable-screen-capturing">Source Code</a>
Firefox? <a href="https://addons.mozilla.org/en-US/firefox/addon/enable-screen-capturing/">Store</a> / <a href="https://github.com/muaz-khan/Firefox-Extensions/tree/master/enable-screen-capturing">Source Code</a> / <button onclick="intallFirefoxScreenCapturingExtension(); this.disabled = true;" style="font-size:inherit; padding-bottom:0;">Click to Install</button>
</li>
</ol>
</section>

0 comments on commit ca3370c

Please sign in to comment.