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 Aug 29, 2021
1 parent 15e3508 commit 9f9524e
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ function genCallID(): string {
*/
export class MatrixCall extends EventEmitter {
roomId: string;
type: CallType;
callId: string;
state: CallState;
hangupParty: CallParty;
Expand Down Expand Up @@ -312,7 +311,6 @@ export class MatrixCall extends EventEmitter {
super();
this.roomId = opts.roomId;
this.client = opts.client;
this.type = null;
this.forceTURN = opts.forceTURN;
this.ourPartyId = this.client.deviceId;
// Array of Objects with urls, username, credential keys
Expand Down Expand Up @@ -379,6 +377,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 @@ -637,8 +654,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 @@ -676,7 +691,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 @@ -685,7 +700,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 @@ -764,7 +779,7 @@ export class MatrixCall extends EventEmitter {
* @returns new mute state
*/
public async upgradeCall(): Promise<boolean> {
if (this.type !== CallType.Voice) return;
if (this.hasLocalUserMediaVideoTrack) return;
if (!this.opponentSupportsSDPStreamMetadata()) return;

try {
Expand Down Expand Up @@ -905,7 +920,7 @@ export class MatrixCall extends EventEmitter {
* @returns the new mute state
*/
async setLocalVideoMuted(muted: boolean): Promise<boolean> {
if (this.type === CallType.Voice && !muted) {
if (!this.hasLocalUserMediaVideoTrack && !muted) {
return await this.upgradeCall();
}
this.localUsermediaFeed?.setVideoMuted(muted);
Expand Down Expand Up @@ -1036,7 +1051,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 @@ -1841,7 +1856,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 9f9524e

Please sign in to comment.