Twilio JS SDK,我想在其他窗口中接听软电话

时间:2019-04-23 23:20:16

标签: javascript twilio voip

我创建了一个使用Twilio Javascript教程(快速入门)的软件电话,它可以正常工作...我的问题是:

我有一个系统可以接收来自twilio的呼叫(浏览器通知),并且我希望用户在新窗口中应答该呼叫(弹出窗口),该窗口仅显示静音和挂断按钮。

那是问题所在,Twilio对象是在父窗口上创建的并且可以正常工作,但是我无法在新(子)窗口中“接听”调用,因为一旦在新窗口上重新声明了twilio对象,我没有通话通知(仍在父窗口上响铃)。

有人知道如何告诉子窗口上的javascript来回答特定的呼叫ID?

我的代码:

  device = new Twilio.Device(tokentwilio, {
    // Set Opus as our preferred codec. Opus generally performs better, requiring less bandwidth and
    // providing better audio quality in restrained network conditions. Opus will be default in 2.0.
    codecPreferences: ['opus', 'pcmu'],
    // Use fake DTMF tones client-side. Real tones are still sent to the other end of the call,
    // but the client-side DTMF tones are fake. This prevents the local mic capturing the DTMF tone
    // a second time and sending the tone twice. This will be default in 2.0.
    fakeLocalDTMF: true,
  });

      device.on('ready',function (device) {
        log('Twilio.Device Ready!');
        document.getElementById('call-controls').style.display = 'block';

      });

  device.on('connect', function (conn) {
      log('Successfully established call!');
      console.log(conn.parameters.CallSid);
    document.getElementById('button-call').style.display = 'none';
    document.getElementById('button-hangup').style.display = 'inline';
  });

  device.on('disconnect', function (conn) {
    console.log(conn);
    document.getElementById('button-call').style.display = 'inline';
    document.getElementById('button-hangup').style.display = 'none';
  });

  device.on('incoming', function (conn) {
      connp = conn;
    log('Incoming connection from ' + conn.parameters.From);

        document.getElementById('btatender').style.display = 'inline';
        console.log("NOVA LIGACAO ****");
        conn.ignore();  //i ignore the call so i can try to answer on the child window
  });

0 个答案:

没有答案