screen-sharing/README.md
Ad-ons free; plugin-free; extension free; direct browser-to-browser screen sharing.
Firefox? Install Firefox Extension / Source Code
=
<script src="//cdn.webrtc-experiment.com/getScreenId.js"></script>
<script src="//cdn.webrtc-experiment.com/screen.js"></script>
=
var screen = new Screen('screen-unique-id'); // argument is optional
// on getting local or remote streams
screen.onaddstream = function(e) {
document.body.appendChild(e.video);
};
// check pre-shared screens
// it is useful to auto-view
// or search pre-shared screens
screen.check();
document.getElementById('share-screen').onclick = function() {
screen.share();
};
=
screen.userid = 'username';
=
You can use each and every signaling channel:
screen.openSignalingChannel = function(callback) {
return io.connect().on('message', callback);
};
If you want to write socket.io over node.js; here is the server code:
io.sockets.on('connection', function (socket) {
socket.on('message', function (data) {
socket.broadcast.emit('message', data);
});
});
That's it! Isn't it easiest method ever!
Want to use Firebase for signaling?
// "chat" is your firebase id
screen.firebase = 'chat';
=
screen.onscreen = function(_screen) {
var li = document.createElement('li');
li.setAttribute('user-id', _screen.userid);
li.setAttribute('room-id', _screen.roomid);
li.onclick = function() {
var _screen = {
userid: this.getAttribute('user-id'),
roomid: this.getAttribute('room-id')
};
screen.view(_screen);
};
};
onscreen is called for each new screen; and view method allows you manually view shared screens.
=
screen.leave();
=
Participants' presence can be detected using onuserleft:
// if someone leaves; just remove his video
screen.onuserleft = function(userid) {
var video = document.getElementById(userid);
if(video) video.parentNode.removeChild(video);
};
=
onaddstreamIt is called both for local and remote media streams. It returns:
video: i.e. HTMLVideoElement objectstream: i.e. MediaStream objectuserid: i.e. id of the user stream coming fromtype: i.e. type of the stream e.g. local or remotescreen.onaddstream = function(e) {
document.body.appendChild(e.video);
};
=
This WebRTC Screen Sharing experiment works fine on following web-browsers:
| Browser | Support |
|---|---|
| Firefox | 52 or higher |
| Google Chrome | 49 or higher |
| Android | latest |
| Edge | 17 or higher |
Safari-11 (on MacOSX/iOS) can merely receive screens.
=
You must enable this flag via chrome://flags.
That flag allows web pages to request access to the screen contents via the getUserMedia() API
var video_constraints = {
mandatory: { chromeMediaSource: 'screen' },
optional: []
};
navigator.webkitGetUserMedia({
audio: false,
video: video_constraints
}, onsuccess, onfailure);
=
Obviously, it is one of the most requested features; however not supported yet. Chrome WebRTC team is planning to support it in near future.
These screen sharing APIs (i.e. { chromeMediaSource: 'screen' }) allows only state-less (non-interactive) screen sharing.
=
Chrome canary denies screen capturing request automatically if:
chromeMediaSource constraint: mandatory: {chromeMediaSource: 'screen'}chromeMediaSource – it is not permitted in a single getUserMedia request.=
Remember, recursive cascade images or blurred screen is chrome's implementation issue. It will be solved soon.
mandatory: {chromeMediaSource: 'tab'} can only be useful in chrome extensions. See Tab sharing using tabCapture APIs.
=
WebRTC Screen Sharing is released under MIT licence . Copyright (c) Muaz Khan.