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

View File

@ -283,7 +283,7 @@ export class Member {
}
}
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 {
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 {
createPeerConnection(forceTURN: boolean, turnServers: RTCIceServer[], iceCandidatePoolSize): PeerConnection {
return new RTCPeerConnection({
const peerConn = new RTCPeerConnection({
iceTransportPolicy: forceTURN ? 'relay' : undefined,
iceServers: turnServers,
iceCandidatePoolSize: iceCandidatePoolSize,
}) 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 {