1

Here bundle.js is bundled through browserify which includes a module called webrtcsupport

<script type="text/javascript" src="/assets/js/bundle.js"></script>
<script type="text/javascript">
    var webrtcSupport = require('webrtcsupport');
    console.log(webrtcSupport.getUserMedia);
    webrtcSupport.getUserMedia();
</script>

Output in browser(Chrome browser) console:

function webkitGetUserMedia() { [native code] }
Uncaught TypeError: Illegal invocation

Why cant I invoke the above function in this manner and what is the right way of doing it?

Krupesh Kotecha
  • 2,396
  • 3
  • 21
  • 40
Aman Gupta
  • 3,627
  • 4
  • 40
  • 64

1 Answers1

2

The error "Illegal Invocation" is usually caused when the invocation context is invalid. In case of .getUserMedia() it expects the context to be of navigator.

Try webrtcSupport.getUserMedia.call(navigator, ...);

Griffith
  • 3,229
  • 1
  • 17
  • 30
  • Amazing!!! That worked.Can you explain to me what is meant by "invocation context" here? – Aman Gupta Oct 29 '15 at 13:10
  • 1
    Basically `.getUserMedia` expects its `this` to be the `navigator`, so when you invoke it through a wrapper/normalizer such as `webrtcSupport`, it throws the error because the context is wrong. – Griffith Oct 29 '15 at 13:20