Skip to content

Commit

Permalink
Merge pull request #512 from jmlacroix/fix-demo-screenid
Browse files Browse the repository at this point in the history
Replace getScreenId call with getDisplayMedia
  • Loading branch information
muaz-khan authored May 3, 2019
2 parents b3ad9a0 + fd2553f commit 3aceba7
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions simple-demos/record-cropped-screen.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,34 @@ <h1>Record Cropped Screen using <a href="https://github.com/muaz-khan/RecordRTC"

var recorder;

function captureScreen(cb) {
getScreenId(function(error, sourceId, screen_constraints) {
navigator.mediaDevices.getUserMedia(screen_constraints).then(cb).catch(function(error) {
console.error('getScreenId error', error);

alert('Failed to capture your screen. Please check Chrome console logs for further information.');
function getScreenStream(callback) {
if (navigator.getDisplayMedia) {
navigator.getDisplayMedia({
video: true
}).then(screenStream => {
callback(screenStream);
});
});
} else if (navigator.mediaDevices.getDisplayMedia) {
navigator.mediaDevices.getDisplayMedia({
video: true
}).then(screenStream => {
callback(screenStream);
});
} else {
getScreenId(function(error, sourceId, screen_constraints) {
navigator.mediaDevices.getUserMedia(screen_constraints).then(function(screenStream) {
callback(screenStream);
});
});
}
}

var mediaElement = document.querySelector('#mediaElement');

document.querySelector('#btn-start-recording').onclick = function() {
document.querySelector('#btn-start-recording').style.display = 'none';

captureScreen(function(screen) {
getScreenStream(function(screen) {
var inited = false;

mediaElement.ontimeupdate = function(ev) {
Expand Down

0 comments on commit 3aceba7

Please sign in to comment.