import { r as registerInstance, h } from './index-7ec78587.js';

const akordVideoStreamViewerCss = "akord-video-stream-viewer{}";

let AkordVideoStreamViewer = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.loading = false;
  }
  componentDidLoad() {
    this.initVideo();
    this.stream();
  }
  initVideo() {
    this.mediaSource = new MediaSource();
    this.mediaSource.addEventListener('sourceopen', () => {
      console.log('open', this.mediaSource);
      this.videoSourceBuffer = this.mediaSource.addSourceBuffer('video/mp4; codecs="avc1.64001e"');
      console.log('added source buffer');
      console.log(this.mediaSource);
    });
    this.mediaSourceUrl = URL.createObjectURL(this.mediaSource);
    this.videoEl.src = this.mediaSourceUrl;
    console.log(this.videoEl);
  }
  onCanPlay() {
    this.loading = false;
  }
  stream() {
    console.log("streaming");
    fetch(this.src)
      .then((response) => response.arrayBuffer())
      .then((videoData) => {
      console.log(this.videoSourceBuffer);
      console.log(videoData);
      this.videoSourceBuffer.appendBuffer(videoData);
      console.log(this.videoSourceBuffer);
    });
  }
  render() {
    if (this.loading)
      return (null);
    return (h("video", { controls: true, onCanPlay: () => this.onCanPlay(), ref: (el) => {
        this.videoEl = el;
        console.log(this.videoEl);
      } }, "Video playback is not supported by your browser."));
  }
};
AkordVideoStreamViewer.style = akordVideoStreamViewerCss;

export { AkordVideoStreamViewer as akord_video_stream_viewer };
