Can I register Web RTC app as Calling app

2.3k views Asked by At

I have web rtc implemented in a webview. Everything working fine as long as app in foreground.

Now if the app is in background/dose mode. I want to show a ringing screen like what's app. I am having a push notification when some one calls.

I know I can show notification alnog with calling sound and onClick of the notification . I can show my app Activity.

Is there any call urls exist like this

and can it be handled without notification

Or can I register my app as calling app. So that whenever call happens I register ConnectionService

and recieve onCreateIncomingConnection

1

There are 1 answers

0
Bilal Şimşek On

Yes you can. I use janus gateway and my code parts is accordingly,

  1. receive firebase message.

         if(!remoteMessage.getData().containsKey("hangup")){
             print(remoteMessage.getData());
             try {
                 Application.shared.pushMessage = new JSONObject(remoteMessage.getData().toString());
                 Application.shared.sipClient = new SipPluginHandler(null,true);
                 Application.shared.action = "incoming";
             } catch (JSONException e) {
                 e.printStackTrace();
             }
    
         }else{
             Application.shared.action = "hangup";
           //  Application.shared.voipPlugin.endCall(Application.shared.uuid);
           Application.shared.voipPlugin = null;
         }
    

SipPluginHanler is where my app connects websocket then initilizes webrtc and send receive jsep operations performed.

  1. After initilizing handler and establishing websocket connection process firebase message.

public void claimSuccess() {

    JSONObject msg = new JSONObject();
    JSONObject result = new JSONObject();

    if (fromConnectionService){

        if(Application.shared.action == "incoming"){
            JSONObject message = Application.shared.pushMessage;

            if (message != null){
                putData(result,"event","incomingcall");

                try {
                    String caller =  message.getString("caller_id");
                    putData(result,"username", "sip:" + caller + "@" + connectionInfo.ulakCagriIp);
                    putData(result,"displayname", caller);
                    putData(msg,"janus","event");


                    JSONObject dtdt = new JSONObject();
                    JSONObject dt = new JSONObject();

                    putData(dtdt,"result",result);

                    putData(dt,"data",dtdt);

                   putData(msg,"plugindata",dt);


                    JSONObject extra = message.getJSONObject("extra");

                    if (extra != null){
                        JSONObject jsep = extra.getJSONObject("jsep");
                        putData(msg,"jsep", jsep);

                        JanusMessage mesg = JanusMessage.fromJson(msg);
                       onEvent(mesg);


                    }




                } catch (JSONException e) {
                    e.printStackTrace();
                }



            }





        }else{

            putData(result,"event", "hangup");
            putData(msg,"janus", "event");
            JSONObject dtdt = new JSONObject();
            JSONObject dt = new JSONObject();

            putData(dtdt,"result",result);

            putData(dt,"data",dtdt);

            putData(msg,"plugindata",dt);

            JanusMessage mesg = JanusMessage.fromJson(msg);
            onEvent(mesg);


        }

    }
}
  1. in on event there is switch case that checks events comes from janus gateway.

     switch (eventType) {
                case accepted:
                updateUI(eventType);
                    onAccepted();
                    break;
                case calling:
                break;
                case declining:
                break;
                case declined:
                   onHangup();
                    onDeclined();
                    updateUI(eventType);
                    break;
                case hangup:
                onHangup();
                updateUI(eventType);
    
                    if (result.code != 0 && (result.code == 486 || result.code == 503) ){
                        incallManager.stop("_DTMF_");
                    } else{ incallManager.stop();
                        //incallManagerPlugin.stopRingtone();
                    }
                break;
                case incall:
                break;
                case incomingcall:
    
                  onIncomingCall(result);
                   updateUI(eventType);
                    break;
                case proceeding:
                updateUI(eventType);
                    onPorceeding();
                    break;
                case progress:
                break;
                case registered:
                onRegistered(message);
    
                    break;
                case registering:
                break;
                case registration_failed:
                break;
                case ringing:
                break;
    
            }
    
  2. finally onIncoming function I check if handler class fromConnection is true then I call ConnectionService.

     private void onIncomingCall(JanusMessage.JanusResult result) 
        {
             Application.shared.text = result.displayname.replace("\"","");
    
      if(fromConnectionService){
         Application.shared.voipPlugin = new VoipPlugin();
    
         uuid = createTransactionID();
         Application.shared.uuid = uuid;
        Application.shared.voipPlugin.reportIncomingCall(uuid,Application.shared.text,Application.shared.text);
       }
    }
    

for connection service classes I just modified android part of a flutter plugin below. https://github.com/BradenBagby/flutter_voip_kit/tree/master/android/src/main/kotlin/com/example/flutter_voip_kit