我有一个正在使用WebRTC在同级之间建立连接并发送文件的项目。我正在处理旧代码,但目前可在Chrome中使用。我在使其无法在Firefox中运行时遇到了麻烦,无法确定问题出在哪里。
这是我的代码:
this.connection = new RTCPeerConnection(config);
...
const desc = await this.connection.createOffer();
this.localConnection.setLocalDescription(desc);
console.log('local description', this.localConnection.localDescription);
对于this.localConnection.localDescription
的值:
RTCSessionDescription {type: "offer", sdp: ...}
null
我在做什么错?
我认为问题出在setLocalDescription
方法周围,它可能无法在Firefox中立即设置,我会在等待时尝试:
await this.localConnection.setLocalDescription(desc);
console.log('local description', this.localConnection.localDescription);