You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SIP.js实现会话遇InvalidAccessError:无ice-ufrag属性问题求助

问题分析与修复方案

错误根源

no ice-ufrag attribute at level 0这个错误说明SDP会话描述里缺少ICE协议必需的ice-ufrag和ice-pwd属性,核心原因是你的PeerConnection配置存在重复冲突,加上媒体流异步获取的时机问题,导致SIP.js无法正确生成符合要求的SDP。

你的代码里的两个关键问题

  • 重复配置RTC参数:你在sessionDescriptionHandlerOptions中同时设置了peerConnectionConfiguration和peerConnectionOptions.rtcConfiguration,这会让SIP.js的SessionDescriptionHandler陷入配置冲突,无法正确应用ICE设置。
  • 媒体流异步时机错误:getUserMedia是异步操作,但你在它还没完成时就调用了invitation.accept(),可能导致PeerConnection初始化时缺少媒体轨道,间接干扰ICE协商流程。

修正后的完整代码

const acceptCall = () => {
  const constraints = {
    audio: true,
    video: false,
  };

  // 必须等媒体流获取完成后再处理通话接受
  navigator.mediaDevices
    .getUserMedia(constraints)
    .then((localStream) => {
      // 绑定本地音频流到页面元素
      const localAudio = document.getElementById('localAudio') as HTMLAudioElement;
      if (localAudio) {
        localAudio.srcObject = localStream;
      }

      const peerConnectionConfig = {
        iceServers: [
          {
            urls: ['stun:stun.l.google.com:19302'],
          },
        ],
        iceTransportPolicy: 'all',
        bundlePolicy: 'balanced' as RTCBundlePolicy,
        rtcpMuxPolicy: 'require' as RTCRtcpMuxPolicy,
      };

      const options = {
        sessionDescriptionHandlerOptions: {
          constraints,
          peerConnectionConfiguration: peerConnectionConfig,
          // 移除重复的rtcConfiguration,只保留必要的iceGatheringTimeout
          peerConnectionOptions: {
            iceGatheringTimeout: 5000,
          },
        },
      };

      // 在媒体流就绪后接受通话
      invitation
        .accept(options)
        .then(() => console.log('Call accepted successfully'))
        .catch((error) => console.error('Failed to accept call:', error));
    })
    .catch((error) => console.error('Error getting user media:', error));
};

额外排查要点

  1. 检查你的SIP服务器(如FreeSWITCH、Asterisk)是否启用了ICE支持,如果服务器端未配置ICE,会导致SDP缺少ICE相关属性。
  2. 确认使用的SIP.js版本,部分旧版本存在SessionDescriptionHandler的配置bug,建议升级到最新稳定版。
  3. 调用invitation.accept()前,确保invitation对象处于pending状态,避免在无效状态下执行操作。

内容的提问来源于stack exchange,提问作者SOORAJ SR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 15:00:09