【问题标题】:How to access the remote stream on a Twilio browser call如何在 Twilio 浏览器调用中访问远程流
【发布时间】:2021-12-22 17:38:11
【问题描述】:

我正在使用新的 v2 Twilio Javascript SDK 从浏览器向其他人进行调用。 这工作正常,但我被要求为传入的音频流添加音量控制。

经过一些研究,我似乎需要从通话中获取远程流并通过增益节点将其馈送以减少音量。

不幸的是,call.getRemoteStream 的结果始终为 null,即使我可以听到通话中的音频。 我已经在最新的 Chrome 和 Edge 上对此进行了测试,它们的行为相同。

我还需要做些什么来访问远程流吗?

代码:

async function(phoneNumber, token) 
{
    console.log("isSecureContext: " + window.isSecureContext); //check we can get the stream

    var options = {
          edge: 'ashburn', //us US endpoint
          closeProtection: true // will warn user if you try to close browser window during an active call
    };
    var device = new Device(token, options);

    const connectionParams = { 
        "phoneNumber": phoneNumber
    };
    var activeCall = await device.connect({ params: connectionParams });

    //Setup gain (volume) control for incoming audio
    //Note, getRemoteStream always returns null.
    var remoteStream = activeCall.getRemoteStream();

    if(remoteStream)
    {
        var audioCtx = new AudioContext();
        var source = audioCtx.createMediaStreamSource(remoteStream);
        var gainNode = audioCtx.createGain();
        source.connect(gainNode)
        gainNode.connect(audioCtx.destination);
    }
    else
    {
        console.log("No remote stream on call");
    }    
}

日志输出为:

isSecureContext: true

然后

No remote stream on call

【问题讨论】:

    标签: javascript twilio


    【解决方案1】:

    Twilio 支持给了我答案:您需要等到开始接收音量事件后再请求流。

    call.on('volume', (inputVolume, outputVolume) => {
    
        if(inputVolume > 0)
        {
           var remoteStream = activeCall.getRemoteStream();
           ....
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 2015-06-25
      • 1970-01-01
      相关资源
      最近更新 更多