【问题标题】:Failed to construct 'RTCSessionDescription': parameter 1 ('descriptionInitDict') is not an object未能构造“RTCSessionDescription”:参数 1(“descriptionInitDict”)不是对象
【发布时间】:2015-10-18 02:16:17
【问题描述】:

我正在尝试在 Chrome 上的 Android 和 Web 应用程序之间进行电话会议。当 Android 将报价发送到 Web 应用程序时,我在 chrome 控制台上收到以下错误:

未能构造“RTCSessionDescription”:参数 1(“descriptionInitDict”)不是对象。

截图如下:

在 Android 上,我有这样的代码:

PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
    true, mEGLcontext);

这就是我创建 Peer Connection 对象的方式:

this.pc = factory.createPeerConnection(RTCConfig.getIceServer(), RTCConfig.getMediaConstraints(), this);

RTCConfig.getMediaConstraints() 函数定义如下:

public static MediaConstraints getMediaConstraints(){
   // Initialize PeerConnection
   MediaConstraints pcMediaConstraints = new MediaConstraints();
   pcMediaConstraints.optional.add(new MediaConstraints.KeyValuePair(
      "DtlsSrtpKeyAgreement", "true"));
   pcMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair(
         "OfferToReceiveAudio", "true"));
   pcMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair(
         "OfferToReceiveVideo", "true"));

   return pcMediaConstraints;
}

而 RTCConfig.getICEServer() 函数定义为:

public static LinkedList<PeerConnection.IceServer> getIceServer(){ 
   // Initialize ICE server list
   LinkedList<PeerConnection.IceServer> iceServers = new LinkedList<PeerConnection.IceServer>();
   iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302"));
   return iceServers;
}

在 Web 应用程序上,我以这种方式创建对等连接对象:

var pc = new RTCPeerConnection(
{'iceServers': [
  createIceServer(isChrome
    ? 'stun:stun.l.google.com:19302'
    : 'stun:23.21.150.121', null, null)
]}, 
{optional: [ {"DtlsSrtpKeyAgreement": true}]});

这是 Web 应用程序处理报价的方式:

pc.setRemoteDescription(new RTCSessionDescription(data.sdp), function () {
  $log.debug('Setting remote description by offer');
  pc.createAnswer(function (sdp) {
    pc.setLocalDescription(sdp);
    socket.emit('msg', { by: currentId, to: data.by, sdp: sdp, type: 'answer' });
  }, function (e) {
    $log.error(e);
  });
}, function (e) {
  $log.error(e);
});

网络到网络之间的电话会议运行良好。当 android 将报价发送到 Web 应用程序时,它不起作用。此外,当 Web 将 offer 发送到 android 时,不会调用 SdpObserver 的 onCreateSuccess(final SessionDescription sdp)。

我在 Internet 上找不到此错误的解决方案。我不明白 descriptionInitDict 是什么意思。

【问题讨论】:

    标签: android webrtc


    【解决方案1】:

    浏览器端data.sdp的类型是什么?如果它是一个字符串,我认为它是基于你给它的名字,那就是问题所在。您应该传递一个具有两个属性的对象:typesdp。看看官方规范here

    【讨论】:

    • 感谢您的回答。它现在显示出一些进展。 Web 现在能够为 android 创建答案。 Android 无法创建答案或生成候选者。
    • 问题是 sdp 对象在我的情况下在信令服务器中被转换为字符串。我只是将其更改为对象类型并出现错误。一旦障碍清除。
    猜你喜欢
    • 2018-08-05
    • 2023-02-08
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 2023-03-25
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多