我想在进行重新协商时使用自己的流。标准方法是将媒体参数传递给createOffer函数。在这种情况下,Janus处理getUserMedia请求。
async switchCamera() {
this.videoCall.createOffer({
media: {
replaceVideo: true
},
success: (jsep) => {
this.videoCall.send({message: {request:"set"}, "jsep": jsep});
},
error: (e) => {
alert(e);
}
});
}
就我而言,我想自己做。我创建了以下函数:
async switchCamera() {
cameraHelper.switchCamera(); // Sets facing mode
this.localStream = await cameraHelper.requestMedia(); // Returns media stream
this.videoCall.createOffer({
stream: this.localStream,
success: (jsep) => {
this.videoCall.send({message: {request:"set"}, "jsep": jsep});
},
error: (e) => {
alert(e);
}
});
}
如果我调用switchCamera函数,则Chrome在接收器侧崩溃。崩溃前的最后一条错误消息如下:
Uncaught DOMException: Failed to execute 'addTrack' on 'RTCPeerConnection': A sender already exists for the track.
添加新流之前,我还必须执行一些其他功能吗?