This commit is contained in:
Bruno Windels 2022-07-12 11:59:52 +02:00
parent e9649ec7c2
commit 3346f68d25
3 changed files with 49 additions and 30 deletions

View file

@ -177,6 +177,7 @@ export class PeerCall implements IDisposable {
if (this._state !== CallState.Fledgling) { if (this._state !== CallState.Fledgling) {
return; return;
} }
log.set("signalingState", this.peerConnection.signalingState);
this.direction = CallDirection.Outbound; this.direction = CallDirection.Outbound;
this.setState(CallState.CreateOffer, log); this.setState(CallState.CreateOffer, log);
this.localMuteSettings = localMuteSettings; this.localMuteSettings = localMuteSettings;
@ -309,35 +310,39 @@ export class PeerCall implements IDisposable {
}, async log => { }, async log => {
logItem = log; logItem = log;
switch (message.type) { const callIdMatches = this.callId === message.content.call_id;
case EventType.Invite:
if (this.callId !== message.content.call_id) { if (message.type === EventType.Invite && !callIdMatches) {
await this.handleInviteGlare(message.content, partyId, log); await this.handleInviteGlare(message.content, partyId, log);
} else { } else if (callIdMatches) {
switch (message.type) {
case EventType.Invite:
await this.handleFirstInvite(message.content, partyId, log); await this.handleFirstInvite(message.content, partyId, log);
} break;
break; case EventType.Answer:
case EventType.Answer: await this.handleAnswer(message.content, partyId, log);
await this.handleAnswer(message.content, partyId, log); break;
break; case EventType.Negotiate:
case EventType.Negotiate: await this.onNegotiateReceived(message.content, log);
await this.onNegotiateReceived(message.content, log); break;
break; case EventType.Candidates:
case EventType.Candidates: await this.handleRemoteIceCandidates(message.content, partyId, log);
await this.handleRemoteIceCandidates(message.content, partyId, log); break;
break; case EventType.SDPStreamMetadataChanged:
case EventType.SDPStreamMetadataChanged: case EventType.SDPStreamMetadataChangedPrefix:
case EventType.SDPStreamMetadataChangedPrefix: this.updateRemoteSDPStreamMetadata(message.content[SDPStreamMetadataKey], log);
this.updateRemoteSDPStreamMetadata(message.content[SDPStreamMetadataKey], log); break;
break; case EventType.Hangup:
case EventType.Hangup: // TODO: this is a bit hacky, double check its what we need
// TODO: this is a bit hacky, double check its what we need log.set("reason", message.content.reason);
log.set("reason", message.content.reason); this.terminate(CallParty.Remote, message.content.reason ?? CallErrorCode.UserHangup, log);
this.terminate(CallParty.Remote, message.content.reason ?? CallErrorCode.UserHangup, log); break;
break; default:
default: log.log(`Unknown event type for call: ${message.type}`);
log.log(`Unknown event type for call: ${message.type}`); break;
break; }
} else if (!callIdMatches) {
log.set("wrongCallId", true);
} }
}); });
return logItem; return logItem;
@ -879,6 +884,7 @@ export class PeerCall implements IDisposable {
this.setState(CallState.Ended, log); this.setState(CallState.Ended, log);
this.localMedia = undefined; this.localMedia = undefined;
// TODO: change signalingState to connectionState?
if (this.peerConnection && this.peerConnection.signalingState !== 'closed') { if (this.peerConnection && this.peerConnection.signalingState !== 'closed') {
this.peerConnection.close(); this.peerConnection.close();
} }

View file

@ -283,7 +283,7 @@ export class Member {
} }
} }
if (!hasBeenDequeued) { if (!hasBeenDequeued) {
syncLog.refDetached(connection.logItem.log({l: "queued signalling message", type: message.type})); syncLog.refDetached(connection.logItem.log({l: "queued signalling message", type: message.type, seq: message.content.seq}));
} }
} else { } else {
syncLog.log({l: "member not connected", userId: this.userId, deviceId: this.deviceId}); syncLog.log({l: "member not connected", userId: this.userId, deviceId: this.deviceId});

View file

@ -24,11 +24,24 @@ const SPEAKING_SAMPLE_COUNT = 8; // samples
export class DOMWebRTC implements WebRTC { export class DOMWebRTC implements WebRTC {
createPeerConnection(forceTURN: boolean, turnServers: RTCIceServer[], iceCandidatePoolSize): PeerConnection { createPeerConnection(forceTURN: boolean, turnServers: RTCIceServer[], iceCandidatePoolSize): PeerConnection {
return new RTCPeerConnection({ const peerConn = new RTCPeerConnection({
iceTransportPolicy: forceTURN ? 'relay' : undefined, iceTransportPolicy: forceTURN ? 'relay' : undefined,
iceServers: turnServers, iceServers: turnServers,
iceCandidatePoolSize: iceCandidatePoolSize, iceCandidatePoolSize: iceCandidatePoolSize,
}) as PeerConnection; }) as PeerConnection;
return new Proxy(peerConn, {
get(target, prop, receiver) {
if (prop === "close") {
console.trace("calling peerConnection.close");
}
const value = target[prop];
if (typeof value === "function") {
return value.bind(target);
} else {
return value;
}
}
});
} }
prepareSenderForPurpose(peerConnection: PeerConnection, sender: Sender, purpose: SDPStreamMetadataPurpose): void { prepareSenderForPurpose(peerConnection: PeerConnection, sender: Sender, purpose: SDPStreamMetadataPurpose): void {