UNPKG

@tvkitchen/appliance-video-http-receiver

Version:

Converts a video url into MPEG-TS Payloads.

58 lines (46 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VideoHttpReceiverAppliance = void 0; var _stream = require("stream"); var _nodeFetch = _interopRequireDefault(require("node-fetch")); var _applianceCore = require("@tvkitchen/appliance-core"); 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; } /** * The VideoHttpReceiverAppliance is able to process data from an HTTP video stream. It is an * implementation of AbstractVideoReceiverAppliance, which reads in a stream, converts it into * an MPEG-TS stream represented as a series of Payloads, and then emits those Payloads. * * @extends AbstractVideoReceiverAppliance */ class VideoHttpReceiverAppliance extends _applianceCore.AbstractVideoReceiverAppliance { /** * Create a VideoHttpReceiverAppliance. * * @param {string} settings.url The url of the stream to be ingested */ constructor(settings) { super({ url: '', ...settings }); _defineProperty(this, "getInputStream", () => { const stream = new _stream.PassThrough(); (0, _nodeFetch.default)(this.settings.url).then(response => { response.body.pipe(stream); }).catch(err => { stream.emit('error', err); }); return stream; }); if (!settings.url) { throw new Error('VideoHttpReceiverAppliance must be instantiated with a stream URL'); } } /** * @inheritdoc */ } exports.VideoHttpReceiverAppliance = VideoHttpReceiverAppliance;