mirror of
https://github.com/owncast/owncast.git
synced 2024-10-10 19:16:02 +00:00
![dependabot[bot]](/assets/img/avatar_default.png)
* Commit updated Javascript packages * Bump preact from 10.5.4 to 10.5.5 in /build/javascript (#265) * Trying a new github workflow to install javascript packages * Bump tailwindcss from 1.9.2 to 1.9.4 in /build/javascript (#266) Bumps [tailwindcss](https://github.com/tailwindlabs/tailwindcss) from 1.9.2 to 1.9.4. - [Release notes](https://github.com/tailwindlabs/tailwindcss/releases) - [Changelog](https://github.com/tailwindlabs/tailwindcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/tailwindlabs/tailwindcss/compare/v1.9.2...v1.9.4) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Commit updated Javascript packages * Bump preact from 10.5.4 to 10.5.5 in /build/javascript Bumps [preact](https://github.com/preactjs/preact) from 10.5.4 to 10.5.5. - [Release notes](https://github.com/preactjs/preact/releases) - [Commits](https://github.com/preactjs/preact/compare/10.5.4...10.5.5) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Owncast <owncast@owncast.online> * Bump @justinribeiro/lite-youtube in /build/javascript Bumps [@justinribeiro/lite-youtube](https://github.com/justinribeiro/lite-youtube) from 0.9.0 to 0.9.1. - [Release notes](https://github.com/justinribeiro/lite-youtube/releases) - [Commits](https://github.com/justinribeiro/lite-youtube/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Owncast <owncast@owncast.online> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com>
142 lines
4.1 KiB
JavaScript
142 lines
4.1 KiB
JavaScript
/**
|
|
* mux.js
|
|
*
|
|
* Copyright (c) Brightcove
|
|
* Licensed Apache-2.0 https://github.com/videojs/mux.js/blob/master/LICENSE
|
|
*
|
|
* A lightweight readable stream implemention that handles event dispatching.
|
|
* Objects that inherit from streams should call init in their constructors.
|
|
*/
|
|
'use strict';
|
|
|
|
var Stream = function() {
|
|
this.init = function() {
|
|
var listeners = {};
|
|
/**
|
|
* Add a listener for a specified event type.
|
|
* @param type {string} the event name
|
|
* @param listener {function} the callback to be invoked when an event of
|
|
* the specified type occurs
|
|
*/
|
|
this.on = function(type, listener) {
|
|
if (!listeners[type]) {
|
|
listeners[type] = [];
|
|
}
|
|
listeners[type] = listeners[type].concat(listener);
|
|
};
|
|
/**
|
|
* Remove a listener for a specified event type.
|
|
* @param type {string} the event name
|
|
* @param listener {function} a function previously registered for this
|
|
* type of event through `on`
|
|
*/
|
|
this.off = function(type, listener) {
|
|
var index;
|
|
if (!listeners[type]) {
|
|
return false;
|
|
}
|
|
index = listeners[type].indexOf(listener);
|
|
listeners[type] = listeners[type].slice();
|
|
listeners[type].splice(index, 1);
|
|
return index > -1;
|
|
};
|
|
/**
|
|
* Trigger an event of the specified type on this stream. Any additional
|
|
* arguments to this function are passed as parameters to event listeners.
|
|
* @param type {string} the event name
|
|
*/
|
|
this.trigger = function(type) {
|
|
var callbacks, i, length, args;
|
|
callbacks = listeners[type];
|
|
if (!callbacks) {
|
|
return;
|
|
}
|
|
// Slicing the arguments on every invocation of this method
|
|
// can add a significant amount of overhead. Avoid the
|
|
// intermediate object creation for the common case of a
|
|
// single callback argument
|
|
if (arguments.length === 2) {
|
|
length = callbacks.length;
|
|
for (i = 0; i < length; ++i) {
|
|
callbacks[i].call(this, arguments[1]);
|
|
}
|
|
} else {
|
|
args = [];
|
|
i = arguments.length;
|
|
for (i = 1; i < arguments.length; ++i) {
|
|
args.push(arguments[i]);
|
|
}
|
|
length = callbacks.length;
|
|
for (i = 0; i < length; ++i) {
|
|
callbacks[i].apply(this, args);
|
|
}
|
|
}
|
|
};
|
|
/**
|
|
* Destroys the stream and cleans up.
|
|
*/
|
|
this.dispose = function() {
|
|
listeners = {};
|
|
};
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Forwards all `data` events on this stream to the destination stream. The
|
|
* destination stream should provide a method `push` to receive the data
|
|
* events as they arrive.
|
|
* @param destination {stream} the stream that will receive all `data` events
|
|
* @param autoFlush {boolean} if false, we will not call `flush` on the destination
|
|
* when the current stream emits a 'done' event
|
|
* @see http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
|
|
*/
|
|
Stream.prototype.pipe = function(destination) {
|
|
this.on('data', function(data) {
|
|
destination.push(data);
|
|
});
|
|
|
|
this.on('done', function(flushSource) {
|
|
destination.flush(flushSource);
|
|
});
|
|
|
|
this.on('partialdone', function(flushSource) {
|
|
destination.partialFlush(flushSource);
|
|
});
|
|
|
|
this.on('endedtimeline', function(flushSource) {
|
|
destination.endTimeline(flushSource);
|
|
});
|
|
|
|
this.on('reset', function(flushSource) {
|
|
destination.reset(flushSource);
|
|
});
|
|
|
|
return destination;
|
|
};
|
|
|
|
// Default stream functions that are expected to be overridden to perform
|
|
// actual work. These are provided by the prototype as a sort of no-op
|
|
// implementation so that we don't have to check for their existence in the
|
|
// `pipe` function above.
|
|
Stream.prototype.push = function(data) {
|
|
this.trigger('data', data);
|
|
};
|
|
|
|
Stream.prototype.flush = function(flushSource) {
|
|
this.trigger('done', flushSource);
|
|
};
|
|
|
|
Stream.prototype.partialFlush = function(flushSource) {
|
|
this.trigger('partialdone', flushSource);
|
|
};
|
|
|
|
Stream.prototype.endTimeline = function(flushSource) {
|
|
this.trigger('endedtimeline', flushSource);
|
|
};
|
|
|
|
Stream.prototype.reset = function(flushSource) {
|
|
this.trigger('reset', flushSource);
|
|
};
|
|
|
|
module.exports = Stream;
|