Android Question WebRtc and WebView

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello all,

this thread was suggested by @Erel , after fixed a https problem in a webview in this https://www.b4x.com/android/forum/threads/problem-with-https-and-webview.98535/#post-620911 ...

Ok, let's go: I'm trying to open a site similar to this: https://rtcmulticonnection.herokuapp.com/demos/Video-Conferencing.html ... in a webview.

But when clicking the "open room" button in the webview there is no result, besides this woks fine in smartphone browser. I thought that WebView behavior was something similar to a embedded browser in an app, but it looks that there are some limitations.
If I could run this site would get at least a great advantage of reusing the same code for web and app... could anybody help me?

Thanks!
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Test it with other WebRTC servers. Hopefully they will provide more information.

Make sure to monitor the unfiltered logs.
Thanks @Erel . I noticed that the problem was in javascript: something that runs on mobile browser doesn't in webview, I didn't find exactly what but I wrote a new JS and worked! A good tool in this situations could be a way to debug js in webview: is there some?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You should never post in an existing thread. Always start a new thread for your question.
 
Upvote 0

deantangNYP

Active Member
Licensed User
Longtime User
got this error when i select [start] in the app. What does it mean?
Thanks
 

Attachments

  • Screenshot_2019-01-10-13-28-11.png
    Screenshot_2019-01-10-13-28-11.png
    137.3 KB · Views: 1,041
Upvote 0

giada

Member
The attached example successfully starts a WebRTC session with: https://janus.conf.meetecho.com/echotest.html
Hi Erel,
i try your example on B4XPages but i have problem with the permission, the code is the same...what's the problem?
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    
    Private rp As RuntimePermissions

    Private WebView1 As WebView
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
            Dim client As JavaObject
            client.InitializeNewInstance(Application.PackageName & ".main$MyChromeClient", Null)
            Dim jo As JavaObject = WebView1
            jo.RunMethod("setWebChromeClient", Array(client))
            
            WebView1.LoadUrl("https://janus.conf.meetecho.com/echotest.html")

        End If
    End If
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub Button1_Click
    WebView1.LoadUrl("https://janus.conf.meetecho.com/echotest.html")
End Sub

#if Java
import android.webkit.*;
public static class MyChromeClient extends WebChromeClient {
@Override
     public void onPermissionRequest(PermissionRequest request) {
        request.grant(request.getResources());
    }
}
#End If
 
Upvote 0

giada

Member
Wait For B4XPage_PermissionResult (...
thank's, now the permission is ok but i have an error on "MyChromeClient"
B4X:
b4xmainpage$ResumableSub_B4XPage_Createdresume (java line: 120)
java.lang.ClassNotFoundException: b4a$example$main$MyChromeClient
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at java.lang.Class.forName(Class.java:379)
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:273)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:83)
    at b4a.example.b4xmainpage$ResumableSub_B4XPage_Created.resume(b4xmainpage.java:120)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8107)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.ClassNotFoundException: b4a$example$main$MyChromeClient
    ... 16 more
b4xmainpage$ResumableSub_B4XPage_Createdresume (java line: 120)
java.lang.ClassNotFoundException: b4a$example$main$MyChromeClient
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at java.lang.Class.forName(Class.java:379)
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:273)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:83)
    at b4a.example.b4xmainpage$ResumableSub_B4XPage_Created.resume(b4xmainpage.java:120)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8107)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.ClassNotFoundException: b4a$example$main$MyChromeClient
    ... 16 more

Is related to ".main$MyChromeClient" and instead i have a b4xpages?
 
Upvote 0

giada

Member
Hi Erel,
i have a problem on the example : the local stream is ok but in the remote stream video(audio is ok) in not working, i have a permanent loader...i try to call the page from chrome and here works, what's the problem?
thanks
I also tested the example on another device and works, what can i do?
 
Last edited:
Upvote 0

giada

Member
I found a similar problem integrating jitsi on a webview: a meet with 2 partecipant works, adding other partecipant put the video of all partecipant on pause, only putting one partecipant on the foreground works it's video, can you suggest me something?
 
Upvote 0
Top