如何在PeerJS中的呼叫者和接收者之间发送数据?

问题描述 投票:0回答:1

我正在构建音频呼叫应用程序,我正在努力在呼叫接收器和呼叫者之间发送数据。这是我的代码(在呼叫接收器中):

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
peer.on('call', function(call) {

   console.log("call.peer: " + call.peer)
   conn = peer.connect(call.peer)

   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 caller
           return false
         }      
      },
      hangup: {
        label: "<i class=\"fa fa-phone\"></i> Decline",
        className: "btn-warning btn-lg pull-left",
        callback: function(){
          conn.send('DECLINED') // Send Decline to the caller
          return false;
        }
      }
    }
  });
});

使用上面的代码,当我进行调用时,会出现对话框,当我按下其中一个选项时,应该将数据发送给调用者。

以下是调用者代码,他们接收上述发送的数据:

peer.on('open', function () {
  Meteor.users.update(Meteor.userId(), { $set: { 'profile.peerId': peer.id } })
  console.log(Meteor.user().profile.peerId);
  peer.on('connection', function(conn) {
    conn.on('data', function(data){
      console.log(data);
    });
  });
});

控制台上没有任何内容。

我在这做错了什么?

meteor webrtc peerjs
1个回答
0
投票

连接事件并不重要。你想听这样的call事件

    peer.on('call', function (incomingCall) {

希望这对你更好。

我不会使用peerId更新用户记录,Meteor不建议使用它,因为身份验证系统也会写入它。我已经成功地使用了dburles:presence,并且实际上将presence ID传递给peerjs使用(而不是让peerjs分配一个)

© www.soinside.com 2019 - 2024. All rights reserved.