Home Reference Source

src/utils/output-filter.ts

import { CaptionScreen } from './cea-608-parser';
import type TimelineController from '../controller/timeline-controller';

export default class OutputFilter {
  timelineController: TimelineController;
  trackName: string;
  startTime: number | null;
  endTime: number | null;
  screen: CaptionScreen | null;

  constructor (timelineController: TimelineController, trackName: string) {
    this.timelineController = timelineController;
    this.trackName = trackName;
    this.startTime = null;
    this.endTime = null;
    this.screen = null;
  }

  dispatchCue () {
    if (this.startTime === null) {
      return;
    }

    this.timelineController.addCues(this.trackName, this.startTime, this.endTime as number, this.screen as CaptionScreen);
    this.startTime = null;
  }

  newCue (startTime: number, endTime: number, screen: CaptionScreen) {
    if (this.startTime === null || this.startTime > startTime) {
      this.startTime = startTime;
    }

    this.endTime = endTime;
    this.screen = screen;
    this.timelineController.createCaptionsTrack(this.trackName);
  }
}