muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.74k stars 3.95k forks source link

Minimal screen sharing setup from tutorial doesn't work #115

Open kooler opened 10 years ago

kooler commented 10 years ago

Hello,

I'm trying to use minimal setup to enable screen sharing according to: https://github.com/muaz-khan/WebRTC-Experiment/tree/master/screen-sharing but unfortunately it doesn't work -- screen stream added to user that shares it but nothing happens on receiving side.

Code I use:

var screen = new Screen('screen-unique-id');

// on getting local or remote streams
screen.onaddstream = function(e) {
    document.body.appendChild(e.video);
};

screen.firebase = 'signaling';

// 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-name');
};

You can check it online here: https://dl.dropboxusercontent.com/u/178301/screen.html

muaz-khan commented 10 years ago

Try same demo here; and it is working. Try this one too:


<html>
<body>
<script src="https://www.webrtc-experiment.com/screen-sharing/screen.js"></script>
<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<button id='share-screen'>Share Your Screen</button>
<script>
var screen = new Screen();
screen.onaddstream = function (e) {
    document.body.appendChild(e.video);
};

// using firebase for signaling
screen.firebase = 'chat';

// check pre-shared screens
screen.check();

document.getElementById('share-screen').onclick = function () {
    screen.share();
    this.disabled = true;
};
</script>
</body>
</html>

You need to use same screen-name for share and check methods:

screen.check('aaa');
screen.share('aaa');

// or 
screen.check('bbb');
screen.share('bbb');

// or otherwise, pass directly to the constructor
var screen = new Screen('screen-unique-identifier');
screen.check();
screen.share();