|
|
|
|
|
|
|
|
import {AfterViewInit, Component, ElementRef, ViewChild} from '@angular/core'; |
|
|
|
|
|
|
|
|
import {AfterViewInit, Component, ElementRef, OnDestroy, ViewChild} from '@angular/core'; |
|
|
import {MatDialogRef} from "@angular/material/dialog"; |
|
|
import {MatDialogRef} from "@angular/material/dialog"; |
|
|
import {loadPlayer, Player} from "rtsp-relay/browser"; |
|
|
import {loadPlayer, Player} from "rtsp-relay/browser"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templateUrl: './camera-dialog.component.html', |
|
|
templateUrl: './camera-dialog.component.html', |
|
|
styleUrls: ['./camera-dialog.component.scss'] |
|
|
styleUrls: ['./camera-dialog.component.scss'] |
|
|
}) |
|
|
}) |
|
|
export class CameraDialogComponent implements AfterViewInit{ |
|
|
|
|
|
|
|
|
export class CameraDialogComponent implements AfterViewInit, OnDestroy{ |
|
|
|
|
|
|
|
|
player?: Player; |
|
|
player?: Player; |
|
|
videoLoaded: boolean = false; |
|
|
|
|
|
@ViewChild('videoPlayer') videoPlayer?: ElementRef<HTMLCanvasElement>; |
|
|
@ViewChild('videoPlayer') videoPlayer?: ElementRef<HTMLCanvasElement>; |
|
|
|
|
|
|
|
|
constructor(public dialogRef: MatDialogRef<CameraDialogComponent>) { } |
|
|
constructor(public dialogRef: MatDialogRef<CameraDialogComponent>) { } |
|
|
|
|
|
|
|
|
async ngAfterViewInit() { |
|
|
async ngAfterViewInit() { |
|
|
const connect = async () => { |
|
|
|
|
|
this.player = await loadPlayer({ |
|
|
this.player = await loadPlayer({ |
|
|
url: 'wss://wss.aztrace.vn/stream', |
|
|
url: 'wss://wss.aztrace.vn/stream', |
|
|
canvas: this.videoPlayer!.nativeElement, |
|
|
canvas: this.videoPlayer!.nativeElement, |
|
|
onDisconnect: () => { |
|
|
|
|
|
setTimeout(connect, 5000); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
onDisconnect(): void{ |
|
|
|
|
|
console.log('disconnect camera, please wait'); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
this.videoLoaded = true; |
|
|
|
|
|
}; |
|
|
|
|
|
connect(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onClose(): void { |
|
|
onClose(): void { |
|
|
this.dialogRef.close(); |
|
|
this.dialogRef.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
|
|
|
if (this.player){ |
|
|
|
|
|
this.player?.destroy(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |