简体   繁体   English

如何拒绝WebRTC呼叫

[英]How to reject WebRTC call

I've made a simple calling application using WebRTC. 我已经使用WebRTC制作了一个简单的调用应用程序。 I've established an connection and I can now call from one browser to another. 我已经建立了连接,现在可以从一个浏览器调用另一个浏览器。

One thing I still can't figure out and can't find in the WebRTC standard is ... How can I reject an call offer. 在WebRTC标准中,我仍然无法弄清和找不到的一件事是...如何拒绝通话提议。

If I get an offer from the caller I was thinking about following 如果我收到来电者的报价,我正在考虑关注

if(msg.type == 'offer') {
    if(confirm(msg.sender+" is calling you ...")) {
        $.calling.calleePeer.setRemoteDescription(new RTCSessionDescription(msg));
        $.calling.calleePeer.addStream($.calling.localstream);
        $.calling.calleePeer.createAnswer($.calling.setLocalCalleeAndSendDescription, null, $.calling.mediaConstraints);

    } else {
        // TODO What to do here in order to reject the offer?
    }
}

Now everything works when I accept the offer, but how I can let the caller know that I'm not interesting in the call right now? 现在,当我接受要约时,一切正常,但是如何让呼叫者知道我现在对通话不感兴趣? I guess there is some solution build into the standard. 我想标准中有一些解决方案。

In WebRTC, the signalling protocol is whatever you define, so the application should send a command to the other party informing that the offer was rejected by the user. 在WebRTC中,您可以定义任何信令协议,因此应用程序应向另一方发送命令,告知要约被用户拒绝。

When you do this, you must close the PeerConnection Objects on both parties, and the browser will stop waiting or trying to establish connection. 执行此操作时,必须在双方上都关闭PeerConnection对象,浏览器将停止等待或尝试建立连接。

if(msg.type == 'offer') {
    if(confirm(msg.sender+" is calling you ...")) {
        $.calling.calleePeer.setRemoteDescription(new RTCSessionDescription(msg));
        $.calling.calleePeer.addStream($.calling.localstream);
        $.calling.calleePeer.createAnswer($.calling.setLocalCalleeAndSendDescription, null, $.calling.mediaConstraints);

    } else {
        $.calling.calleePeer.close();
        // Send a command to the other party (i.e. a response to the invitation) rejecting the offer.
    }
}

The client that started the process should do the same, when receiving the rejection. 收到拒绝后,启动该过程的客户端应执行相同的操作。

// I suppose you have something like this.
$.calling.callerPeer.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM