You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
896B

  1. import {Component, OnInit, ViewChild, ElementRef, AfterViewInit, Renderer2} from '@angular/core';
  2. import {loadPlayer, Player} from "rtsp-relay/browser";
  3. @Component({
  4. selector: 'app-camera-stream',
  5. templateUrl: './camera-stream.component.html',
  6. styleUrls: ['./camera-stream.component.scss']
  7. })
  8. export class CameraStreamComponent implements OnInit, AfterViewInit{
  9. player?: Player;
  10. @ViewChild('videoPlayer')
  11. videoPlayer?: ElementRef<HTMLCanvasElement>;
  12. constructor(private el: ElementRef, private renderer: Renderer2) {}
  13. ngOnInit() {
  14. }
  15. async ngAfterViewInit() {
  16. const connect = async () => {
  17. this.player = await loadPlayer({
  18. url: 'ws://localhost:8080/stream',
  19. canvas: this.videoPlayer!.nativeElement,
  20. onDisconnect: () => {
  21. setTimeout(connect, 5000); // reconnect after 5 seconds
  22. },
  23. });
  24. };
  25. connect();
  26. }
  27. }