Skip to content

Latest commit

 

History

History
 
 

getScreenId.js

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

getScreenId.js: Use single chrome extension for all domains!

Simply use getScreenId.js and enjoy screen capturing from any domain. You don't need to deploy chrome extension yourself. You can refer your users to install this chrome extension instead. Also, getScreenId.js auto-fallbacks to command-line based screen capturing if chrome extension isn't installed or disabled. getScreenId.js throws clear exceptions which is helpful for end-user experiences.

Demo: https://www.webrtc-experiment.com/getScreenId/

=

How to use getScreenId.js?

<script src="//cdn.WebRTC-Experiment.com/getScreenId.js"></script>
getScreenId(function (error, sourceId, screen_constraints) {
    // error    == null || 'permission-denied' || 'not-installed' || 'installed-disabled' || 'not-chrome'
    // sourceId == null || 'string'

    navigator.webkitGetUserMedia(screen_constraints, function (stream) {
        document.querySelector('video').src = URL.createObjectURL(stream);
    }, function (error) {
        console.error(error);
    });
});

Or...

getScreenId(function (error, sourceId, screen_constraints) {
    // error    == null || 'permission-denied' || 'not-installed' || 'installed-disabled' || 'not-chrome'
    // sourceId == null || 'string'

    screen_constraints = {
        video: {
            mandatory: {
                chromeMediaSource: 'screen',
                maxWidth: 1920,
                maxHeight: 1080,
                minAspectRatio: 1.77
            }
        }
    };

    if (error === 'permission-denied') return alert('Permission is denied.');
    if (error === 'not-chrome') return alert('Please use chrome.');

    if (!error && sourceId) {
        screen_constraints.video.mandatory.chromeMediaSource = 'desktop';
        screen_constraints.video.mandatory.chromeMediaSourceId = sourceId;
    }

    navigator.webkitGetUserMedia(screen_constraints, function (stream) {
        document.querySelector('video').src = URL.createObjectURL(stream);
    }, function (error) {
        console.error(error);
    });
});

=

License

getScreenId.js is released under MIT licence . Copyright (c) Muaz Khan.