Access camera or webcam without webRTC

2024/2/26 8:31:36

In my website, it needs to access camera or webcam. But webRTC is not supported yet on ios webview based on https://forums.developer.apple.com/thread/88052 (please cmiiw). So, I'm trying to find a way to access it without webRTC. Is there any?

  1. And is this following code, a part of utilizing webRTC? Because the console.log shows up on ios webview

    function hasGetUserMedia() {return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
    }//then, somewhere in the code
    if (!hasGetUserMedia()) {           console.log( "webRTC is not supported in your browser" );//it shows up on ios webview              
    }//other code
    navigator.mediaDevices.getUserMedia({audio: false, //no audiovideo: {deviceId: {exact: videoSource.camera_id} }
    })
    
  2. If yes, so what's the workaround which not using webRTC, and can be run on android webview, ios webview, and web browsers?

Answer

2021 Edit:

We now have access to getUserMedia on iOS WebViews!


The Good News:

As of iOS 14.3, iOS now allows access to getUserMedia in a WKWebView

Whenever I have questions about browser features like this, I find it very helpful to check out caniuse.com. In this case, there is a note on the entry for Safari & Chrome for iOS

Before iOS 14.3 getUserMedia returned no video input devices in UIWebView or WKWebView, but only directly in Safari

The Old News:

Prior to 2021, we could not access getUserMedia on iOS outside of Safari. So back then, a workaround was to build a website and direct iOS users to visit the site in Safari instead of making a native app for iOS.

The Other News:

getUserMedia controls access to a user's camera and microphone, whereas WebRTC helps you send that audio/video to another client, like in a video chat. Here you're stuck on getting the video in the first place so you don't need to worry about WebRTC yet, but when you do, I recommend you check out This article that helped me.

And if you want to test getUserMedia or WebRTC functions yourself, try using These provided samples, so that you can be sure that it is not the fault of your own code :)

http://en.ppmy.cn/q/41344.html

Related Q&A

Java eqivalent method of splice(a,b,...) in JavaScript method

someArray.splice(a,b,...) method in JavaScript adds or removes items to/from array. What could be good and simple solution to implement such method in Java language? Assume we have String[] array.

Expressjs bodyParser and connect-form

Im uploading images with connect form. But it does not work if I use the bodyParser(). And the other way around, if i dont use the bodyParser, i cant upload files? How do I make them play together? H…

Highlight multiple items on hovers condition

Okay sorry for the title, wasnt too sure how to phrase it.So we have a project going, and we are offering multiple incentives depending on what people donate (similar to Kickstarter if you know what th…

Cache results for functions?

In Javascript, is there a way to cache results for functions that are:a). Computationally expensive. b). Called multiple times.Take for example a recursive factorial function that gets called frequentl…

Poor time performance of rake assets:precompile

Running:bundle exec rake assets:precompile RAILS_ENV=productionTakes about 6 minutes for 15 .js files of about 250kb total. It should not take this long surely? I see the Microsoft Console Based Scr…

How do I extract the metadata of a local image in Javascript?

I would like to get the metadata of an image that a user drags and drops into a webpage. I have the drag and drop set up. However, the image isnt actually uploaded to a server. Its accessed locally. Ca…

Updating localstorage arrays in Javascript

Im trying to store and update an array in the localstorage using JSON.parse/stringify. But it doesnt seem to be working.yesArray = JSON.parse(localStorage.getItem(yesArray));yesArray.push("yes&quo…

JavaFX WebView up call from JavaScript doesnt work

I have a JavaFX WebView and want to call the method "hello" of the class "JavaBridge" from "test.html" displayed in the webview. Why doesnt this work? I making sure that…

Want to fire Dropdown SelectedIndexChanged Event in Javascript

I have dropdown on my page, I am changing selected value of dropdown from popup window using Javascript. I have some logic in dropdown SelectedIndexChanged event, so I need to fire the SelectedIndexCha…

How to have controllers in separate file in AngularJS

I look around a bit and didnt find an answer that fit with my current situation. I have a app.js file:use strict;var demoApp = angular.module(demoApp, [// Dpendances du "module" <-- demoAp…