连接对等体不能按预期工作 - PeerJS

时间:2018-03-23 09:19:04

标签: meteor webrtc peerjs

我正在使用PeerJS构建音频呼叫应用程序。在呼叫接收器中,我在peer.on('call', function(call) { ... }

中有以下代码
var conn = peer.connect(call.peer);

var receiveCall = bootbox.dialog({
   className: "modal-danger nonumpad",
   closeButton: false,
   animate: true,
   title: 'Call Recieved',
   message: "Accept or Decline",
   onEscape: null,
   buttons: {
    pickup: {
     label: "<i class=\"fa fa-phone\"></i> Answer",
     className: "btn-warning btn-lg pull-left",
     callback: function(){
      conn.send('ACCEPT') // send ACCEPT to the other client
      window.currentCall = call;
      call.answer(stream); // Answer the call with an A/V stream.
      call.on('stream', function(remoteStream) {
        var audio = $('<audio autoplay />').appendTo('body');
        audio[0].src = (URL || webkitURL || mozURL).createObjectURL(stream);
      });
      return false;
    }
  },
  hangup: {
    label: "<i class=\"fa fa-phone\"></i> Decline",
    className: "btn-warning btn-lg pull-left",
    callback: function(){
      conn.send('DECLINED') // send DECLINED to the other client
      window.currentCall.close()
      stream.getTracks().forEach(track => track.stop());
      return false;
    }
  }
}
});

我可以看到数据已成功接收到其他客户端(拨打电话的客户端)。我使用以下代码来接收数据:

callDialog.init(function(){
        peer.on('connection', function(conn) {
            conn.on('data', function(data){

                console.log(call);
                if(data == "ACCEPT"){
                    $("#test").text("This is dynamic msg");
                    $("#hangup").text("Hangup");

                } else if (data == "DECLINED"){
                    stream.getTracks().forEach(track => track.stop());
    }
});
        });
    });

问题在于我在客户端使用相同的代码进行调用以将数据发送到呼叫接收器,但它不起作用且控制台中没有显示错误。

这是调用初始化程序客户端中的代码:

var conn = peer.connect(destinationPeerId);

var callDialog = bootbox.dialog({
        title: 'Making Call',
        message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i><span id="test"> Waiting for Reply... </span></div>',
        onEscape: null,
        buttons: {
            hangup: {
                label: "<span id='hangup' <i class=\"fa fa-phone\"></i> Cancel </span>",
                className: "btn-warning btn-lg pull-left",
                callback: function(){
                    conn.send('DECLINED'); // sent to the call receiver
                    stream.getTracks().forEach(track => track.stop());
                    return false;
                }
            }
        }
    });

为什么相同的代码会将数据从呼叫接收器发送到初始化器,但不是相反?

我应该如何使用它来反过来发送数据呢?

0 个答案:

没有答案