1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Use ICallFeedOpts in the CallFeed constructor

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2021-10-02 08:12:43 +02:00
parent a7a08fd760
commit c63abe9988
2 changed files with 55 additions and 13 deletions

View File

@@ -497,7 +497,15 @@ export class MatrixCall extends EventEmitter {
if (existingFeed) { if (existingFeed) {
existingFeed.setNewStream(stream); existingFeed.setNewStream(stream);
} else { } else {
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId, audioMuted, videoMuted)); this.feeds.push(new CallFeed({
client: this.client,
roomId: this.roomId,
userId,
stream,
purpose,
audioMuted,
videoMuted,
}));
this.emit(CallEvent.FeedsChanged, this.feeds); this.emit(CallEvent.FeedsChanged, this.feeds);
} }
@@ -528,7 +536,15 @@ export class MatrixCall extends EventEmitter {
if (feed) { if (feed) {
feed.setNewStream(stream); feed.setNewStream(stream);
} else { } else {
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId, false, false)); this.feeds.push(new CallFeed({
client: this.client,
roomId: this.roomId,
audioMuted: false,
videoMuted: false,
userId,
stream,
purpose,
}));
this.emit(CallEvent.FeedsChanged, this.feeds); this.emit(CallEvent.FeedsChanged, this.feeds);
} }
@@ -543,7 +559,15 @@ export class MatrixCall extends EventEmitter {
if (existingFeed) { if (existingFeed) {
existingFeed.setNewStream(stream); existingFeed.setNewStream(stream);
} else { } else {
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId, false, false)); this.feeds.push(new CallFeed({
client: this.client,
roomId: this.roomId,
audioMuted: false,
videoMuted: false,
userId,
stream,
purpose,
}));
this.emit(CallEvent.FeedsChanged, this.feeds); this.emit(CallEvent.FeedsChanged, this.feeds);
} }

View File

@@ -22,6 +22,16 @@ import { RoomMember } from "../models/room-member";
const POLLING_INTERVAL = 250; // ms const POLLING_INTERVAL = 250; // ms
const SPEAKING_THRESHOLD = -60; // dB const SPEAKING_THRESHOLD = -60; // dB
export interface ICallFeedOpts {
client: MatrixClient;
roomId: string;
userId: string;
stream: MediaStream;
purpose: SDPStreamMetadataPurpose;
audioMuted: boolean;
videoMuted: boolean;
}
export enum CallFeedEvent { export enum CallFeedEvent {
NewStream = "new_stream", NewStream = "new_stream",
MuteStateChanged = "mute_state_changed", MuteStateChanged = "mute_state_changed",
@@ -30,6 +40,14 @@ export enum CallFeedEvent {
} }
export class CallFeed extends EventEmitter { export class CallFeed extends EventEmitter {
public stream: MediaStream;
public userId: string;
public purpose: SDPStreamMetadataPurpose;
private client: MatrixClient;
private roomId: string;
private audioMuted: boolean;
private videoMuted: boolean;
private measuringVolumeActivity = false; private measuringVolumeActivity = false;
private audioContext: AudioContext; private audioContext: AudioContext;
private analyser: AnalyserNode; private analyser: AnalyserNode;
@@ -38,17 +56,17 @@ export class CallFeed extends EventEmitter {
private speaking = false; private speaking = false;
private volumeLooperTimeout: number; private volumeLooperTimeout: number;
constructor( constructor(opts: ICallFeedOpts) {
public stream: MediaStream,
public userId: string,
public purpose: SDPStreamMetadataPurpose,
private client: MatrixClient,
private roomId: string,
private audioMuted: boolean,
private videoMuted: boolean,
) {
super(); super();
this.updateStream(null, stream);
this.client = opts.client;
this.roomId = opts.roomId;
this.userId = opts.userId;
this.purpose = opts.purpose;
this.audioMuted = opts.audioMuted;
this.videoMuted = opts.videoMuted;
this.updateStream(null, opts.stream);
if (this.hasAudioTrack) { if (this.hasAudioTrack) {
this.initVolumeMeasuring(); this.initVolumeMeasuring();