android - 我可以将 Web RTC 应用程序注册为调用应用程序吗

标签 android telecommunication webrtc-android android-phone-call

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


现在如果应用程序位于 背景/剂量模式。我要显示 响铃之类的应用程序 .
当有人打电话时,我收到推送通知。
我知道我可以通过调用声音和通知的 onClick 显示通知警报。我可以显示我的应用 Activity 。
是否存在诸如 this 之类的调用 url
可以是未经通知处理
或者我可以将我的应用注册为调用应用。这样每当通话发生时,我都会注册 ConnectionService
并收到onCreateIncomingConnection

最佳答案

是的你可以。我使用 janus 网关,我的代码部分是相应的,

  • 接收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 操作的地方。
  • 在初始化处理程序并建立 websocket 连接后处理 firebase 消息。

  • 公共(public)无效声明成功(){
        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);
    
    
            }
    
        }
    }
    
  • 在事件中,有开关盒检查事件是否来自 janus 网关。
     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;
    
            }
    
  • 最后 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);
       }
    }
    

  • 对于连接服务类,我刚刚修改了下面颤振插件的 android 部分。
    https://github.com/BradenBagby/flutter_voip_kit/tree/master/android/src/main/kotlin/com/example/flutter_voip_kit

    关于android - 我可以将 Web RTC 应用程序注册为调用应用程序吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64425303/

    相关文章:

    android - 如何使用 gradle 为所有模块定义通用的 android 属性

    erlang - Erlang 在电信领域的应用

    hadoop - CDR的大数据分析(通话详细记录)。帮助:D

    kotlin - Android (Kotlin) WebRTC - "Failed to parse: "“。原因 : Invalid SDP line"

    前台服务中的 Android webRTC 调用

    android - Google Play 服务 6.5.87 与 7.3.0 - 布局问题?

    android - 如何制作 Groupie recylerview 2x2 布局

    sip - "P-Asserted-Identity"和 "P-Called-Party-ID"和有什么区别?

    android google maponClick 没有响应