Permalink
Browse files

getScreenId(sucessCallback, ['screen, 'audio']) implemented!

  • Loading branch information...
muaz-khan committed Jun 8, 2018
1 parent 8216d1c commit 35b66f47d9b93774360e43945e73d854f6ea56b2
Showing with 53 additions and 52 deletions.
  1. +10 −8 README.md
  2. +0 −16 fake-keys/certificate.pem
  3. +0 −15 fake-keys/privatekey.pem
  4. +28 −3 getScreenId.html
  5. +13 −8 getScreenId.js
  6. +2 −2 index.html
View
@@ -72,7 +72,7 @@ getScreenId(function (error, sourceId, screen_constraints) {
alert('Failed to capture your screen. Please check Chrome console logs for further information.');
});
}, 'pass second argument only if you want to capture speakers as well');
});
```
Or...
@@ -113,7 +113,7 @@ getScreenId(function (error, sourceId, screen_constraints) {
alert('Failed to capture your screen. Please check Chrome console logs for further information.');
});
}, 'pass second argument only if you want to capture speakers as well');
});
```
# `getChromeExtensionStatus`
@@ -136,16 +136,18 @@ getChromeExtensionStatus(function(status) {
* That `<iframe>` can connect with chrome-extension. It can send/receive `postMessage` data.
* Same `postMessage` API are used to pass `screen-id` back to your script.
# System Audio i.e. Speakers?
# Custom Parameter
Pass second argument to `getScrenId` method:
* `true` means that capture system audio i.e. speakers
* `[]` array means that capture custom array items
```javascript
// second argument can be any non-Zero or non-False character
// e.g. a boolean, a string, or a number greater than or equal to 1
getScreenId(successCallback, true);
getScreenId(successCallback, 1);
getScreenId(successCallback, 'enable speakers');
getScreenId(successCallback, true); // capture speakers
getScreenId(successCallback, ['tab']); // capature only tab
getScreenId(successCallback, ['window']); // capature only app's windows
getScreenId(successCallback, ['screen', 'audio']); // capature only screen with speakers
```
# Firefox
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -20,10 +20,23 @@
DetectRTC.screen = {
chromeMediaSource: 'screen',
getSourceId: function(callback) {
if (!callback) throw '"callback" parameter is mandatory.';
screenCallback = callback;
window.postMessage('get-sourceId', '*');
},
getCustomSourceId: function(arr, callback) {
if (!arr || !arr.forEach) throw '"arr" parameter is mandatory and it must be an array.';
if (!callback) throw '"callback" parameter is mandatory.';
screenCallback = callback;
window.postMessage({
'get-custom-sourceId': arr
}, '*');
},
getSourceIdWithAudio: function(callback) {
if (!callback) throw '"callback" parameter is mandatory.';
screenCallback = callback;
window.postMessage('audio-plus-tab', '*');
},
@@ -81,7 +94,7 @@
};
window.addEventListener('message', function(event) {
if (!event.data || !(typeof event.data == 'string' || event.data.sourceId || event.data.captureSourceId || event.data.getChromeExtensionStatus || event.data.captureSourceIdWithAudio)) return;
if (!event.data || !(typeof event.data == 'string' || event.data.sourceId || event.data.captureSourceId || event.data.captureCustomSourceId || event.data.getChromeExtensionStatus || event.data.captureSourceIdWithAudio)) return;
if (event.data.getChromeExtensionStatus) {
DetectRTC.screen.getChromeExtensionStatus(function(status) {
@@ -92,6 +105,10 @@
return;
}
if(event.data.captureCustomSourceId) {
captureSourceId(null, event.data.captureCustomSourceId);
}
if (event.data.captureSourceId) {
captureSourceId();
}
@@ -103,7 +120,7 @@
DetectRTC.screen.onMessageCallback(event.data);
});
function captureSourceId(system_audio) {
function captureSourceId(system_audio, custom_sourceId) {
// check if desktop-capture extension installed.
DetectRTC.screen.getChromeExtensionStatus(function(status) {
if (status != 'installed-enabled') {
@@ -113,7 +130,15 @@
return;
}
if(!system_audio) {
if(!!custom_sourceId) {
DetectRTC.screen.getCustomSourceId(custom_sourceId, function(sourceId, canRequestAudioTrack) {
window.parent.postMessage({
chromeMediaSourceId: sourceId,
canRequestAudioTrack: !!canRequestAudioTrack
}, '*');
});
}
else if(!system_audio && !custom_sourceId) {
DetectRTC.screen.getSourceId(function(sourceId) {
window.parent.postMessage({
chromeMediaSourceId: sourceId
View
@@ -1,4 +1,4 @@
// Last time updated on May 04, 2018
// Last time updated on June 08, 2018
// Latest file can be found here: https://cdn.webrtc-experiment.com/getScreenId.js
@@ -25,7 +25,7 @@ getScreenId(function (error, sourceId, screen_constraints) {
*/
(function() {
window.getScreenId = function(callback, system_audio) {
window.getScreenId = function(callback, custom_parameter) {
if(navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob)) {
// microsoft edge => navigator.getDisplayMedia(screen_constraints).then(onSuccess, onFailure);
callback({
@@ -71,12 +71,12 @@ getScreenId(function (error, sourceId, screen_constraints) {
}
}
if(!system_audio) {
if(!custom_parameter) {
setTimeout(postGetSourceIdMessage, 100);
}
else {
setTimeout(function() {
postGetSourceIdMessage('system_audio');
postGetSourceIdMessage(custom_parameter);
}, 100);
}
};
@@ -115,26 +115,31 @@ getScreenId(function (error, sourceId, screen_constraints) {
return screen_constraints;
}
function postGetSourceIdMessage(system_audio) {
function postGetSourceIdMessage(custom_parameter) {
if (!iframe) {
loadIFrame(function() {
postGetSourceIdMessage(system_audio);
postGetSourceIdMessage(custom_parameter);
});
return;
}
if (!iframe.isLoaded) {
setTimeout(function() {
postGetSourceIdMessage(system_audio);
postGetSourceIdMessage(custom_parameter);
}, 100);
return;
}
if(!system_audio) {
if(!custom_parameter) {
iframe.contentWindow.postMessage({
captureSourceId: true
}, '*');
}
else if(!!custom_parameter.forEach) {
iframe.contentWindow.postMessage({
captureCustomSourceId: custom_parameter
}, '*');
}
else {
iframe.contentWindow.postMessage({
captureSourceIdWithAudio: true
View
@@ -244,7 +244,7 @@ <h1>
alert('Failed to capture your screen. Please check Chrome console logs for further information.');
});
}/*, 'we need speakers as well!'*/);
}/*, ['screen', 'audio']*/);
};
</script>
@@ -319,7 +319,7 @@ <h2 class="header specific-h2">
}).catch(function (error) {
console.error(error);
});
}, 'pass second argument only if you want to capture speakers as well');
});
&lt;/script&gt;
</pre>

0 comments on commit 35b66f4

Please sign in to comment.