handle remote ice candidates

This commit is contained in:
Bruno Windels 2022-03-11 16:35:32 +01:00
parent b213a45c5c
commit 3c160c8a37
2 changed files with 43 additions and 6 deletions

View file

@ -105,7 +105,7 @@ export class PeerCall implements IDisposable {
log(...args) { console.log.apply(console, ["WebRTC log:", ...args])}, log(...args) { console.log.apply(console, ["WebRTC log:", ...args])},
warn(...args) { console.log.apply(console, ["WebRTC warn:", ...args])}, warn(...args) { console.log.apply(console, ["WebRTC warn:", ...args])},
error(...args) { console.error.apply(console, ["WebRTC error:", ...args])}, error(...args) { console.error.apply(console, ["WebRTC error:", ...args])},
} };
} }
get state(): CallState { return this._state; } get state(): CallState { return this._state; }
@ -214,9 +214,9 @@ export class PeerCall implements IDisposable {
case EventType.Answer: case EventType.Answer:
await this.handleAnswer(message.content, partyId); await this.handleAnswer(message.content, partyId);
break; break;
//case EventType.Candidates: case EventType.Candidates:
// await this.handleRemoteIceCandidates(message.content, partyId); await this.handleRemoteIceCandidates(message.content, partyId);
// break; break;
case EventType.Hangup: case EventType.Hangup:
default: default:
throw new Error(`Unknown event type for call: ${message.type}`); throw new Error(`Unknown event type for call: ${message.type}`);
@ -296,7 +296,7 @@ export class PeerCall implements IDisposable {
} }
}; };
private async handleInviteGlare(content: MCallInvite, partyId: PartyId): Promise<void> { private async handleInviteGlare(content: MCallInvite<MCallBase>, partyId: PartyId): Promise<void> {
// this is only called when the ids are different // this is only called when the ids are different
const newCallId = content.call_id; const newCallId = content.call_id;
if (this.callId! > newCallId) { if (this.callId! > newCallId) {
@ -386,7 +386,7 @@ export class PeerCall implements IDisposable {
} }
} }
private async handleAnswer(content: MCallAnswer, partyId: PartyId): Promise<void> { private async handleAnswer(content: MCallAnswer<MCallBase>, partyId: PartyId): Promise<void> {
this.logger.debug(`Got answer for call ID ${this.callId} from party ID ${partyId}`); this.logger.debug(`Got answer for call ID ${this.callId} from party ID ${partyId}`);
if (this._state === CallState.Ended) { if (this._state === CallState.Ended) {
@ -424,6 +424,42 @@ export class PeerCall implements IDisposable {
} }
} }
async handleRemoteIceCandidates(content: MCallCandidates<MCallBase>, partyId) {
if (this.state === CallState.Ended) {
//debuglog("Ignoring remote ICE candidate because call has ended");
return;
}
const candidates = content.candidates;
if (!candidates) {
this.logger.info(`Call ${this.callId} Ignoring candidates event with no candidates!`);
return;
}
const fromPartyId = content.version === 0 ? null : partyId || null;
if (this.opponentPartyId === undefined) {
// we haven't picked an opponent yet so save the candidates
this.logger.info(`Call ${this.callId} Buffering ${candidates.length} candidates until we pick an opponent`);
const bufferedCandidates = this.remoteCandidateBuffer!.get(fromPartyId) || [];
bufferedCandidates.push(...candidates);
this.remoteCandidateBuffer!.set(fromPartyId, bufferedCandidates);
return;
}
if (this.opponentPartyId !== partyId) {
this.logger.info(
`Call ${this.callId} `+
`Ignoring candidates from party ID ${partyId}: ` +
`we have chosen party ID ${this.opponentPartyId}`,
);
return;
}
await this.addIceCandidates(candidates);
}
// private async onNegotiateReceived(event: MatrixEvent): Promise<void> { // private async onNegotiateReceived(event: MatrixEvent): Promise<void> {
// const content = event.getContent<MCallNegotiate>(); // const content = event.getContent<MCallNegotiate>();
// const description = content.description; // const description = content.description;

View file

@ -103,6 +103,7 @@ DONE: Make it possible to olm encrypt the messages
Do work needed for state events Do work needed for state events
- DONEish: receiving (almost done?) - DONEish: receiving (almost done?)
- DONEish: sending - DONEish: sending
logging
Expose call objects Expose call objects
expose volume events from audiotrack to group call expose volume events from audiotrack to group call
Write view model Write view model