Temasys / SkylinkJS

SkylinkJS Javascript WebRTC SDK
http://skylink.io/web
Other
275 stars 57 forks source link

Skylink getUserMedia throwing errors instead of using error callbacks #152

Closed MichaelJCole closed 8 years ago

MichaelJCole commented 8 years ago

Hey, I'm using getUserMedia() to get the screen.

Unless I'm misunderstanding, I noticed the Skylink code is throwing exceptions, instead of using the callbacks. This means my error callbacks are not happening which is a bummer.

Here's an excerpt from skylink.complete.js:

            delete updatedConstraints.video.mediaSource;

            baseGetUserMedia(updatedConstraints, successCb, failureCb);

          } else {
            if (error === 'permission-denied') {
              throw new Error('Permission denied for screen retrieval');
            } else {
              throw new Error('Failed retrieving selected screen');
            }
          }
        };

Based on what I've learned about async error handling, those thrown errors cannot be caught.

I would expect more this behavior:

            delete updatedConstraints.video.mediaSource;

            baseGetUserMedia(updatedConstraints, successCb, failureCb);

          } else {
            if (error === 'permission-denied') {
              failureCb('Permission denied for screen retrieval');  // Use the callback, not an exception
            } else {
              failureCb('Failed retrieving selected screen');    // Use the callback, not an exception
            }
          }
        };

You could wrap the whole thing in a try{} catch(){}, but that gets tricky. If I'm misunderstanding please let me know. Here's my use case that isn't working:

  getScreen: function() {
console.log('getScreen');
    Helpers.connectForm.state.set('checkedScreen', true);

    navigator.getUserMedia({video: {mediaSource: 'window'}}, function(stream) {
console.log(screen);
      var vid = document.getElementById('browserCheck');
      attachMediaStream(vid, stream);
      Helpers.connectForm.state.set('canScreen', true);
    }, function(error) {
console.log(error);
      // Note: this is not being called for permission denied.  FIXME.
      Helpers.connectForm.state.set('canScreen', false);
    });
  },

The function is intended to check if the user can share the screen. If so, attach it to browserCheck video.

Otherwise, set some state so the form can react. Somewhere else shows the user a message based on the state of checkedScreen an canScreen

In the console I see:

getScreen
>

In Chrome, the share dialog comes up, I share the screen, but neither of my callbacks get called function(stream) or function(error)

I am successfully getting mic and camera in another prior navigator.getUserMedia() call. getScreen() is called from clicking a button.

How are you testing and catching these thrown exceptions? Am I missing something?

Thanks for any help!

MichaelJCole commented 8 years ago

Tried this code but it doesn't work either. The callback is never called.

  getScreen: function() {
    console.log(Helpers.connectForm.skylink.shareScreen);
    Helpers.connectForm.state.set('checkedScreen', true);
    Helpers.connectForm.skylink.shareScreen(function(error, success) {
      if (error){
        console.log(error);
      } else {
        console.log(success);
      }
    });
  },

I see the shareScreen function and can read it.

Stepping through the code, these breakpoints are never triggered:

  try {
    window.getUserMedia(settings, function (stream) {
      self.once('mediaAccessSuccess', function (stream) {  // breakpoint never triggered
        if (self._inRoom) {           // breakpoint never triggered

shareScreen does work if it's called in Meteor's Template.templateName.onCreated() function, but not in these event handlers.

PS. For whatever reason the event mediaAccessSuccess is not being triggered.

ncurrier commented 8 years ago

Our next update of AdapterJS should address this issue for the most part. I will update here when that has been published, should be out in the next few days.

MichaelJCole commented 8 years ago

Awesome! Thanks!

oooookk7 commented 8 years ago

This should return an error in the shareScreen callback instead of throwing in the console

https://github.com/Temasys/SkylinkJS/releases/tag/0.6.4

oooookk7 commented 8 years ago

Hi @MichaelJCole, I would like to check if the 0.6.4 release did fix the issue you have. Does it still occur for you?

MichaelJCole commented 8 years ago

Hey Leticia, thanks for checking in. I switched to SimpleWebRTC with a Xirsys backend.

oooookk7 commented 8 years ago

Thanks for the response, we will be closing this ticket then.