All Projects → muaz-khan → getScreenId

muaz-khan / getScreenId

Licence: MIT License
getScreenId | Capture Screen on Any Domain! This script is a hack used to support single chrome extension usage on any HTTPs domain.

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to getScreenId

docker-nvidia-glx-desktop
MATE Desktop container designed for Kubernetes supporting OpenGL GLX and Vulkan for NVIDIA GPUs with WebRTC and HTML5, providing an open source remote cloud graphics or game streaming platform. Spawns its own fully isolated X Server instead of using the host X server, therefore not requiring /tmp/.X11-unix host sockets or host configuration.
Stars: ✭ 47 (-20.34%)
Mutual labels:  webrtc
sdp
A Go implementation of the SDP
Stars: ✭ 89 (+50.85%)
Mutual labels:  webrtc
dtls
Datagram Transport Layer Security (DTLS) client.
Stars: ✭ 72 (+22.03%)
Mutual labels:  webrtc
sdp-anatomy
Source code for webrtcHacks' Anatomy of a SDP
Stars: ✭ 60 (+1.69%)
Mutual labels:  webrtc
udpeer
A simple UDP peer to peer networking proxy using webrtc
Stars: ✭ 19 (-67.8%)
Mutual labels:  webrtc
WebRTC-Flask-server
WebRTC demo using flask for routing.
Stars: ✭ 34 (-42.37%)
Mutual labels:  webrtc
ion-avp
Audio/Video Processing Service
Stars: ✭ 55 (-6.78%)
Mutual labels:  webrtc
webrtcsink
All-batteries included GStreamer WebRTC producer
Stars: ✭ 18 (-69.49%)
Mutual labels:  webrtc
easy-voice-call
A self-hosting voice chating App
Stars: ✭ 30 (-49.15%)
Mutual labels:  webrtc
gise-video-chat
Video chat application for your own web server
Stars: ✭ 48 (-18.64%)
Mutual labels:  webrtc
Tubumu.Abp.Meeting
An abp module to create meeting app quickly.
Stars: ✭ 15 (-74.58%)
Mutual labels:  webrtc
baresip-webrtc
Baresip WebRTC Demo
Stars: ✭ 33 (-44.07%)
Mutual labels:  webrtc
Xamarin.Agora.Samples
Agora.io samples for Xamarin.iOS, Xamarin.Android, Xamarin.MacOS and Xamarin.Forms
Stars: ✭ 41 (-30.51%)
Mutual labels:  webrtc
Diffy
🎞️💓🍿 Love streaming - It's always best to watch a movie together ! 🤗
Stars: ✭ 37 (-37.29%)
Mutual labels:  webrtc
visual-ts-game-engine
Typescript project based on matter.ts implementation."This version 2 of visualjs game engine, totally different approach. Whole project is based fully dependency build. Main file is app.ts and ioc.ts. Class ioc saves singleton instances also bind. In this project html and css is also present, webpack helps and handle this type of files. GamePlay…
Stars: ✭ 15 (-74.58%)
Mutual labels:  webrtc
node-sctp
SCTP userspace sockets for Node.js
Stars: ✭ 47 (-20.34%)
Mutual labels:  webrtc
webrtc-stats
Helps you collect stats for peer connections
Stars: ✭ 31 (-47.46%)
Mutual labels:  webrtc
Dockerfiles
Optimized media, analytics and graphics software stack images. Use the dockerfile(s) in your project or as a recipe book for bare metal installation.
Stars: ✭ 98 (+66.1%)
Mutual labels:  webrtc
loowid
Webconference solution based on webrtc
Stars: ✭ 92 (+55.93%)
Mutual labels:  webrtc
classroom-demo
Full web application (Angular 7 + Spring Boot 2 + MySQL) making use of OpenVidu
Stars: ✭ 50 (-15.25%)
Mutual labels:  webrtc

getScreenId | Capture Screen on Any Domain!

getScreenStream(function(screenStream) {
    video.srcObject = screenStream;
});

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);
            });
        });
    }
}

npm downloads

  1. Install this: https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk
  2. Now use below codes on any HTTPs domain.
  3. Remember, HTTPs is required.
  4. getScreenId gives you "MediaStream" object; you can share that object with other users using AppRTC demo, SimpleWebRTC or EasyRTC or PeerJs libraries, or any standalone peer-to-peer demo.
  5. In simple words, you have to use RTCPeerConnection API along with getScreenId to share screen with other users.
npm instll webrtc-screen-capturing

Hacking to use single chrome-extension on any domain!

<!--
* This script is a hack used to support single chrome extension usage on any domain.

* This script has issues, though.
* It uses "postMessage" mechanism which fails to work if someone is using it from inside an <iframe>.
* The only solution for such cases is, use WebSockets or external servers to pass "source-ids".
-->

You don't need to PUBLISH/deploy your own chrome-extension when using this script!

LocalHost server

node server.js

Nope open: https://localhost:9001/

How to use?

<script src="https://cdn.WebRTC-Experiment.com/getScreenId.js"></script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>

<video controls autoplay playsinline></video>

getScreenId

This method allows you get chrome-media-source-id; which can be used to capture screens.

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

    if(navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob)) {
        navigator.getDisplayMedia(screen_constraints).then(stream => {
            document.querySelector('video').srcObject = stream;
        }, error => {
            alert('Please make sure to use Edge 17 or higher.');
        });
        return;
    }

    if(error == 'not-installed') {
      alert('Please install Chrome extension.');
      return;
    }

    navigator.mediaDevices.getUserMedia(screen_constraints).then(function (stream) {
        document.querySelector('video').srcObject = stream;

        // share this "MediaStream" object using RTCPeerConnection API
    }).catch(function (error) {
      console.error('getScreenId error', error);

      alert('Failed to capture your screen. Please check Chrome console logs for further information.');
    });
});

Or...

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

    if(sourceId && sourceId != 'firefox') {
        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.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
    navigator.getUserMedia(screen_constraints, function (stream) {
        document.querySelector('video').src = URL.createObjectURL(stream);

        // share this "MediaStream" object using RTCPeerConnection API
    }, function (error) {
      console.error('getScreenId error', error);

      alert('Failed to capture your screen. Please check Chrome console logs for further information.');
    });
});

getChromeExtensionStatus

This method allows you detect whether chrome extension is installed or not:

getChromeExtensionStatus(function(status) {
    if (status === 'installed-enabled') alert('installed');
    if (status === 'installed-disabled') alert('installed but disabled');
    // etc.
});

How it works?

  • Your script will make a postMessage request to getScreenId.js
  • getScreenId.js will connect with chrome-extension using an internal <iframe>.
  • That <iframe> is loaded from domain: https://www.webrtc-experiment.com/
  • 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.

Custom Parameter

Pass second argument to getScrenId method:

  • true means that capture system audio i.e. speakers
  • [] array means that capture custom array items
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

Deploy extension yourself?

Alternative?

Disclaimer

There is no warranty, expressed or implied, associated with this product. Use at your own risk.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].