2022-04-21 21:09:11 +05:30
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type {Track, Stream} from "../../platform/types/MediaDevices";
|
|
|
|
|
|
|
|
export function getStreamAudioTrack(stream: Stream | undefined): Track | undefined {
|
|
|
|
return stream?.getAudioTracks()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getStreamVideoTrack(stream: Stream | undefined): Track | undefined {
|
|
|
|
return stream?.getVideoTracks()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
export class MuteSettings {
|
2022-06-10 20:40:23 +05:30
|
|
|
constructor (
|
|
|
|
private readonly isMicrophoneMuted: boolean = false,
|
|
|
|
private readonly isCameraMuted: boolean = false,
|
|
|
|
private hasMicrophoneTrack: boolean = false,
|
|
|
|
private hasCameraTrack: boolean = false,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
updateTrackInfo(userMedia: Stream | undefined) {
|
|
|
|
this.hasMicrophoneTrack = !!getStreamAudioTrack(userMedia);
|
|
|
|
this.hasCameraTrack = !!getStreamVideoTrack(userMedia);
|
|
|
|
}
|
|
|
|
|
|
|
|
get microphone(): boolean {
|
|
|
|
return !this.hasMicrophoneTrack || this.isMicrophoneMuted;
|
|
|
|
}
|
|
|
|
|
|
|
|
get camera(): boolean {
|
|
|
|
return !this.hasCameraTrack || this.isCameraMuted;
|
|
|
|
}
|
2022-04-22 19:18:14 +05:30
|
|
|
|
|
|
|
toggleCamera(): MuteSettings {
|
2022-06-10 20:40:23 +05:30
|
|
|
return new MuteSettings(this.microphone, !this.camera, this.hasMicrophoneTrack, this.hasCameraTrack);
|
2022-04-22 19:18:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
toggleMicrophone(): MuteSettings {
|
2022-06-10 20:40:23 +05:30
|
|
|
return new MuteSettings(!this.microphone, this.camera, this.hasMicrophoneTrack, this.hasCameraTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
equals(other: MuteSettings) {
|
|
|
|
return this.microphone === other.microphone && this.camera === other.camera;
|
2022-04-22 19:18:14 +05:30
|
|
|
}
|
2022-04-21 21:09:11 +05:30
|
|
|
}
|
2022-05-04 22:14:11 +05:30
|
|
|
|
|
|
|
export const CALL_LOG_TYPE = "call";
|