@tvkitchen/countertop
Version:
The entry point for developers who want to set up a TV Kitchen.
82 lines (58 loc) • 3.12 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _assert = _interopRequireDefault(require("assert"));
var _uuid = require("uuid");
var _countertop = require("../tools/utils/countertop");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
class CountertopStream {
/**
* Create a new CountertopStream.
*
* CountertopStreams are made up of a distinct stream of stations (e.g. Appliance instances).
* This allows a given countertop to have multiple sources of video data being processed
* simultaneously.
*
* The tributary map does not need to be complete -- there can be inputs with no associated
* tributary streams.
*
* The tributary map cannot contain irrelevant streams (the output map should match the inputs).
*
* @param {CountertopStation} station The station at the end of the stream.
* @param {Map} tributaries The streams that are flowing into the final station.
*/
constructor(_station, tributaries = new Map()) {
_defineProperty(this, "id", null);
_defineProperty(this, "tributaries", null);
_defineProperty(this, "mouth", null);
_defineProperty(this, "source", null);
_defineProperty(this, "getSource", () => this.source);
_defineProperty(this, "getMouth", () => this.mouth);
_defineProperty(this, "getTributaryMap", () => this.tributaries);
_defineProperty(this, "getTributaryArray", () => [...this.tributaries.values()]);
_defineProperty(this, "getLength", () => (0, _countertop.getLongestStreamLength)(this.getTributaryArray()) + 1);
_defineProperty(this, "includesStation", station => this.mouth === station || this.getTributaryArray().some(tributary => tributary.includesStation(station)));
_defineProperty(this, "includesStream", stream => this.getTributaryArray().includes(stream) || this.getTributaryArray().some(tributary => tributary.includesStream(stream)));
_defineProperty(this, "getOutputTypes", () => this.mouth.getOutputTypes());
Array.from(tributaries.keys()).forEach(outputType => (0, _assert.default)(_station.getInputTypes().includes(outputType), 'The tributaries contained an invalid stream type.'));
this.id = `CountertopStream::${(0, _uuid.v4)()}`;
this.mouth = _station;
this.tributaries = tributaries;
if (_station.getInputTypes().length === 0) {
this.source = _station;
} else {
var _getSourcesFromStream;
this.source = (_getSourcesFromStream = (0, _countertop.getSourcesFromStreamMap)(tributaries).pop()) !== null && _getSourcesFromStream !== void 0 ? _getSourcesFromStream : null;
}
}
/**
* Get the origin / first station in the stream.
*
* @return {CountertopStation} The origin station in the stream.
*/
}
var _default = CountertopStream;
exports.default = _default;