简体   繁体   English

如何在Android Webview上禁用webRTC?

[英]How can we disable webRTC on Android webview?

I am developing VPN app and I need to put WebRTC support menu in that. 我正在开发VPN应用程序,需要在其中添加WebRTC支持菜单。 Where user can enable and disable that option. 用户可以在其中启用和禁用该选项的位置。 But I didn't disable it in my app. 但是我没有在我的应用程序中禁用它。 I dont know how to disable it via code. 我不知道如何通过代码禁用它。

here is code please check and tell me how can resolve this. 这是代码,请检查并告诉我如何解决此问题。

mWebView.setWebChromeClient(new WebChromeClient(){
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void onPermissionRequest(final PermissionRequest request) {
            request.deny();
        }
    });

or 要么

mWebView.setWebChromeClient(null);

Permissions 权限

If you do not want to inject JS I think your solution isn't far off. 如果您不想注入JS,我认为您的解决方案就在不久的将来。 Just a bit of state management can help this. 只需一点状态管理就可以帮助您。

You need to have the AndroidManifiest and Android Permission checks at compile time and the first runtime a user uses your app because you want to allow a user to specifically allow/deny this functionality dynamically during the experience. 您需要在编译时进行AndroidManifiedt和Android权限检查,并在用户使用您的应用程序的第一个运行时进行检查,因为您希望允许用户在体验期间专门动态地允许/拒绝此功能。 Not constantly fiddle around with Android app settings / permissions. 并非经常摆弄Android应用程序设置/权限。 Going to and from settings would be rather tedious. 往返于设置将是非常乏味的。 I also presume this UX is what you are trying to avoid. 我还假定您要避免这种UX。

Thus you should do runtime checking on permissions within WebChromeClients onPermissionRequest (which is basically what you have) for when each time this is fired. 因此,您应该在每次触发时对WebChromeClients onPermissionRequest(基本上是您所拥有的)中的权限进行运行时检查。 You can use a state variable, or a white list of domains stored in the state to allow a user allows to limit this functionality and even lock it to specific domains. 您可以使用状态变量或状态中存储的域白名单,以允许用户允许限制此功能,甚至将其锁定到特定域。 You can also check specifically for RESOURCE_VIDEO_CAPTURE, etc. 您还可以专门检查RESOURCE_VIDEO_CAPTURE等。

For an example you can see how I do domain locking in my GitHub example here: https://github.com/marcusbelcher/android-getUserMedia-test see line 106 and 116. You can use a variable/state logic to block specific requests here. 例如,您可以在以下GitHub示例中看到我如何进行域锁定: https : //github.com/marcusbelcher/android-getUserMedia-test参见第106和116行。您可以使用变量/状态逻辑来阻止特定请求这里。 This is the request per session when someone fires off getUserMedia. 当有人触发getUserMedia时,这是每个会话的请求。

This is the only place at runtime you can deny/allow. 这是运行时唯一可以拒绝/允许的地方。 More info is here: 更多信息在这里:

https://github.com/googlesamples/android-PermissionRequest https://github.com/googlesamples/android-PermissionRequest

https://developer.android.com/reference/android/webkit/PermissionRequest https://developer.android.com/reference/android/webkit/PermissionRequest

JS Overrides JS覆盖

If you can / want to inject JS you can inject and override getUserMedia inside the DOM via navigator.mediaDevices.getUserMedia = undefined . 如果可以/想要注入JS,则可以通过navigator.mediaDevices.getUserMedia = undefined注入并覆盖DOM中的getUserMedia。 You could move the reference temporarily window.t = navigator.mediaDevices.getUserMedia; navigator.mediaDevices.getUserMedia = null; 您可以暂时将参考window.t = navigator.mediaDevices.getUserMedia; navigator.mediaDevices.getUserMedia = null; window.t = navigator.mediaDevices.getUserMedia; navigator.mediaDevices.getUserMedia = null; and reverse this when you would like. 并在需要时将其反转。

More info is here: 更多信息在这里:

Android webview, loading javascript file in assets folder Android Webview,在素材资源文件夹中加载javascript文件

https://medium.com/appunite-edu-collection/webview-with-injected-js-script-13eb1e0257c9 https://medium.com/appunite-edu-collection/webview-with-injected-js-script-13eb1e0257c9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM