openvidu/openvidu-testapp/src/app/app.component.ts

65 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Component, ChangeDetectionStrategy } from '@angular/core';
2026-03-31 12:06:23 +02:00
import { FormsModule } from '@angular/forms';
import { Router, RouterOutlet, RouterLink } from '@angular/router';
2024-07-02 19:19:05 +02:00
import { LogLevel, setLogLevel } from 'livekit-client';
import { LivekitParamsService } from './services/livekit-params.service';
2026-03-31 12:06:23 +02:00
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
2017-09-26 18:13:00 +02:00
@Component({
2025-02-19 12:03:43 +01:00
selector: 'app-root',
templateUrl: './app.component.html',
2026-03-31 12:06:23 +02:00
styleUrl: './app.component.css',
changeDetection: ChangeDetectionStrategy.Eager,
2026-03-31 12:06:23 +02:00
imports: [FormsModule, RouterOutlet, RouterLink, MatSidenavModule, MatToolbarModule, MatFormFieldModule, MatInputModule, MatButtonModule],
2017-09-26 18:13:00 +02:00
})
export class AppComponent {
2024-07-02 19:19:05 +02:00
livekitUrl = 'ws://localhost:7880/'; // `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://localhost:1880/`;
livekitApiKey = 'devkey';
livekitApiSecret = 'secret';
2017-09-26 18:13:00 +02:00
constructor(
private router: Router,
private livekitParamsService: LivekitParamsService
) {}
2024-07-02 19:19:05 +02:00
async ngOnInit() {
// LiveKit client logging. Change here to build with verbose logging.
// Levels: trace, debug, info (default), warn, error, silent.
setLogLevel(LogLevel.debug);
await this.updateParams();
console.log('LiveKit credentials updated');
}
updateUrl(url: any) {
this.livekitUrl = url;
this.updateParams();
}
2024-07-02 19:19:05 +02:00
updateApiKey(apiKey: any) {
this.livekitApiKey = apiKey;
this.updateParams();
}
2024-07-02 19:19:05 +02:00
updateApiSecret(apiSecret: any) {
this.livekitApiSecret = apiSecret;
this.updateParams();
}
async updateParams() {
let myUrl = this.livekitUrl;
if (!(myUrl.substring(myUrl.length - 1) === '/')) {
myUrl += '/';
}
await this.livekitParamsService.updateParams({
livekitUrl: myUrl,
livekitApiKey: this.livekitApiKey,
livekitApiSecret: this.livekitApiSecret,
});
2017-09-26 18:13:00 +02:00
}
}