1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Internally remove call types

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2021-08-29 10:43:19 +02:00
parent 1bd7de5a18
commit 7143ef8a32

View File

@@ -251,7 +251,6 @@ function genCallID(): string {
*/ */
export class MatrixCall extends EventEmitter { export class MatrixCall extends EventEmitter {
public roomId: string; public roomId: string;
public type: CallType = null;
public callId: string; public callId: string;
public state = CallState.Fledgling; public state = CallState.Fledgling;
public hangupParty: CallParty; public hangupParty: CallParty;
@@ -359,6 +358,25 @@ export class MatrixCall extends EventEmitter {
return this.remoteAssertedIdentity; 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 { public get localUsermediaFeed(): CallFeed {
return this.getLocalFeeds().find((feed) => feed.purpose === SDPStreamMetadataPurpose.Usermedia); return this.getLocalFeeds().find((feed) => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
} }
@@ -617,8 +635,6 @@ export class MatrixCall extends EventEmitter {
return; return;
} }
this.type = remoteStream.getTracks().some(t => t.kind === 'video') ? CallType.Video : CallType.Voice;
this.setState(CallState.Ringing); this.setState(CallState.Ringing);
if (event.getLocalAge()) { if (event.getLocalAge()) {
@@ -656,7 +672,7 @@ export class MatrixCall extends EventEmitter {
return; return;
} }
logger.debug(`Answering call ${this.callId} of type ${this.type}`); logger.debug(`Answering call ${this.callId}`);
if (!this.localUsermediaStream && !this.waitForLocalAVStream) { if (!this.localUsermediaStream && !this.waitForLocalAVStream) {
this.setState(CallState.WaitLocalMedia); this.setState(CallState.WaitLocalMedia);
@@ -665,7 +681,7 @@ export class MatrixCall extends EventEmitter {
try { try {
const mediaStream = await this.client.getMediaHandler().getUserMediaStream( const mediaStream = await this.client.getMediaHandler().getUserMediaStream(
true, true,
this.type === CallType.Video, this.hasRemoteUserMediaVideoTrack,
); );
this.waitForLocalAVStream = false; this.waitForLocalAVStream = false;
this.gotUserMediaForAnswer(mediaStream); this.gotUserMediaForAnswer(mediaStream);
@@ -986,7 +1002,7 @@ export class MatrixCall extends EventEmitter {
this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia); this.pushLocalFeed(stream, SDPStreamMetadataPurpose.Usermedia);
this.setState(CallState.CreateOffer); this.setState(CallState.CreateOffer);
logger.debug("gotUserMediaForInvite -> " + this.type); logger.debug("gotUserMediaForInvite");
// Now we wait for the negotiationneeded event // Now we wait for the negotiationneeded event
}; };
@@ -1803,7 +1819,6 @@ export class MatrixCall extends EventEmitter {
if (!audio) { if (!audio) {
throw new Error("You CANNOT start a call without audio"); throw new Error("You CANNOT start a call without audio");
} }
this.type = video ? CallType.Video : CallType.Voice;
this.checkForErrorListener(); this.checkForErrorListener();
// XXX Find a better way to do this // XXX Find a better way to do this
this.client.callEventHandler.calls.set(this.callId, this); this.client.callEventHandler.calls.set(this.callId, this);