openvidu/openvidu-testapp/src/app/components/video-track/video-track.component.ts

108 lines
3.0 KiB
TypeScript
Raw Normal View History

import { Component } from '@angular/core';
import {
LocalTrack,
VideoTrack,
RemoteTrackPublication,
VideoQuality,
} from 'livekit-client';
2024-07-02 19:19:05 +02:00
import { TrackComponent } from '../track/track.component';
import { MatDialog } from '@angular/material/dialog';
import { TestFeedService } from 'src/app/services/test-feed.service';
import { InfoDialogComponent } from '../dialogs/info-dialog/info-dialog.component';
2024-07-02 19:19:05 +02:00
@Component({
selector: 'app-video-track',
templateUrl: './video-track.component.html',
styleUrls: ['./video-track.component.css'],
2024-07-02 19:19:05 +02:00
})
export class VideoTrackComponent extends TrackComponent {
muteVideoIcon: string = 'videocam';
blurIcon: string = 'blur_on';
maxVideoQuality: string;
2024-07-02 19:19:05 +02:00
2024-10-24 11:36:52 +02:00
videoZoom = false;
constructor(
protected override testFeedService: TestFeedService,
private dialog: MatDialog
) {
super(testFeedService);
}
2024-07-02 19:19:05 +02:00
async muteUnmuteVideo() {
if (this._track?.isMuted) {
this.muteVideoIcon = 'videocam';
await (this._track as LocalTrack).unmute();
} else {
this.muteVideoIcon = 'videocam_off';
await (this._track as LocalTrack).mute();
2024-07-02 19:19:05 +02:00
}
}
2024-07-02 19:19:05 +02:00
async onQualityChange() {
let videoQuality: VideoQuality;
switch (this.maxVideoQuality) {
case 'LOW':
videoQuality = VideoQuality.LOW;
break;
case 'MEDIUM':
videoQuality = VideoQuality.MEDIUM;
break;
case 'HIGH':
videoQuality = VideoQuality.HIGH;
break;
default:
videoQuality = VideoQuality.HIGH;
2024-07-02 19:19:05 +02:00
}
await (this.trackPublication as RemoteTrackPublication).setVideoQuality(
videoQuality
);
}
2024-07-02 19:19:05 +02:00
openInfoDialog() {
const updateFunction = async (): Promise<string> => {
const videoLayers: any[] = [];
let stats = await (this._track! as VideoTrack).getRTCStatsReport();
stats?.forEach((report) => {
if (report.type === 'outbound-rtp' || report.type === 'inbound-rtp') {
videoLayers.push({
codecId: report.codecId,
scalabilityMode: report.scalabilityMode,
rid: report.rid,
active: report.active,
frameWidth: report.frameWidth,
frameHeight: report.frameHeight,
framesPerSecond: report.framesPerSecond,
bytesReceived: report.bytesReceived,
bytesSent: report.bytesSent,
});
2024-07-02 19:19:05 +02:00
}
});
return JSON.stringify(videoLayers, null, 2);
};
this.dialog.open(InfoDialogComponent, {
data: {
title: 'Video Track Layers Info',
subtitle: this.finalElementRefId,
updateFunction,
},
});
}
2024-07-02 19:19:05 +02:00
async blur() {
if (this.blurIcon == 'blur_on') {
// await (this._track! as LocalVideoTrack).setProcessor(BackgroundBlur());
this.blurIcon = 'blur_off';
} else {
// await (this._track! as LocalVideoTrack).stopProcessor();
this.blurIcon = 'blur_on';
}
}
2024-10-24 11:36:52 +02:00
toggleVideoZoom() {
this.videoZoom = !this.videoZoom;
let newWidth = this.videoZoom ? '720px' : '120px';
this.elementRef.nativeElement.style.width = newWidth;
}
2024-07-02 19:19:05 +02:00
}