0

I have an odd problem with code that works in Chrome, but not Firefox. For whatever reason, it says that the variable (success) is undefined, even though it is clearly defined before the function is ever called. Take a look:

createRoom.addEventListener('click',function(e){
            e.preventDefault();
            var success = function(myStream){
                ownVideo.src = URL.createObjectURL(myStream);
                // create a room
                WebRTC.createRoom();
            };
            navigator.getUserMedia({audio: true, video: true}, gotStream, gotError);
        });

After success is defined, I run getUserMedia which, upon running successfully will run gotStream, which will then run success. Why won't Firefox accept the definition of success? Halp.

kelbirk
  • 5
  • 3
  • Most likely getStream doesn't know what success is. Success appears to be defined in a different scope than getStream. – dpk2442 Jun 14 '14 at 03:08
  • 1
    You don't show where you are trying to access `success`. – Felix Kling Jun 14 '14 at 03:58
  • You need to pass `success` as an argument to your function, your function doesn't just *know* what `success` is. There could be a million variables in different scopes in your app all called `success`. – user229044 Jun 14 '14 at 04:02
  • possible duplicate of [how to make getUserMedia() work on all browsers](http://stackoverflow.com/questions/21015847/how-to-make-getusermedia-work-on-all-browsers) – Muath Jun 15 '14 at 09:36

1 Answers1

0

according to mozila,

// you code should be     
navigator.getUserMedia({audio: true, video: true}, success, gotError);

may be, function gotStream is running for chrome.

here is the running sample from Mozila's reference page :

navigator.getUserMedia = ( navigator.getUserMedia ||
                   navigator.webkitGetUserMedia ||
                   navigator.mozGetUserMedia ||
                   navigator.msGetUserMedia);

if (navigator.getUserMedia) {
    navigator.getUserMedia (

  // constraints
  {
     video: true,
     audio: true
  },

  // successCallback
  function(localMediaStream) {
     var video = document.querySelector('video');
     video.src = window.URL.createObjectURL(localMediaStream);
     // Do something with the video here, e.g. video.play()
  },

  // errorCallback
  function(err) {
     console.log("The following error occured: " + err);
   }
  );
} else {
   console.log("getUserMedia not supported");
}
Nafis Ahmad
  • 2,689
  • 2
  • 26
  • 13