我可以将Web RTC应用程序注册为呼叫应用程序吗



我在web视图中实现了web rtc。只要应用程序在前台,一切都很好。

现在,如果应用程序处于背景/剂量模式。我想显示一个铃声屏幕,就像应用程序一样。当有人打电话给我时,我收到了推送通知。

我知道我可以用呼叫声和点击通知来显示通知日志。我可以显示我的应用程序"活动"。

是否存在类似 的调用URL

是否可以在不通知的情况下处理

或者我可以将我的应用程序注册为呼叫应用程序。因此,每当调用发生时,我都会注册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操作。

初始化处理程序并建立websocket连接后,处理firebase消息

公共无效索赔成功(({

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. 在on事件中,存在检查来自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;
    }
    
  2. 最后,在编码函数时,我检查处理程序类fromConnection是否为true,然后调用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

最新更新