Simple WebRTC Not Working

1,563 views
Skip to first unread message

Ray Jender

unread,
Jan 12, 2020, 3:21:08 PM1/12/20
to discuss-webrtc

I have been away from playing with WebRTC for quite awhile, but I am back.

I am trying to code a simple example of using MediaStream API  "getUserMedia" but I'll be damned if I can figure out why it's not working!

I have the following code on my Linode server with Apache2 running - http://streamingworld.us

It's probably something very simple and I'll be kickng myself when you tell me.

Here is the html:

<!DOCTYPE html> <html lang = "en">
 
   
<head>
     
<meta charset = "utf-8" />
   
</head>
       
   
<body>
     
<video autoplay></video>
     
<script src = "client.js"></script>
   
</body>
       
</html>


And here us the javascript client.js:


function hasUserMedia() {    //check if the browser supports the WebRTC
   
return !!(navigator.mediaDevices.getUserMedia || navigator.webkitGetUserMedia ||
      navigator
.mozGetUserMedia);
}
 
if (hasUserMedia()) {
   navigator
.mediaDevices.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia
     
|| navigator.mozGetUserMedia;
               
   
//enabling video and audio channels
   navigator
.mediaDevices.getUserMedia({ video: true, audio: true }, function (stream) {
     
var video = document.querySelector('video');
               
     
//inserting our stream to the video tag    
      video
.src = window.URL.createObjectURL(stream);
   
}, function (err) {});
} else {
   alert
("WebRTC is not supported");
}



The response I get it:  WebRTC is not supported

What am I doing wrong?

Thanks.

Ray

Thomas Greenwood

unread,
Jan 12, 2020, 5:14:40 PM1/12/20
to discuss...@googlegroups.com
I think perhaps it's because it's an insecure domain.

HTH

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/36537a17-1b43-493f-8aa1-9f41d25a4cd8%40googlegroups.com.

Ray Jender

unread,
Jan 13, 2020, 7:43:15 AM1/13/20
to discuss-webrtc
To unsubscribe from this group and stop receiving emails from it, send an email to discuss...@googlegroups.com.

Thomas Greenwood

unread,
Jan 13, 2020, 8:53:51 AM1/13/20
to discuss...@googlegroups.com
Hi Ray

Sorry I didn't see any response.  If you're unsure you need to use HTTPS to make WebRTC work.  There are quite a few free services for certificates that you should be able to use.

HTH


To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/1c58113b-581a-4430-a238-369c2229a067%40googlegroups.com.

S To

unread,
Mar 8, 2020, 4:51:22 AM3/8/20
to discuss-webrtc
This has nothing to do with insecure sites. I tried the same code using it on a properly configured OpenSSL server.

I think the code he is using is deprecated in newer updated browsers since I also have the same issue. The code is old coming from around 2015.

There is newer standards for webrtc codes and functions, I'm able to use the getusermedia function properly using the newer codes.

Thomas Greenwood

unread,
Mar 8, 2020, 5:10:53 AM3/8/20
to discuss...@googlegroups.com
Hi

Yes I suspect something else might be wrong. It's probably worth using promises for getusermedia and setting the video source can be done by video.srcObject = stream. If you need some sample code I think you could try here https://github.com/webrtc/samples/blob/gh-pages/src/content/getusermedia/gum/js/main.js

However you can't use getusermedia on insecure sites now - which was probably the biggest change since 2015 and the OP needed a secure site to make this work. The original url provided was http:

HTH

To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/3c388c61-f194-47ed-8a53-1a1d87f5e35a%40googlegroups.com.

Akil

unread,
Mar 11, 2020, 3:20:25 AM3/11/20
to discuss-webrtc
As Tom mentioned, There are a few issues in the code
  1. On chrome at-least, navigator.mediaDevices is undefined on http sites, it only works on https sites, that is the cause of the "WebRTC is not supported" alert
  2. navigator.mediaDevices.getUserMedia returns a promise, it does not use callbacks
  3. For WebRTC streams, use video.srcObject rather than video.src
Reply all
Reply to author
Forward
0 new messages