簡體   English   中英

我可以將 Web RTC 應用注冊為通話應用嗎

[英]Can I register Web RTC app as Calling app

我在 webview 中實現了 web rtc。 只要應用程序在前台,一切正常。

現在,如果應用程序處於后台/劑量模式。 我想顯示一個像什么 app 一樣響鈴屏幕 有人打電話時,我收到推送通知。

我知道我可以通過呼叫聲音和通知的 onClick 來顯示通知。 我可以顯示我的應用活動。

是否有任何通話網址存在像這樣

是否可以在不通知的情況下處理

或者我可以將我的應用程序注冊為調用應用程序。 這樣無論何時發生呼叫,我都會注冊ConnectionService

並收到onCreateIncomingConnection

是的你可以。 我使用 janus 網關,我的代碼部分是相應的,

  1. 接收firebase消息。

     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 是我的應用程序連接 websocket 然后初始化 webrtc 並發送接收 jsep 操作的地方。

  1. 在初始化處理程序並建立 websocket 連接后處理 firebase 消息。

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. 在事件中有檢查事件來自 janus 網關的 switch case。

     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. 最后 onIncoming 函數我檢查處理程序類 fromConnection 是否為真,然后我調用 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);

    } }

對於連接服務類,我剛剛修改了下面 flutter 插件的 android 部分。 https://github.com/BradenBagby/flutter_voip_kit/tree/master/android/src/main/kotlin/com/example/flutter_voip_kit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM