muaz-khan / RTCMultiConnection

RTCMultiConnection is a WebRTC JavaScript library for peer-to-peer applications (screen sharing, audio/video conferencing, file sharing, media streaming etc.)
https://muazkhan.com:9001/
MIT License
2.57k stars 1.37k forks source link

addStream for screen via getSreenId failure callback #227

Closed emilio93 closed 8 years ago

emilio93 commented 8 years ago

Hi Muaz!

I have the following piece of code to share the screen using the screen capturing chrome extension and the getScreenId.js script.

screenshare_button.onclick = function () {
  screenshare_button.style.display = 'none'; // hide button to prevent multiple calls to extension
  connection.addStream({
    screen: true,
    oneway: true,
    streamCallback: function (screenStream) {
      screenStream.onended = function () {
        screenshare_button.style.display = 'block';
      }
    }
  });
  return false;
}

So everything goes great unless the user decides to cancel the popup to select the window to share, because the screenshare_button won't show again.

I know that by editing the getScreenId.js file I can get the behaviour I want, but I don't want to touch that file(the code above only shows the important parts, there's actually more stuff done that would need to be added to the getScreenId.js file).

Is there any work around to getting this done? Could there be another callback in the addStream method in case the user cancels the selection? I'd be keen to help, but by looking the dev files I get lost, so any recommendation on how to implement this would be appreciated!

Thanks!

muaz-khan commented 8 years ago

Maybe we should add this?

connection.addStream({
    screen: true,
    oneway: true,
    streamCallback: function(screenStream) {
        if (!screenStream) {
            alert('User did NOT select to share any stream. He clicked "Cancel" button instead.');
            return;
        }
        screenStream.onended = function() {};
    }
});

I'll add above feature in the NEXT commit.

emilio93 commented 8 years ago

Yeah that would be great! Thanks again!