perfectnogation #20

Merged
saqut merged 6 commits from perfectnogation into stable 2025-07-14 23:25:51 +03:00
1 changed files with 57 additions and 10 deletions
Showing only changes of commit 7756caa0f8 - Show all commits

View File

@ -32,6 +32,12 @@ export default class WebRTC
rtcpMuxPolicy:"require",
};
public isPolite() : boolean
{
let myId = this.peer?.mwse.peer('me').socketId as string;
let peerId = this.peer?.socketId as string;
return myId < peerId;
}
public static defaultICEServers : RTCIceServer[] = [{
urls: "stun:stun.l.google.com:19302"
@ -49,6 +55,11 @@ export default class WebRTC
public FileTransportChannel? : P2PFileSender;
public makingOffer = false;
public ignoreOffer = false;
public isSettingRemoteAnswerPending = false;
constructor(
rtcConfig?: RTCConfiguration,
rtcServers?: RTCIceServer[]
@ -105,7 +116,23 @@ export default class WebRTC
break;
}
case "offer":{
let readyForOffer = !this.makingOffer && (this.rtc.signalingState == "stable" || this.isSettingRemoteAnswerPending);
const offerCollision = !readyForOffer;
this.ignoreOffer = !this.isPolite() && offerCollision;
if(this.ignoreOffer){
return;
}
this.isSettingRemoteAnswerPending = false;
await this.rtc.setRemoteDescription(new RTCSessionDescription(data.value));
this.isSettingRemoteAnswerPending = false;
let answer = await this.rtc.createAnswer({
offerToReceiveAudio: true,
offerToReceiveVideo: true
@ -118,7 +145,19 @@ export default class WebRTC
break;
}
case "answer":{
let readyForOffer = !this.makingOffer && (this.rtc.signalingState == "stable" || this.isSettingRemoteAnswerPending);
const offerCollision = !readyForOffer;
this.ignoreOffer = !this.isPolite() && offerCollision;
if(this.ignoreOffer){
return;
}
this.isSettingRemoteAnswerPending = true;
await this.rtc.setRemoteDescription(new RTCSessionDescription(data.value))
this.isSettingRemoteAnswerPending = false;
break;
}
case "streamInfo":{
@ -298,6 +337,8 @@ export default class WebRTC
}
public async eventNogationNeeded()
{
try{
this.makingOffer = true;
let offer = await this.rtc.createOffer({
iceRestart: true,
offerToReceiveAudio: true,
@ -308,6 +349,12 @@ export default class WebRTC
type: 'offer',
value: offer
});
}catch(error){
console.error(`Nogation Error:`, error)
}
finally{
this.makingOffer = false;
}
}
public eventSignalingState()
{