Skip to content

Commit

Permalink
Internally remove call types
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <[email protected]>
  • Loading branch information
SimonBrandner committed Sep 11, 2021
1 parent c620a20 commit d916d3f
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ function genCallID(): string {
*/
export class MatrixCall extends EventEmitter {
public roomId: string;
public type: CallType = null;
public callId: string;
public state = CallState.Fledgling;
public hangupParty: CallParty;
Expand Down Expand Up @@ -359,6 +358,25 @@ export class MatrixCall extends EventEmitter {
return this.remoteAssertedIdentity;
}

public get type(): CallType {
return (this.hasLocalUserMediaVideoTrack || this.hasRemoteUserMediaVideoTrack)
? CallType.Video
: CallType.Voice;
}

public get hasLocalUserMediaVideoTrack(): boolean {
return this.localUsermediaStream?.getVideoTracks().length > 0;
}

public get hasRemoteUserMediaVideoTrack(): boolean {
return this.getRemoteFeeds().some((feed) => {
return (
feed.purpose === SDPStreamMetadataPurpose.Usermedia &&
feed.stream.getVideoTracks().length > 0
);
});
}

public get localUsermediaFeed(): CallFeed {
return this.getLocalFeeds().find((feed) => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
}
Expand Down Expand Up @@ -617,8 +635,6 @@ export class MatrixCall extends EventEmitter {
return;
}

this.type = remoteStream.getTracks().some(t => t.kind === 'video') ? CallType.Video : CallType.Voice;

this.setState(CallState.Ringing);

if (event.getLocalAge()) {
Expand Down Expand Up @@ -656,7 +672,7 @@ export class MatrixCall extends EventEmitter {
return;
}

logger.debug(`Answering call ${this.callId} of type ${this.type}`);
logger.debug(`Answering call ${this.callId}`);

if (!this.localUsermediaStream && !this.waitForLocalAVStream) {
this.setState(CallState.WaitLocalMedia);
Expand All @@ -665,7 +681,7 @@ export class MatrixCall extends EventEmitter {
try {
const mediaStream = await this.client.getMediaHandler().getUserMediaStream(
true,
this.type === CallType.Video,
this.hasRemoteUserMediaVideoTrack,
);
this.waitForLocalAVStream = false;
this.gotUserMediaForAnswer(mediaStream);
Expand Down Expand Up @@ -986,7 +1002,7 @@ export class MatrixCall extends EventEmitter {
this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia);
this.setState(CallState.CreateOffer);

logger.debug("gotUserMediaForInvite -> " + this.type);
logger.debug("gotUserMediaForInvite");
// Now we wait for the negotiationneeded event
};

Expand Down Expand Up @@ -1803,7 +1819,6 @@ export class MatrixCall extends EventEmitter {
if (!audio) {
throw new Error("You CANNOT start a call without audio");
}
this.type = video ? CallType.Video : CallType.Voice;
this.checkForErrorListener();
// XXX Find a better way to do this
this.client.callEventHandler.calls.set(this.callId, this);
Expand Down

0 comments on commit d916d3f

Please sign in to comment.