构造 'RTCSessionDescription' 失败:参数 1 ('descriptionInitDict') 不是 object
Failed to construct 'RTCSessionDescription': parameter 1 ('descriptionInitDict') is not an object
我正在尝试在 Android 和 Chrome 上的 Web 应用程序之间进行电话会议。当 Android 将报价发送到 Web 应用程序时,我在 chrome 控制台上收到以下错误:
构造'RTCSessionDescription'失败:参数1('descriptionInitDict')不是object。
截图如下:
在 Android 上,我有这样的代码:
PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
true, mEGLcontext);
这就是我创建对等连接的方式object:
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 应用程序上,我以这种方式创建对等连接 object:
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);
});
Web 到 Web 之间的电话会议工作正常。当 android 将报价发送到 Web 应用程序时,它不起作用。此外,当 Web 将报价发送到 android 时,不会调用 SdpObserver 的 onCreateSuccess(final SessionDescription sdp)。
我无法在 Internet 上找到解决此错误的方法。我不明白 descriptionInitDict 是什么意思。
浏览器端data.sdp的类型是什么?如果它是一个字符串,我认为它是基于你给它的名字,那就是问题所在。您应该传递一个具有两个属性的对象:type
和 sdp
。看看官方规格 here
我正在尝试在 Android 和 Chrome 上的 Web 应用程序之间进行电话会议。当 Android 将报价发送到 Web 应用程序时,我在 chrome 控制台上收到以下错误:
构造'RTCSessionDescription'失败:参数1('descriptionInitDict')不是object。
截图如下:
在 Android 上,我有这样的代码:
PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
true, mEGLcontext);
这就是我创建对等连接的方式object:
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 应用程序上,我以这种方式创建对等连接 object:
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);
});
Web 到 Web 之间的电话会议工作正常。当 android 将报价发送到 Web 应用程序时,它不起作用。此外,当 Web 将报价发送到 android 时,不会调用 SdpObserver 的 onCreateSuccess(final SessionDescription sdp)。
我无法在 Internet 上找到解决此错误的方法。我不明白 descriptionInitDict 是什么意思。
浏览器端data.sdp的类型是什么?如果它是一个字符串,我认为它是基于你给它的名字,那就是问题所在。您应该传递一个具有两个属性的对象:type
和 sdp
。看看官方规格 here