android棒棒糖webrtc webview应用程序

时间:2018-01-16 11:36:03

标签: android webview webrtc

他一点儿。我尝试根据lollipop API 22设备测试我的应用程序。

作为测试,我制作了一个webview并尝试连接到网址“https://appr.tc/r/xxxxx”。

在我的webview中,我可以看到我的前置摄像头预览,appr服务器消息(按钮名为joint ....等等)..但是如果尝试建立RTC对等聊天,我会收到以下错误:

  

https://appr.tc处的页面说:无法创建rtcpeerconnection:   undefined不是函数

我在.grandle上有这些行......

implementation 'org.webrtc:google-webrtc:1.0.+'

我有这些明确的许可......

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature android:name="android.hardware.location.gps" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.webkit.PermissionRequest" />

    <meta-data android:name="android.webkit.WebView.MetricsOptOut"
        android:value="true" />
    <meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
        android:value="true" />

我有这些java代码用于实现webview chrome ...

public class CameraViewFrag extends Fragment {
    private static final String TAG = "CameraViewFrag";
    private WebView mWebView;
    private String url = "https://appr.tc/r/658450307";
    private Button goOnButton;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_camera_view,container,false);

        goOnButton = (Button) view.findViewById(R.id.gotoButton);
        mWebView = (WebView) view.findViewById(R.id.webview);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportMultipleWindows(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setLoadWithOverviewMode(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            webSettings.setSafeBrowsingEnabled(true);
        }

        goOnButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mWebView.getSettings().setLoadsImagesAutomatically(true);
                mWebView.getSettings().setLoadWithOverviewMode(true);
                mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
                mWebView.setScrollbarFadingEnabled(true);
                mWebView.getSettings().setAllowFileAccess(true);
                mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
                mWebView.getSettings().setDomStorageEnabled(true);
                mWebView.getSettings().setAppCacheEnabled(true);
                mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
                //carichiamo finalmete la url
                mWebView.setWebChromeClient(new WebChromeClient(){
                    // Need to accept permissions to use the camera
                    @Override
                    public void onPermissionRequest(final PermissionRequest request) {
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                request.grant(request.getResources());
                            }
                        });
                    }
                });
                mWebView.loadUrl(url);
            }
        });







        return view;
    }
}

cose是洞察力片段......

我没有看到我的错误,直到现在堆栈上都没有找到这种错误的答案....

抱歉...我添加了logcat的有趣部分:

01-16 12:00:36.627 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "4.864: Opening signaling channel.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.007 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.274: Joined the room.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.169 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.444: Signaling channel opened.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.169 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.445: Registering signaling channel.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.171 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.445: Signaling channel registered.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.172 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.450: Starting signaling.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.173 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.455: Creating RTCPeerConnnection with:
                                                                                 config: '{"rtcpMuxPolicy":"require","bundlePolicy":"max-bundle","iceServers":[{"urls":["turn:74.125.143.127:19305?transport=udp","turn:[2607:f8b0:400d:c09::7f]:19305?transport=udp","turn:74.125.143.127:443?transport=tcp","turn:[2607:f8b0:400d:c09::7f]:443?transport=tcp"],"username":"CNDZ/NIFEgbJSf4StDgYzc/s6OMTIICjBQ","credential":"P6ssOSIPA2wBBQMHXiDa9BEsJUI="},{"urls":["stun:stun.l.google.com:19302"]}]}';
                                                                                 constraints: '{"optional":[]}'.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.204 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.487: Created PeerConnectionClient", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.207 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.491: Adding local stream.", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.214 12598-12598/com.example.bleahkthe.test I/chromium: [INFO:CONSOLE(5590)] "5.499: Create PeerConnection exception: TypeError: undefined is not a function", source: https://appr.tc/js/apprtc.debug.js (5590)
01-16 12:00:37.296 12598-12615/com.example.bleahkthe.test D/ufoEGL: Pixel Format : GGL_PIXEL_FORMAT_RGBA_8888
01-16 12:00:39.710 12598-12615/com.example.bleahkthe.test D/ufoEGL: Surface destroy: ANDROID_NATIVE_WINDOW_MAGIC
01-16 12:00:39.714 12598-12615/com.example.bleahkthe.test D/OpenGLRenderer: endAllStagingAnimators on 0xce92f800 (RippleDrawable) with handle 0xde6cc030
01-16 12:00:46.322 12598-12615/com.example.bleahkthe.test D/ufoEGL: Pixel Format : GGL_PIXEL_FORMAT_RGBA_8888
01-16 12:00:48.255 12598-12598/com.example.bleahkthe.test I/art: Explicit concurrent mark sweep GC freed 47570(3MB) AllocSpace objects, 4(61KB) LOS objects, 40% free, 6MB/10MB, paused 695us total 54.479ms
01-16 12:00:48.260 12598-12598/com.example.bleahkthe.test I/art: System.exit called, status: 0
01-16 12:00:48.262 12598-12598/com.example.bleahkthe.test I/AndroidRuntime: VM exiting with result code 0, cleanup skipped.

问候 BKT

1 个答案:

答案 0 :(得分:0)

这是因为webview具有默认浏览器的属性,如果默认浏览器不是chrome,则不支持。要求浏览器打开网址。并选择chrome来进行webrtc调用。