question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Illegal invocation when using Media calls demo

See original GitHub issue

Hi @peers @michellebu I’m trying to use peerjs in my angularjs application. While trying to use the code for media call in your example,

var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
getUserMedia({video: true, audio: true}, function(stream) {
  var call = peer.call('another-peers-id', stream);
  call.on('stream', function(remoteStream) {
    // Show stream in some <video> element.
  });
}, function(err) {
  console.log('Failed to get local stream' ,err);
});

I got an error message like this: TypeError: Illegal invocation...

But if I try to use it like this, it works just fine.

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({video: true, audio: true}, function(stream) {
  var call = peer.call('another-peers-id', stream);
  call.on('stream', function(remoteStream) {
    // Show stream in some <video> element.
  });
}, function(err) {
  console.log('Failed to get local stream' ,err);
});

Not sure if this is related to the browser navigator api or just an angularjs issues. Do you have any idea? Thanks.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
hasangilakcommented, Dec 7, 2018

these sort of function needs navigator as its context. so with bind we can simply solve the problem.

  var getUserMedia = (function () {
    if(navigator.getUserMedia) {
        return navigator.getUserMedia.bind(navigator)
    }
    if(navigator.webkitGetUserMedia) {
      return navigator.webkitGetUserMedia.bind(navigator)
    }
    if(navigator.mozGetUserMedia) {
      return navigator.mozGetUserMedia.bind(navigator)
    }
  })();
1reaction
ocolotcommented, Jun 11, 2016

By the way, this issue is still in the media section of http://peerjs.com

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Uncaught TypeError: Illegal invocation" in Chrome
In your code you are assigning a native method to a property of custom object. When you call support.animationFrame(function () {}) , it...
Read more >
Illegal invocation" error thrown in js-agent.newrelic.com ...
We have a PHP integration with New Relic in our SAAS application, ... TypeError: Illegal invocation (Most recent call first) File ...
Read more >
"Illegal invocation" errors in JavaScript - Matias Kinnunen
An "illegal invocation" error is thrown when calling a function whose this keyword doesn't refer to the object where it originally did. In...
Read more >
"Uncaught TypeError: Illegal invocation" on click handler
produces this error. Seems like a bug, either in highcharts or jquery. I'm using jQuery version 1.6.2 and HighCharts version 2.1.6.
Read more >
TypeError: 'open' called on an object that does not implement ...
Uncaught TypeError: illegal Invocation ... rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found