0

我创建了 webrtc 视频聊天应用程序,但是当用户离开房间然后再次加入房间时抛出错误,因为在 chrome 中以前的内部没有清理。刷新页面内部清理后,用户可以创建连接而不会出错。这是用户离开房间时的代码:

public disconnect() {
    this.opened = false;
    this.requestService.leaveRoom(this.currentUser.id, this.room)
      .pipe(first())
      .subscribe((data) => {
        console.log(data);
       });
    this.socket.emit('leaveRoom', this.currentGroup.id);
    this.remoteStreams = [];
    if (this.server) {
      this.server = false;
    }
    Object.keys(this.peerConnections).forEach(peer => {
      if (this.peerConnections[peer]) {
        this.peerConnections[peer].pc.onicecandidate = null;
        this.peerConnections[peer].pc.ontrack = null;
        this.peerConnections[peer].pc.oniceconnectionstatechange = null;
        this.peerConnections[peer].pc.getSenders().forEach((sender: any) => {
          this.peerConnections[peer].pc.removeTrack(sender);
          sender.setStreams();
          sender.track?.stop();
        });
        this.peerConnections[peer].pc.getReceivers().forEach((receiver: any) => {
          receiver.track?.stop();
        });
        this.peerConnections[peer].pc.getTransceivers().forEach((transceiver: any) => {
          this.peerConnections[peer].pc.removeTrack(transceiver.sender)
          transceiver.sender.setStreams();
          transceiver.sender.track?.stop();
          transceiver.stop();
        });
        this.peerConnections[peer].pc.close();
        this.peerConnections[peer].pc = null;
        delete this.peerConnections[peer];
      }
    });
    this.peerConnections = {};
    const eventData = {
      applicationId: { id: this.currentUser.id, room: this.currentGroup.id },
      participants: this.currentGroup.participants
    };
    this.requestService.addEvent("av", "userDisconnected", JSON.stringify(eventData), eventData.participants!)
      .pipe(first())
      .subscribe(data => {
        console.log(data);
      });
  }

有人能帮我吗?我可以清除 webrtc 内部吗?

这是错误列表:

错误错误:未捕获(承诺中):OperationError:无法在'RTCPeerConnection'上执行'setLocalDescription':无法设置本地答案sdp:在错误状态下调用:稳定错误:无法在'RTCPeerConnection'上执行'setLocalDescription':无法设置本地答案 sdp:在错误状态下调用:稳定

DOMException:无法在“RTCPeerConnection”上执行“setRemoteDescription”:无法设置远程应答 sdp:在错误状态下调用:稳定

错误错误:未捕获(承诺中):InvalidModificationError:无法在“RTCPeerConnection”上执行“setLocalDescription”:SDP 与先前为该类型生成的 SDP 不匹配错误:无法在“RTCPeerConnection”上执行“setLocalDescription”:SDP 确实与之前为该类型生成的 SDP 不匹配

DOMException:处理 ICE 候选时出错

4

0 回答 0