VoIP SIP (Voice Calls) System : Source Code

MarcoRome

Expert
Licensed User
Longtime User
Hi Saif, All
So I tried to set requestpermission again.
Otherwise, it is not possible to enter it on the Play Store.
This is the Manifest:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddPermission(android.permission.USE_SIP)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.RECORD_AUDIO)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(android.permission.VIBRATE)
AddPermission(android.permission.PROCESS_OUTGOING_CALLS)
AddPermission(android.permission.READ_PHONE_STATE)

'-----New
AddPermission(android.permission.CONFIGURE_SIP)
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false"/>)
AddManifestText(<uses-feature android:name="android.software.sip" android:required="true" />)
AddManifestText(<uses-feature android:name="android.software.sip.voip" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.microphone" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.wifi" android:required="true" />)


SetApplicationAttribute(android:usesCleartextTraffic, "true")

This is the code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    If File.Exists(File.DirInternal,"db.db") =  False Then
        File.Copy(File.DirAssets,"db.db",File.DirInternal,"db.db")
        
    End If
    SQl1.Initialize(File.DirInternal,"db.db",False)
    
    GrantPermission

End Sub

Sub Activity_Resume

End Sub

Sub GrantPermission
    Try
        
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_USE_SIP)
        Wait For Activity_PermissionResult (permission As String, Result As Boolean)
        If Result Then
            Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_RECORD_AUDIO)
            Wait For Activity_PermissionResult (permission As String, Result As Boolean)
            If Result Then
                Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_PROCESS_OUTGOING_CALLS)
                Wait For Activity_PermissionResult (permission As String, Result As Boolean)
                    If Result Then
                    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_PHONE_STATE)
                    Wait For Activity_PermissionResult (permission As String, Result As Boolean)
                    If Result Then
                        Add_FieldToDB       
                        StartService(srvVoIPSIP) '--- SHould start after the permission
                        StartActivity(MainMenu)
                        Activity.Finish
                    End If
                End If
            End If
        End If
                
        
    Catch
        Log(LastException)
    End Try
End Sub

It arrives on Sip.Register and no events are triggered
Any idea ?
Thank you
 

sfsameer

Well-Known Member
Licensed User
Longtime User
Hi Saif, All
So I tried to set requestpermission again.
Otherwise, it is not possible to enter it on the Play Store.
This is the Manifest:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddPermission(android.permission.USE_SIP)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_WIFI_STATE)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.RECORD_AUDIO)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(android.permission.VIBRATE)
AddPermission(android.permission.PROCESS_OUTGOING_CALLS)
AddPermission(android.permission.READ_PHONE_STATE)

'-----New
AddPermission(android.permission.CONFIGURE_SIP)
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false"/>)
AddManifestText(<uses-feature android:name="android.software.sip" android:required="true" />)
AddManifestText(<uses-feature android:name="android.software.sip.voip" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.microphone" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.wifi" android:required="true" />)


SetApplicationAttribute(android:usesCleartextTraffic, "true")

This is the code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    If File.Exists(File.DirInternal,"db.db") =  False Then
        File.Copy(File.DirAssets,"db.db",File.DirInternal,"db.db")
       
    End If
    SQl1.Initialize(File.DirInternal,"db.db",False)
   
    GrantPermission

End Sub

Sub Activity_Resume

End Sub

Sub GrantPermission
    Try
       
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_USE_SIP)
        Wait For Activity_PermissionResult (permission As String, Result As Boolean)
        If Result Then
            Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_RECORD_AUDIO)
            Wait For Activity_PermissionResult (permission As String, Result As Boolean)
            If Result Then
                Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_PROCESS_OUTGOING_CALLS)
                Wait For Activity_PermissionResult (permission As String, Result As Boolean)
                    If Result Then
                    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_PHONE_STATE)
                    Wait For Activity_PermissionResult (permission As String, Result As Boolean)
                    If Result Then
                        Add_FieldToDB      
                        StartService(srvVoIPSIP) '--- SHould start after the permission
                        StartActivity(MainMenu)
                        Activity.Finish
                    End If
                End If
            End If
        End If
               
       
    Catch
        Log(LastException)
    End Try
End Sub

It arrives on Sip.Register and no events are triggered
Any idea ?
Thank you
We would like to connect with you using anydesk same as yesterday to inspect the problem if that's okay with you :)
Send me the ID via private message
 

MarcoRome

Expert
Licensed User
Longtime User
We would like to connect with you using anydesk same as yesterday to inspect the problem if that's okay with you :)
Send me the ID via private message
Thank you Saif. For me now isnt possible. But i send you ( email ) an example already set up like this.
 

sfsameer

Well-Known Member
Licensed User
Longtime User
Thank you Saif. For me now isnt possible. But i send you ( email ) an example already set up like this.
It's okay, later when you do have the time just let us know and we will connect with you right away.
And we can't test it because we don't have android 12 so we are not sure where or why it's failing to register

:)
 

MarcoRome

Expert
Licensed User
Longtime User
It's okay, later when you do have the time just let us know and we will connect with you right away.
And we can't test it because we don't have android 12 so we are not sure where or why it's failing to register

:)
Thank you Saif.
These days we are delivering a system and therefore it is not possible. But I will definitely notify you next week so that I can take the test.
I experienced the same problem it also has on Android 11.
For the moment Thanks and Good Work
 

amorosik

Expert
Licensed User
Hello,

in SIP you are able to contact other clients even if they are not registered on the same server, it's very possible.

More information :

Thank you,
Saif

I am trying to initiate a telephone call from a B4A sip client, as in Voip Sip System project, to a telephone connected to the public telephone network
Re-reading your advice, I should locate the uri address of the phone at which I want to initiate the 'invite' command
I seem to have understood that a 'redirect server' must be queried to get the address of the destination phone in response
But how to understand which 'redirect servers' are available?
And once the address of the destination phone is obtained, how to initiate the call?
 

sfsameer

Well-Known Member
Licensed User
Longtime User
I am trying to initiate a telephone call from a B4A sip client, as in Voip Sip System project, to a telephone connected to the public telephone network
Re-reading your advice, I should locate the uri address of the phone at which I want to initiate the 'invite' command
I seem to have understood that a 'redirect server' must be queried to get the address of the destination phone in response
But how to understand which 'redirect servers' are available?
And once the address of the destination phone is obtained, how to initiate the call?
let me explain the process :
1- The B4A Client connects to the B4J server
The Client sends the following commands :
-Command Name : Register
-Client Number : example : 456
-Server IP
-Server Port

2- The B4J Server registers the client as follows :
456@serverIP:ServerPort
Also it registered the Client local IP and Port in case the connection was a local connection

So when the call is made from Client A to Client B the server will search for the Dialed Number in the registered users list and redirects the invite request.

What you need to do is :
Enable the server to redirect the invite requests to external servers in case it didn't find the registered user.

It's not an easy task at all, so before editing the code please study the code in the B4J server inline java to know from where to start.
 

amorosik

Expert
Licensed User
The process to follow is clear, it was already so before
What I still can't do, and for which I am looking for help in the forum, is the sending of the request from the B4j server to the voip provider, the external trunk
And the subsequent audio connection between caller (B4A client in LAN) and recipient (public network telephone)
 

sfsameer

Well-Known Member
Licensed User
Longtime User
The process to follow is clear, it was already so before
What I still can't do, and for which I am looking for help in the forum, is the sending of the request from the B4j server to the voip provider, the external trunk
And the subsequent audio connection between caller (B4A client in LAN) and recipient (public network telephone)
Unfortunately we don't have any knowledge regarding this matter except the concept of how to do it which we mentioned it above :)
 

prbmjr

Active Member
Licensed User
Hi Saif,

When I tried to make call the follow error appears in log:


B4X:
java.lang.IllegalArgumentException: Bad message: Null requestURI
    at gov.nist.javax.sip.stack.DefaultRouter.getNextHop(DefaultRouter.java:170)
    at gov.nist.javax.sip.stack.SIPTransactionStack.getNextHop(SIPTransactionStack.java:1583)
    at gov.nist.javax.sip.SipProviderImpl.getNewClientTransaction(SipProviderImpl.java:337)
    at b4j.example.mainmenu$MySipListener.processInvite(mainmenu.java:1286)
    at b4j.example.mainmenu$MySipListener.processRequest(mainmenu.java:1527)
    at gov.nist.javax.sip.EventScanner.deliverEvent(EventScanner.java:223)
    at gov.nist.javax.sip.EventScanner.run(EventScanner.java:492)
    at java.base/java.lang.Thread.run(Thread.java:834)
 

sfsameer

Well-Known Member
Licensed User
Longtime User
Hi Saif,

When I tried to make call the follow error appears in log:


B4X:
java.lang.IllegalArgumentException: Bad message: Null requestURI
    at gov.nist.javax.sip.stack.DefaultRouter.getNextHop(DefaultRouter.java:170)
    at gov.nist.javax.sip.stack.SIPTransactionStack.getNextHop(SIPTransactionStack.java:1583)
    at gov.nist.javax.sip.SipProviderImpl.getNewClientTransaction(SipProviderImpl.java:337)
    at b4j.example.mainmenu$MySipListener.processInvite(mainmenu.java:1286)
    at b4j.example.mainmenu$MySipListener.processRequest(mainmenu.java:1527)
    at gov.nist.javax.sip.EventScanner.deliverEvent(EventScanner.java:223)
    at gov.nist.javax.sip.EventScanner.run(EventScanner.java:492)
    at java.base/java.lang.Thread.run(Thread.java:834)
Hello,

This error means one of the clients were disconnected before establishing or receiving the call.
Make sure both of the clients are registered correctly.

Also this is very important because we had a lot of clients that made the same mistake :
If the b4j server is set to Udp make sure the clients are also UDP
And the same case goes for TCP

What is the protocol you are using?
Android version?
Local connection or public connection?
Did you open the port in your firewall? (inbound and outbound)

Thank you,
Saif
 

prbmjr

Active Member
Licensed User
Hello,

This error means one of the clients were disconnected before establishing or receiving the call.
Make sure both of the clients are registered correctly.

Also this is very important because we had a lot of clients that made the same mistake :
If the b4j server is set to Udp make sure the clients are also UDP
And the same case goes for TCP

What is the protocol you are using?
Android version?
Local connection or public connection?
Did you open the port in your firewall? (inbound and outbound)

Thank you,
Saif

What is the protocol you are using? TCP
Android version? Phone 1: 9 - Phone 2: 7.1.1
Local connection or public connection? Local
Did you open the port in your firewall? (inbound and outbound) Yes Both, including I stop the firewall in my tests.
 

sfsameer

Well-Known Member
Licensed User
Longtime User
What is the protocol you are using? TCP
Android version? 9
Local connection or public connection? Local
Did you open the port in your firewall? (inbound and outbound) Yes Both, including I stop the firewall in my tests.
Hello,

We have tested it today using android 8,9,10 and they worked perfectly, but we need to inspect the problem you are facing, so we would like to connect with you using anydesk or teamviewer, if that's okay with you then send us the ID via PM and we will connect with you right away.

Thank you,
Saif
 

prbmjr

Active Member
Licensed User
Hello,

We have tested it today using android 8,9,10 and they worked perfectly, but we need to inspect the problem you are facing, so we would like to connect with you using anydesk or teamviewer, if that's okay with you then send us the ID via PM and we will connect with you right away.

Thank you,
Saif

Perfect,

I sent to you via PM my Teamviewer ID and pwd
 

sfsameer

Well-Known Member
Licensed User
Longtime User
Hello everyone :)

Thanks to @prbmjr for taking the time to let us to inspect the problem, the problem occurs when selecting the TCP protocol.

The following line is causing the problem when processing the Invite request :
"transport=tcp"

We will fix it shortly and upload the fix.

Thank you,
Saif
 

Xfood

Expert
Licensed User
Consider that it doesn't even work with the UDP protocol (at least here by me)
 
Top