Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 868 Bytes

angular.md

File metadata and controls

37 lines (29 loc) · 868 Bytes

app.component.html

<canvas #videoPlayer></canvas>

app.component.js

import { Component, ElementRef, AfterViewInit, ViewChild } from '@angular/core';
import { loadPlayer, Player } from 'rtsp-relay/browser';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent implements AfterViewInit {
  /** the instance of the rtsp-relay client */
  player?: Player;

  @ViewChild('videoPlayer')
  videoPlayer?: ElementRef<HTMLCanvasElement>;

  async ngAfterViewInit() {
    // this will wait until the connection is established
    this.player = await loadPlayer({
      url: 'ws://localhost:2000/api/stream/1',
      canvas: this.videoPlayer!.nativeElement,

      // optional
      onDisconnect: () => console.log('Connection lost!'),
    });

    console.log('Connected!', this.player);
  }
}