无法构造“RTCSessionDescription”:参数 1(“descriptionInitDict”)不是对象

Soj*_*ngi 2 android webrtc

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

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

这是屏幕截图:

在此输入图像描述

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

PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
    true, mEGLcontext);
Run Code Online (Sandbox Code Playgroud)

这就是我创建对等连接对象的方式:

this.pc = factory.createPeerConnection(RTCConfig.getIceServer(), RTCConfig.getMediaConstraints(), this);
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

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

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

这是 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);
});
Run Code Online (Sandbox Code Playgroud)

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

我在互联网上找不到该错误的解决方案。我无法理解descriptionInitDict 的含义。

nbe*_*ezs 5

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