fix error Cannot set remote answer in state stable

This commit is contained in:
schlagmichdoch 2023-01-23 19:53:14 +01:00
parent 19d7e6fecd
commit ec6bee05fd

View file

@ -264,12 +264,12 @@ class Peer {
combinedSize += files[i].size; combinedSize += files[i].size;
} }
this._fileHeaderRequested = header; this._fileHeaderRequested = header;
let bytesCompleted = 0;
let bytesCompleted = 0;
zipper.createNewZipWriter(); zipper.createNewZipWriter();
for (let i=0; i<files.length; i++) { for (let i=0; i<files.length; i++) {
const entry = await zipper.addFile(files[i], { await zipper.addFile(files[i], {
onprogress: (progress, total) => { onprogress: (progress) => {
Events.fire('set-progress', { Events.fire('set-progress', {
peerId: this._peerId, peerId: this._peerId,
progress: (bytesCompleted + progress) / combinedSize, progress: (bytesCompleted + progress) / combinedSize,
@ -543,7 +543,7 @@ class RTCPeer extends Peer {
if (!this._conn) this._connect(message.sender, false); if (!this._conn) this._connect(message.sender, false);
if (message.sdp) { if (message.sdp) {
this._conn.setRemoteDescription(new RTCSessionDescription(message.sdp)) this._conn.setRemoteDescription(message.sdp)
.then( _ => { .then( _ => {
if (message.sdp.type === 'offer') { if (message.sdp.type === 'offer') {
return this._conn.createAnswer() return this._conn.createAnswer()
@ -663,29 +663,20 @@ class PeersManager {
} }
_onMessage(message) { _onMessage(message) {
this._refreshOrCreatePeer(message.sender, message.roomType, message.roomSecret); // if different roomType -> abort
this.peers[message.sender].onServerMessage(message); if (this.peers[message.sender] && this.peers[message.sender]._roomType !== message.roomType) return;
} if (!this.peers[message.sender]) {
this.peers[message.sender] = new RTCPeer(this._server, undefined, message.roomType, message.roomSecret);
_refreshOrCreatePeer(id, roomType, roomSecret) {
if (!this.peers[id]) {
this.peers[id] = new RTCPeer(this._server, undefined, roomType, roomSecret);
}else if (this.peers[id]._roomType !== roomType) {
this.peers[id]._roomType = roomType;
this.peers[id]._roomSecret = roomSecret;
} }
this.peers[message.sender].onServerMessage(message);
} }
_onPeers(msg) { _onPeers(msg) {
msg.peers.forEach(peer => { msg.peers.forEach(peer => {
if (this.peers[peer.id]) { if (this.peers[peer.id]) {
if (this.peers[peer.id].roomType === msg.roomType) { // if different roomType -> abort
this.peers[peer.id].refresh(); if (this.peers[peer.id].roomType !== msg.roomType) return;
} else { this.peers[peer.id].refresh();
this.peers[peer.id].roomType = msg.roomType;
this.peers[peer.id].roomSecret = msg.roomSecret;
}
return;
} }
if (window.isRtcSupported && peer.rtcSupported) { if (window.isRtcSupported && peer.rtcSupported) {
this.peers[peer.id] = new RTCPeer(this._server, peer.id, msg.roomType, msg.roomSecret); this.peers[peer.id] = new RTCPeer(this._server, peer.id, msg.roomType, msg.roomSecret);