@ignitify-integrations/stream 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ ignitify integrations
2
+ Copyright 2026 The ignitify integrations authors
3
+
4
+ This product includes software developed by the ignitify integrations authors.
5
+
6
+ integrations/stream serves hls.js (https://github.com/video-dev/hls.js), Apache-2.0, from its npm package at run time.
7
+ integrations/stream drives ffmpeg (https://ffmpeg.org) as a separate process. ffmpeg is not distributed by this project;
8
+ it is installed in the task image as a system package and keeps its own licence (LGPL-2.1-or-later, or GPL when
9
+ built with GPL components).
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
1
+ # stream
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Let a task serve a live audio or video stream that viewers open in any browser. ffmpeg does the media work; this package does the platform plumbing (server, player page, viewer link, progress, stop on cancel).
4
+
5
+ ## Add it
6
+
7
+ ```bash
8
+ ignitify integration:add stream --task live
9
+ ```
10
+
11
+ The plan line says `runs ffmpeg`. The plan adds `ffmpeg` to `build.system_packages`, a bidirectional network with port 8080 and the route `/live/`, a long continuous execution, and at least the `std.medium` preset.
12
+
13
+ **You add one host** when the source is an `https://` URL: the source host (for example `raw.githubusercontent.com`) in `execution.network.egress_allow`. A file on the VM needs no host.
14
+
15
+ ## Use it
16
+
17
+ ```ts
18
+ import { stream } from '@ignitify-integrations/stream';
19
+
20
+ export async function run(payload, ctx) {
21
+ return stream(ctx, { source: payload.url, seconds: payload.seconds });
22
+ }
23
+ ```
24
+
25
+ The first chunk the caller gets is `{ status: 'live', watch, playlist }`. A viewer opens `watch` (the deployment's public host + `/live/`). Then progress chunks follow: `{ status: 'streaming', time_s, of_s, speed }`, at most every 2 s.
26
+
27
+ | Option | Default | Meaning |
28
+ | :-------------- | :------------------- | :---------------------------------------------------------------------------------------------------------------------------- |
29
+ | `source` | — | `https://` URL, or an absolute file path on the VM |
30
+ | `profile` | `'video'` | `'video'` (x264 + AAC) or `'audio'` (AAC only) |
31
+ | `seconds` | whole source | Stop after this many seconds; `run.timeout_sec` is the safety stop |
32
+ | `height` | 480 | Output height in pixels (1–2160); ignored for `audio` |
33
+ | `startDelaySec` | 0 | Serve the player first, start the stream later |
34
+ | `after` | `'replay'` | `'replay'`: keep serving the recording until cancel (or `lingerSec`). `'stop'`: return when ffmpeg ends |
35
+ | `lingerSec` | none | With `replay`: stop this long after the end |
36
+ | `route`, `port` | `'/live/'`, 8080 | Must equal `inbound_routes` and `inbound_port` in `task.yaml` |
37
+ | `ffmpegArgs` | — | `(defaults, paths) => args`: change the encoder arguments. Keep `-progress pipe:1` and write the playlist to `paths.playlist` |
38
+ | `onProgress` | — | Called for every ffmpeg progress report |
39
+ | `signal` | `SIGTERM` / `SIGINT` | An `AbortSignal` that stops the stream |
40
+
41
+ The result is `{ success: true, stage: 'streamed', cancelled, watch, streamed_s, height, wall_ms }`, or `{ success: true, cancelled: true, stage: 'before-stream' }` when it is stopped during the start delay. A failed ffmpeg run throws, with the end of ffmpeg's error output in the message.
42
+
43
+ ## Grow your task
44
+
45
+ - **A radio-style stream.** Use `profile: 'audio'`.
46
+ - **Give viewers time to join.** Use `startDelaySec`, and send the link first: `watchUrl(ctx)` returns it before the stream starts (for example, in a chat message).
47
+ - **Keep the recording.** Use `after: 'stop'`; the playlist and segments stay in `$HOME/hls` until the next stream starts. To return one playable link, upload each segment with [`s3-storage`](https://github.com/ignitify-dev/ignitify-integrations/tree/master/integrations/s3-storage)'s `put` under one prefix, keeping its file name (`key: 'rec/<file>'`), then the playlist with `putAndLink` and the same prefix, and return that link. The player fetches the segments by plain URL, so the prefix must allow public read. With a private bucket, return one link per file.
48
+ - **Your own encoding.** Change bitrate, codec or filters with `ffmpegArgs`; the package still runs the server and the progress.
49
+ - **React to progress.** Use `onProgress`, for example to stop early on a condition with your own `AbortController` and `signal`.
50
+
51
+ ## Limits
52
+
53
+ - Serves **HLS over HTTPS** only, with a few seconds of delay. It reads the source over HTTPS or from disk.
54
+ - **No ingest.** Inbound is HTTPS only, so RTMP, SRT and WebRTC cannot reach the task. You cannot stream from OBS into a task.
55
+ - **One stream per task, for a small audience.** Many viewers need a CDN or a media server.
56
+ - The memory need of the `audio` profile is not measured; the minimum preset stays `std.medium`.
57
+
58
+ ## Licence of ffmpeg
59
+
60
+ FFmpeg is LGPL-2.1-or-later; builds with libx264 (as distribution builds are) are GPL. This package runs the OS package unmodified as a separate process and links none of it. hls.js (Apache-2.0) is an npm dependency, served from `node_modules`.
@@ -0,0 +1,67 @@
1
+ /** Must equal the manifest's `inbound_routes` prefix and `inbound_port`; the CLI writes these. */
2
+ export declare const DEFAULT_ROUTE = "/live/";
3
+ export declare const DEFAULT_PORT = 8080;
4
+ export declare const DEFAULT_HEIGHT = 480;
5
+ export declare const PROFILES: readonly ["video", "audio"];
6
+ export declare const AFTER_MODES: readonly ["replay", "stop"];
7
+ /** 4K. Above it a live x264 encode does not fit any sold preset. */
8
+ export declare const HEIGHT_MAX = 2160;
9
+ /**
10
+ * Same rule as the manifest schema's route prefix: starts and ends with "/", is not "/" itself.
11
+ * It also keeps the route safe to inline in the player page (no quotes or angle brackets).
12
+ */
13
+ export declare const ROUTE_PATTERN: RegExp;
14
+ export declare const HTTPS = "https:";
15
+ export declare const FFMPEG_BIN = "ffmpeg";
16
+ /** The VM has no /tmp: the only writable disk is the scratch disk, which is the task's HOME. */
17
+ export declare const SCRATCH_HOME_FALLBACK = "/mnt/scratch";
18
+ export declare const HLS_SUBDIR = "hls";
19
+ export declare const PLAYLIST_FILE = "index.m3u8";
20
+ /** hls.js is served from the installed package, so a viewer's browser needs no third-party CDN. */
21
+ export declare const PLAYER_SCRIPT_FILE = "hls.min.js";
22
+ export declare const HLS_JS_DIST = "hls.js/dist/hls.min.js";
23
+ /** ffmpeg writes MPEG-TS segments for both profiles (an audio-only HLS output is `.ts` too). */
24
+ export declare const MEDIA_TYPES: Readonly<Record<string, string>>;
25
+ export declare const HTML_TYPE = "text/html; charset=utf-8";
26
+ export declare const SCRIPT_TYPE = "text/javascript; charset=utf-8";
27
+ export declare const NO_CACHE = "no-cache";
28
+ /** ffmpeg names its files from the playlist stem: `index.m3u8`, `index0.ts`, … */
29
+ export declare const MEDIA_STEM_PATTERN: RegExp;
30
+ export declare const READ_METHODS: readonly string[];
31
+ /** One progress chunk + metric per interval; the last report is always sent. */
32
+ export declare const PROGRESS_EVERY_MS = 2000;
33
+ /** How often the player page asks whether the playlist exists yet. */
34
+ export declare const PLAYER_POLL_MS = 2000;
35
+ export declare const STDERR_TAIL_CHARS = 2000;
36
+ export declare const METRIC_STREAMED_SECONDS = "streamed_seconds";
37
+ export declare const MS_PER_SEC = 1000;
38
+ export declare const US_PER_SEC = 1000000;
39
+ /** Chunk times are rounded to tenths of a second: enough for a progress bar, short on the wire. */
40
+ export declare const TIME_DECIMALS = 1;
41
+ export declare const STATUS: {
42
+ readonly live: "live";
43
+ readonly waiting: "waiting";
44
+ readonly streaming: "streaming";
45
+ readonly ended: "ended";
46
+ };
47
+ export declare const MESSAGES: {
48
+ readonly progressHandlerFailed: (error: unknown) => string;
49
+ readonly badSource: (source: unknown) => string;
50
+ readonly badProfile: (profile: unknown) => string;
51
+ readonly badAfter: (after: unknown) => string;
52
+ readonly badPositive: (name: string, value: unknown) => string;
53
+ readonly badNonNegative: (name: string, value: unknown) => string;
54
+ readonly badHeight: (value: unknown) => string;
55
+ readonly badPort: (value: unknown) => string;
56
+ readonly badRoute: (value: unknown) => string;
57
+ readonly badFunction: (name: string) => string;
58
+ readonly lingerNeedsReplay: "lingerSec applies only with after: 'replay'";
59
+ readonly ffmpegMissing: "ffmpeg is not installed: add it to build.system_packages in task.yaml";
60
+ readonly ffmpegFailed: (code: number | null, tail: string) => string;
61
+ readonly serving: (route: string, port: number, watch: string | null) => string;
62
+ readonly waiting: (sec: number) => string;
63
+ readonly ended: (replayUntil: string) => string;
64
+ readonly replayUntilCancel: "run:cancel";
65
+ readonly replayUntilLinger: (sec: number) => string;
66
+ };
67
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,kGAAkG;AAClG,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,eAAO,MAAM,QAAQ,6BAA8B,CAAC;AACpD,eAAO,MAAM,WAAW,6BAA8B,CAAC;AAEvD,oEAAoE;AACpE,eAAO,MAAM,UAAU,OAAO,CAAC;AAE/B;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAmC,CAAC;AAE9D,eAAO,MAAM,KAAK,WAAW,CAAC;AAC9B,eAAO,MAAM,UAAU,WAAW,CAAC;AAEnC,gGAAgG;AAChG,eAAO,MAAM,qBAAqB,iBAAiB,CAAC;AACpD,eAAO,MAAM,UAAU,QAAQ,CAAC;AAChC,eAAO,MAAM,aAAa,eAAe,CAAC;AAE1C,mGAAmG;AACnG,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAC/C,eAAO,MAAM,WAAW,2BAA2B,CAAC;AAEpD,gGAAgG;AAChG,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAGxD,CAAC;AACF,eAAO,MAAM,SAAS,6BAA6B,CAAC;AACpD,eAAO,MAAM,WAAW,mCAAmC,CAAC;AAC5D,eAAO,MAAM,QAAQ,aAAa,CAAC;AACnC,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,QAAqB,CAAC;AACrD,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAAoB,CAAC;AAE/D,gFAAgF;AAChF,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,sEAAsE;AACtE,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D,eAAO,MAAM,UAAU,OAAO,CAAC;AAC/B,eAAO,MAAM,UAAU,UAAY,CAAC;AACpC,mGAAmG;AACnG,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,eAAO,MAAM,MAAM;;;;;CAKT,CAAC;AAEX,eAAO,MAAM,QAAQ;4CACY,OAAO;iCAElB,OAAO;mCAEL,OAAO;+BACX,OAAO;iCACL,MAAM,SAAS,OAAO;oCACnB,MAAM,SAAS,OAAO;gCAC1B,OAAO;8BACT,OAAO;+BAEN,OAAO;iCAEL,MAAM;;;kCAGL,MAAM,GAAG,IAAI,QAAQ,MAAM;8BAC/B,MAAM,QAAQ,MAAM,SAAS,MAAM,GAAG,IAAI;4BAE5C,MAAM;kCACA,MAAM;;sCAEF,MAAM;CACvB,CAAC"}
@@ -0,0 +1,72 @@
1
+ // Defaults, limits and messages of the stream integration. A change here is a code change, not config.
2
+ import { INBOUND_PORT_MAX, INBOUND_PORT_MIN, ROUTE_PREFIX_PATTERN } from '@ignitify-integrations/runtime';
3
+ /** Must equal the manifest's `inbound_routes` prefix and `inbound_port`; the CLI writes these. */
4
+ export const DEFAULT_ROUTE = '/live/';
5
+ export const DEFAULT_PORT = 8080;
6
+ export const DEFAULT_HEIGHT = 480;
7
+ export const PROFILES = ['video', 'audio'];
8
+ export const AFTER_MODES = ['replay', 'stop'];
9
+ /** 4K. Above it a live x264 encode does not fit any sold preset. */
10
+ export const HEIGHT_MAX = 2160;
11
+ /**
12
+ * Same rule as the manifest schema's route prefix: starts and ends with "/", is not "/" itself.
13
+ * It also keeps the route safe to inline in the player page (no quotes or angle brackets).
14
+ */
15
+ export const ROUTE_PATTERN = new RegExp(ROUTE_PREFIX_PATTERN);
16
+ export const HTTPS = 'https:';
17
+ export const FFMPEG_BIN = 'ffmpeg';
18
+ /** The VM has no /tmp: the only writable disk is the scratch disk, which is the task's HOME. */
19
+ export const SCRATCH_HOME_FALLBACK = '/mnt/scratch';
20
+ export const HLS_SUBDIR = 'hls';
21
+ export const PLAYLIST_FILE = 'index.m3u8';
22
+ /** hls.js is served from the installed package, so a viewer's browser needs no third-party CDN. */
23
+ export const PLAYER_SCRIPT_FILE = 'hls.min.js';
24
+ export const HLS_JS_DIST = 'hls.js/dist/hls.min.js';
25
+ /** ffmpeg writes MPEG-TS segments for both profiles (an audio-only HLS output is `.ts` too). */
26
+ export const MEDIA_TYPES = {
27
+ '.m3u8': 'application/vnd.apple.mpegurl',
28
+ '.ts': 'video/mp2t',
29
+ };
30
+ export const HTML_TYPE = 'text/html; charset=utf-8';
31
+ export const SCRIPT_TYPE = 'text/javascript; charset=utf-8';
32
+ export const NO_CACHE = 'no-cache';
33
+ /** ffmpeg names its files from the playlist stem: `index.m3u8`, `index0.ts`, … */
34
+ export const MEDIA_STEM_PATTERN = /^[A-Za-z0-9_-]+$/;
35
+ export const READ_METHODS = ['GET', 'HEAD'];
36
+ /** One progress chunk + metric per interval; the last report is always sent. */
37
+ export const PROGRESS_EVERY_MS = 2000;
38
+ /** How often the player page asks whether the playlist exists yet. */
39
+ export const PLAYER_POLL_MS = 2000;
40
+ export const STDERR_TAIL_CHARS = 2000;
41
+ export const METRIC_STREAMED_SECONDS = 'streamed_seconds';
42
+ export const MS_PER_SEC = 1000;
43
+ export const US_PER_SEC = 1_000_000;
44
+ /** Chunk times are rounded to tenths of a second: enough for a progress bar, short on the wire. */
45
+ export const TIME_DECIMALS = 1;
46
+ export const STATUS = {
47
+ live: 'live',
48
+ waiting: 'waiting',
49
+ streaming: 'streaming',
50
+ ended: 'ended',
51
+ };
52
+ export const MESSAGES = {
53
+ progressHandlerFailed: (error) => `onProgress threw, the stream goes on: ${error instanceof Error ? error.message : String(error)}`,
54
+ badSource: (source) => `source ${JSON.stringify(source)} must be an https:// URL or an absolute file path (use path.resolve for a relative one)`,
55
+ badProfile: (profile) => `profile ${JSON.stringify(profile)} must be one of ${PROFILES.join(', ')}`,
56
+ badAfter: (after) => `after ${JSON.stringify(after)} must be one of ${AFTER_MODES.join(', ')}`,
57
+ badPositive: (name, value) => `${name} ${JSON.stringify(value)} must be a number above 0`,
58
+ badNonNegative: (name, value) => `${name} ${JSON.stringify(value)} must be a number of 0 or more`,
59
+ badHeight: (value) => `height ${JSON.stringify(value)} must be an integer from 1 to ${HEIGHT_MAX}`,
60
+ badPort: (value) => `port ${JSON.stringify(value)} must be an integer from ${INBOUND_PORT_MIN} to ${INBOUND_PORT_MAX}`,
61
+ badRoute: (value) => `route ${JSON.stringify(value)} must start and end with "/", must not be "/", and must match ${ROUTE_PATTERN}`,
62
+ badFunction: (name) => `${name} must be a function`,
63
+ lingerNeedsReplay: `lingerSec applies only with after: 'replay'`,
64
+ ffmpegMissing: `ffmpeg is not installed: add it to build.system_packages in task.yaml`,
65
+ ffmpegFailed: (code, tail) => `ffmpeg exited with ${code ?? 'a signal'}: ${tail}`,
66
+ serving: (route, port, watch) => `serving ${route} on :${port}${watch === null ? '' : `, public at ${watch}`}`,
67
+ waiting: (sec) => `streaming starts in ${sec} s`,
68
+ ended: (replayUntil) => `stream ended; serving the replay until ${replayUntil}`,
69
+ replayUntilCancel: 'run:cancel',
70
+ replayUntilLinger: (sec) => `${sec} s`,
71
+ };
72
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,uGAAuG;AAEvG,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAE1G,kGAAkG;AAClG,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;AACtC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC;AACjC,MA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C,SAAS,CAAC,KAAK,CAAC,gCAAgC;IAClH,SAAS,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iCAAiC,UAAU,EAAE;IAC3G,OAAO,EAAE,CAAC,KAAc,EAAE,EAAE,CAC1B,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,4BAA4B,gBAAgB,OAAO,gBAAgB,EAAE;IACpG,QAAQ,EAAE,CAAC,KAAc,EAAE,EAAE,CAC3B,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iEAAiE,aAAa,EAAE;IAChH,WAAW,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,GAAG,IAAI,qBAAqB;IAC3D,iBAAiB,EAAE,6CAA6C;IAChE,aAAa,EAAE,uEAAuE;IACtF,YAAY,EAAE,CAAC,IAAmB,EAAE,IAAY,EAAE,EAAE,CAAC,sBAAsB,IAAI,IAAI,UAAU,KAAK,IAAI,EAAE;IACxG,OAAO,EAAE,CAAC,KAAa,EAAE,IAAY,EAAE,KAAoB,EAAE,EAAE,CAC7D,WAAW,KAAK,QAAQ,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,KAAK,EAAE,EAAE;IAC/E,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,uBAAuB,GAAG,IAAI;IACxD,KAAK,EAAE,CAAC,WAAmB,EAAE,EAAE,CAAC,0CAA0C,WAAW,EAAE;IACvF,iBAAiB,EAAE,YAAY;IAC/B,iBAAiB,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI;CACtC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { StreamConfig } from './options.js';
2
+ /** Where the engine writes. The HLS folder is the only folder the server reads from. */
3
+ export interface StreamPaths {
4
+ readonly hlsDir: string;
5
+ readonly playlist: string;
6
+ }
7
+ export type FfmpegArgsFn = (defaults: readonly string[], paths: StreamPaths) => readonly string[];
8
+ /** The arguments ffmpeg runs with: the profile, passed through the task's `ffmpegArgs` if it has one. */
9
+ export declare const ffmpegArgs: (config: Pick<StreamConfig, "source" | "seconds" | "height" | "profile" | "ffmpegArgs">, paths: StreamPaths) => readonly string[];
10
+ //# sourceMappingURL=ffmpeg-args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffmpeg-args.d.ts","sourceRoot":"","sources":["../src/ffmpeg-args.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAW,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,KAAK,SAAS,MAAM,EAAE,CAAC;AA2DlG,yGAAyG;AACzG,eAAO,MAAM,UAAU,GACrB,QAAQ,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC,EACtF,OAAO,WAAW,KACjB,SAAS,MAAM,EAGjB,CAAC"}
@@ -0,0 +1,56 @@
1
+ // The engine arguments: one pure profile per output kind. This is the only media logic of this integration,
2
+ // and a task can change or replace it with the `ffmpegArgs` option.
3
+ const AUDIO_CODEC = ['-c:a', 'aac', '-b:a', '128k'];
4
+ // `-progress pipe:1` feeds the progress reports; a replacement must keep it to keep them.
5
+ // `-re` reads at playback speed, so the stream is live, not a fast transcode.
6
+ const input = (p) => [
7
+ '-hide_banner',
8
+ '-nostats',
9
+ '-loglevel',
10
+ 'error',
11
+ '-progress',
12
+ 'pipe:1',
13
+ '-re',
14
+ '-i',
15
+ p.source,
16
+ ...(p.seconds === null ? [] : ['-t', String(p.seconds)]),
17
+ ];
18
+ // A keyframe every 48 frames with no scene-cut keyframes gives segments of an even length.
19
+ const video = (p) => [
20
+ '-vf',
21
+ `scale=-2:${p.height}`,
22
+ '-c:v',
23
+ 'libx264',
24
+ '-preset',
25
+ 'veryfast',
26
+ '-g',
27
+ '48',
28
+ '-sc_threshold',
29
+ '0',
30
+ ...AUDIO_CODEC,
31
+ ];
32
+ const audio = () => ['-vn', ...AUDIO_CODEC];
33
+ // An "event" playlist keeps every segment, so a late viewer can seek to the start and replay it.
34
+ const hls = (paths) => [
35
+ '-f',
36
+ 'hls',
37
+ '-hls_time',
38
+ '4',
39
+ '-hls_list_size',
40
+ '0',
41
+ '-hls_playlist_type',
42
+ 'event',
43
+ paths.playlist,
44
+ ];
45
+ const PROFILE_ARGS = { video, audio };
46
+ const defaultArgs = (config, paths) => [
47
+ ...input(config),
48
+ ...PROFILE_ARGS[config.profile](config),
49
+ ...hls(paths),
50
+ ];
51
+ /** The arguments ffmpeg runs with: the profile, passed through the task's `ffmpegArgs` if it has one. */
52
+ export const ffmpegArgs = (config, paths) => {
53
+ const defaults = defaultArgs(config, paths);
54
+ return config.ffmpegArgs === null ? defaults : config.ffmpegArgs(defaults, paths);
55
+ };
56
+ //# sourceMappingURL=ffmpeg-args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffmpeg-args.js","sourceRoot":"","sources":["../src/ffmpeg-args.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,oEAAoE;AAcpE,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAE7D,0FAA0F;AAC1F,8EAA8E;AAC9E,MAAM,KAAK,GAAG,CAAC,CAAe,EAAqB,EAAE,CAAC;IACpD,cAAc;IACd,UAAU;IACV,WAAW;IACX,OAAO;IACP,WAAW;IACX,QAAQ;IACR,KAAK;IACL,IAAI;IACJ,CAAC,CAAC,MAAM;IACR,GAAG,CAAC,CAAC,CAAC,OAAO,KAAK,IAAI,C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C,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { stream, type StreamResult } from './stream.js';
2
+ export { watchUrl } from './routes.js';
3
+ export type { StreamOptions, Profile, AfterMode, ProgressHandler } from './options.js';
4
+ export type { FfmpegArgsFn, StreamPaths } from './ffmpeg-args.js';
5
+ export type { ProgressReport } from './progress.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACvF,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { stream } from './stream.js';
2
+ export { watchUrl } from './routes.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { type Result } from '@ignitify-integrations/runtime';
2
+ import { AFTER_MODES, PROFILES } from './constants.js';
3
+ import type { FfmpegArgsFn } from './ffmpeg-args.js';
4
+ import type { ProgressReport } from './progress.js';
5
+ export type Profile = (typeof PROFILES)[number];
6
+ export type AfterMode = (typeof AFTER_MODES)[number];
7
+ export type ProgressHandler = (report: ProgressReport) => void;
8
+ export interface StreamOptions {
9
+ /** An https:// URL, or an absolute path of a file on the VM (for example on the scratch disk). */
10
+ readonly source: string;
11
+ readonly profile?: Profile;
12
+ /** Stop after this many seconds. Default: the whole source. */
13
+ readonly seconds?: number;
14
+ /** Output height in pixels (video profile only). */
15
+ readonly height?: number;
16
+ readonly startDelaySec?: number;
17
+ readonly after?: AfterMode;
18
+ /** With `after: 'replay'`: stop on its own this long after the stream ends. */
19
+ readonly lingerSec?: number;
20
+ readonly route?: string;
21
+ readonly port?: number;
22
+ readonly ffmpegArgs?: FfmpegArgsFn;
23
+ /** Called for every ffmpeg progress report, next to the built-in chunk and metric. */
24
+ readonly onProgress?: ProgressHandler;
25
+ /** Stop source. Default: the first SIGTERM (run:cancel) or SIGINT. */
26
+ readonly signal?: AbortSignal;
27
+ }
28
+ export interface StreamConfig {
29
+ readonly source: string;
30
+ readonly profile: Profile;
31
+ readonly seconds: number | null;
32
+ readonly height: number;
33
+ readonly startDelaySec: number;
34
+ readonly after: AfterMode;
35
+ readonly lingerSec: number | null;
36
+ readonly route: string;
37
+ readonly port: number;
38
+ readonly ffmpegArgs: FfmpegArgsFn | null;
39
+ readonly onProgress: ProgressHandler | null;
40
+ }
41
+ export declare const parseOptions: (options: StreamOptions) => Result<StreamConfig, readonly string[]>;
42
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAIA,OAAO,EAA+C,KAAK,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC1G,OAAO,EACL,WAAW,EAOX,QAAQ,EAET,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAChD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACr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AQ,CAAC,UAAU,EAAE,YAAY,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,UAAU,EAAE,eAAe,GAAG,IAAI,CAAC;CAC7C;AAoED,eAAO,MAAM,YAAY,GAAI,SAAS,aAAa,KAAG,MAAM,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAkB3F,CAAC"}
@@ -0,0 +1,80 @@
1
+ // Options in, a checked config out. Pure. Every refusal is collected, so one run shows them all.
2
+ // Values are checked at run time too: they usually come straight from a JSON payload.
3
+ import { isAbsolute } from 'node:path';
4
+ import { err, INBOUND_PORT_MAX, INBOUND_PORT_MIN, ok } from '@ignitify-integrations/runtime';
5
+ import { AFTER_MODES, DEFAULT_HEIGHT, DEFAULT_PORT, DEFAULT_ROUTE, HEIGHT_MAX, HTTPS, MESSAGES, PROFILES, ROUTE_PATTERN, } from './constants.js';
6
+ /** JSON payloads carry `null` for "not set" as often as they leave the key out. */
7
+ const absent = (value) => value === undefined || value === null;
8
+ const isFiniteNumber = (value) => typeof value === 'number' && Number.isFinite(value);
9
+ const isIntIn = (value, min, max) => Number.isInteger(value) && value >= min && value <= max;
10
+ const parseSource = (value) => {
11
+ if (typeof value !== 'string' || value === '')
12
+ return err(MESSAGES.badSource(value));
13
+ // An absolute path cannot be read by ffmpeg as a protocol ("concat:", "pipe:", …).
14
+ if (isAbsolute(value))
15
+ return ok(value);
16
+ if (!URL.canParse(value))
17
+ return err(MESSAGES.badSource(value));
18
+ const url = new URL(value);
19
+ return url.protocol === HTTPS ? ok(url.toString()) : err(MESSAGES.badSource(value));
20
+ };
21
+ const oneOf = (all, value, fallback, message) => {
22
+ if (absent(value))
23
+ return ok(fallback);
24
+ return all.includes(value) ? ok(value) : err(message(value));
25
+ };
26
+ const positiveOrNull = (name, value) => {
27
+ if (absent(value))
28
+ return ok(null);
29
+ return isFiniteNumber(value) && value > 0 ? ok(value) : err(MESSAGES.badPositive(name, value));
30
+ };
31
+ const nonNegative = (name, value) => {
32
+ if (absent(value))
33
+ return ok(0);
34
+ return isFiniteNumber(value) && value >= 0 ? ok(value) : err(MESSAGES.badNonNegative(name, value));
35
+ };
36
+ const intIn = (value, fallback, min, max, message) => {
37
+ if (absent(value))
38
+ return ok(fallback);
39
+ return isIntIn(value, min, max) ? ok(value) : err(message(value));
40
+ };
41
+ const route = (value) => {
42
+ if (absent(value))
43
+ return ok(DEFAULT_ROUTE);
44
+ return typeof value === 'string' && ROUTE_PATTERN.test(value) ? ok(value) : err(MESSAGES.badRoute(value));
45
+ };
46
+ const fnOrNull = (name, value) => {
47
+ if (absent(value))
48
+ return ok(null);
49
+ return typeof value === 'function' ? ok(value) : err(MESSAGES.badFunction(name));
50
+ };
51
+ /** All fields ok → their values; else every error, in field order. */
52
+ const collect = (fields) => {
53
+ const entries = Object.entries(fields);
54
+ const errors = entries.flatMap(([, r]) => (r.ok ? [] : [r.error]));
55
+ if (errors.length > 0)
56
+ return err(errors);
57
+ return ok(Object.fromEntries(entries.map(([key, r]) => [key, r.ok ? r.value : undefined])));
58
+ };
59
+ export const parseOptions = (options) => {
60
+ const fields = collect({
61
+ source: parseSource(options.source),
62
+ profile: oneOf(PROFILES, options.profile, 'video', MESSAGES.badProfile),
63
+ seconds: positiveOrNull('seconds', options.seconds),
64
+ height: intIn(options.height, DEFAULT_HEIGHT, 1, HEIGHT_MAX, MESSAGES.badHeight),
65
+ startDelaySec: nonNegative('startDelaySec', options.startDelaySec),
66
+ after: oneOf(AFTER_MODES, options.after, 'replay', MESSAGES.badAfter),
67
+ lingerSec: positiveOrNull('lingerSec', options.lingerSec),
68
+ route: route(options.route),
69
+ port: intIn(options.port, DEFAULT_PORT, INBOUND_PORT_MIN, INBOUND_PORT_MAX, MESSAGES.badPort),
70
+ ffmpegArgs: fnOrNull('ffmpegArgs', options.ffmpegArgs),
71
+ onProgress: fnOrNull('onProgress', options.onProgress),
72
+ });
73
+ if (!fields.ok)
74
+ return fields;
75
+ // A linger with `stop` would be silently ignored; refuse it so the intent is visible.
76
+ if (fields.value.after === 'stop' && fields.value.lingerSec !== null)
77
+ return err([MESSAGES.lingerNeedsReplay]);
78
+ return fields;
79
+ };
80
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,sFAAsF;AAEtF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,EAAE,EAAe,MAAM,gCAAgC,CAAC;AAC1G,OAAO,EACL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,aAAa,EACb,UAAU,EACV,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,aAAa,GACd,MAAM,gBAAgB,CAAC;AA2CxB,mFAAmF;AACnF,MAAM,MAAM,GAAG,CAAC,KAAc,EAA6B,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACpG,MAAM,cAAc,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChH,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,GAAW,EAAE,GAAW,EAAmB,EAAE,CAC5E,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAK,KAAgB,IAAI,GAAG,IAAK,KAAgB,IAAI,GAAG,CAAC;AAElF,MAAM,WAAW,GAAG,CAAC,KAAc,EAAkB,EAAE;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACrF,mFAAmF;IACnF,IAAI,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,CAAC,GAAG,CAAC,QAAQ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AE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;QACrE,SAAS,EAAE,cAAc,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC;QACzD,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,QAAQ,CAAC,OAAO,CAAC;QAC7F,UAAU,EAAE,QAAQ,CAAe,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC;QACpE,UAAU,EAAE,QAAQ,CAAkB,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC;KACxE,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAC;IAC9B,sFAAsF;IACtF,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC/G,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ export interface ProgressReport {
2
+ /** Seconds of output written so far. */
3
+ readonly doneSec: number;
4
+ /** ffmpeg's speed, as it prints it ("1.01x", or "N/A" at the start). */
5
+ readonly speed: string;
6
+ /** True on the last report of the run. */
7
+ readonly end: boolean;
8
+ }
9
+ /** Carry-over between stdout reads: a partial line, and the fields of the open report. */
10
+ export interface ProgressState {
11
+ readonly partial: string;
12
+ readonly fields: Readonly<Record<string, string>>;
13
+ }
14
+ export declare const PROGRESS_START: ProgressState;
15
+ /** Text in, finished reports out. A read may end mid-line; that line waits in `partial`. */
16
+ export declare const parseProgress: (state: ProgressState, text: string) => {
17
+ readonly state: ProgressState;
18
+ readonly reports: readonly ProgressReport[];
19
+ };
20
+ /** At most one emit per interval, and always the last report. */
21
+ export declare const shouldEmit: (report: ProgressReport, lastEmitMs: number | null, nowMs: number) => boolean;
22
+ export declare const roundTime: (sec: number) => number;
23
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB;AAED,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD;AAED,eAAO,MAAM,cAAc,EAAE,aAA2C,CAAC;AAWzE,4FAA4F;AAC5F,eAAO,MAAM,aAAa,GACxB,OAAO,aAAa,EACpB,MAAM,MAAM,KACX;IAAE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAkB9E,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,UAAU,GAAI,QAAQ,cAAc,EAAE,YAAY,MAAM,GAAG,IAAI,EAAE,OAAO,MAAM,KAAG,OAChB,CAAC;AAE/E,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,MAA4C,CAAC"}
@@ -0,0 +1,36 @@
1
+ // The ffmpeg `-progress` parser and the report throttle. Pure: text and times in, decisions out.
2
+ // `-progress` prints `key=value` lines; a `progress=continue|end` line closes one report.
3
+ import { PROGRESS_EVERY_MS, TIME_DECIMALS, US_PER_SEC } from './constants.js';
4
+ export const PROGRESS_START = { partial: '', fields: {} };
5
+ const END_VALUE = 'end';
6
+ const CLOSING_KEY = 'progress';
7
+ // ffmpeg prints "N/A" for out_time_us before the first frame is out.
8
+ const toSeconds = (us) => {
9
+ const value = Number(us);
10
+ return Number.isFinite(value) && value > 0 ? value / US_PER_SEC : 0;
11
+ };
12
+ /** Text in, finished reports out. A read may end mid-line; that line waits in `partial`. */
13
+ export const parseProgress = (state, text) => {
14
+ const lines = (state.partial + text).split('\n');
15
+ const partial = lines.pop() ?? '';
16
+ let fields = state.fields;
17
+ const reports = [];
18
+ for (const line of lines) {
19
+ const at = line.indexOf('=');
20
+ if (at <= 0)
21
+ continue;
22
+ const key = line.slice(0, at).trim();
23
+ const value = line.slice(at + 1).trim();
24
+ if (key !== CLOSING_KEY) {
25
+ fields = { ...fields, [key]: value };
26
+ continue;
27
+ }
28
+ reports.push({ doneSec: toSeconds(fields.out_time_us), speed: fields.speed ?? '', end: value === END_VALUE });
29
+ fields = {};
30
+ }
31
+ return { state: { partial, fields }, reports };
32
+ };
33
+ /** At most one emit per interval, and always the last report. */
34
+ export const shouldEmit = (report, lastEmitMs, nowMs) => report.end || lastEmitMs === null || nowMs - lastEmitMs >= PROGRESS_EVERY_MS;
35
+ export const roundTime = (sec) => Number(sec.toFixed(TIME_DECIMALS));
36
+ //# sourceMappingURL=progress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.js","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,0FAA0F;AAE1F,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAiB9E,MAAM,CAAC,MAAM,cAAc,GAAkB,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAEzE,MAAM,SAAS,GAAG,KAAK,CAAC;AACxB,MAAM,WAAW,GAAG,UAAU,CAAC;AAE/B,qEAAqE;AACrE,MAAM,SAAS,GAAG,CAAC,EAAsB,EAAU,EAAE;IACnD,MAAM,KAAK,GAA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,GAAG,EAAE,CAAC;IACd,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC;AACjD,CAAC,CAAC;AAEF,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAsB,EAAE,UAAyB,EAAE,KAAa,EAAW,EAAE,CACtG,MAAM,CAAC,GAAG,IAAI,UAAU,KAAK,IAAI,IAAI,KAAK,GAAG,UAAU,IAAI,iBAAiB,CAAC;AAE/E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { TaskCtx } from '@ignitify-integrations/runtime';
2
+ export type Route = {
3
+ readonly kind: 'player';
4
+ } | {
5
+ readonly kind: 'script';
6
+ } | {
7
+ readonly kind: 'media';
8
+ readonly name: string;
9
+ readonly type: string;
10
+ } | {
11
+ readonly kind: 'none';
12
+ };
13
+ /** `route` is a checked prefix such as `/live/`; `urlPath` is the request's decoded-or-not pathname. */
14
+ export declare const resolveRoute: (urlPath: string, route: string) => Route;
15
+ /** The public viewer address: this deployment's host (from the callback URL) + the route. */
16
+ export declare const viewerUrl: (callbackUrl: string | null, route: string) => string | null;
17
+ /**
18
+ * The viewer link, for task code that tells people about the stream before or while it runs
19
+ * (stream() sends the same link to the caller as its first chunk). Null when the run has no callback.
20
+ */
21
+ export declare const watchUrl: (ctx: Pick<TaskCtx, "callback">, route?: string) => string | null;
22
+ export declare const playerPage: (route: string) => string;
23
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAU9D,MAAM,MAAM,KAAK,GACb;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI9B,wGAAwG;AACxG,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,EAAE,OAAO,MAAM,KAAG,KAS7D,CAAC;AAEF,6FAA6F;AAC7F,eAAO,MAAM,SAAS,GAAI,aAAa,MAAM,GAAG,IAAI,EAAE,OAAO,MAAM,KAAG,MAAM,GAAG,IACP,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,QAAO,MAAsB,KAAG,MAAM,GAAG,IACrD,CAAC;AAK9C,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,MAc1B,CAAC"}
package/dist/routes.js ADDED
@@ -0,0 +1,47 @@
1
+ // What the inbound server answers, decided from the URL path alone. Pure.
2
+ // Under the route: the player page, hls.js, and the `.m3u8` / `.ts` files of ONE folder.
3
+ // Everything else is 404: no sub-folders, no dot names, no other extensions.
4
+ import { extname } from 'node:path';
5
+ import { DEFAULT_ROUTE, MEDIA_STEM_PATTERN, MEDIA_TYPES, PLAYER_POLL_MS, PLAYER_SCRIPT_FILE, PLAYLIST_FILE, } from './constants.js';
6
+ const NONE = { kind: 'none' };
7
+ /** `route` is a checked prefix such as `/live/`; `urlPath` is the request's decoded-or-not pathname. */
8
+ export const resolveRoute = (urlPath, route) => {
9
+ if (urlPath === route || urlPath === route.slice(0, -1))
10
+ return { kind: 'player' };
11
+ if (!urlPath.startsWith(route))
12
+ return NONE;
13
+ const name = urlPath.slice(route.length);
14
+ if (name === PLAYER_SCRIPT_FILE)
15
+ return { kind: 'script' };
16
+ const ext = extname(name);
17
+ const type = MEDIA_TYPES[ext];
18
+ if (type === undefined || !MEDIA_STEM_PATTERN.test(name.slice(0, -ext.length)))
19
+ return NONE;
20
+ return { kind: 'media', name, type };
21
+ };
22
+ /** The public viewer address: this deployment's host (from the callback URL) + the route. */
23
+ export const viewerUrl = (callbackUrl, route) => callbackUrl === null ? null : `${new URL(callbackUrl).origin}${route}`;
24
+ /**
25
+ * The viewer link, for task code that tells people about the stream before or while it runs
26
+ * (stream() sends the same link to the caller as its first chunk). Null when the run has no callback.
27
+ */
28
+ export const watchUrl = (ctx, route = DEFAULT_ROUTE) => viewerUrl(ctx.callback?.url ?? null, route);
29
+ // Paths are absolute so the page works at both `/live/` and `/live`. The playlist does not exist
30
+ // until the first segment is written, so the page polls until it does, then plays. Safari plays
31
+ // HLS natively; every other browser uses hls.js.
32
+ export const playerPage = (route) => `<!doctype html><meta charset="utf-8"><title>Live</title>
33
+ <meta name="viewport" content="width=device-width, initial-scale=1">
34
+ <body style="margin:0;background:#000">
35
+ <video id="v" controls autoplay muted playsinline style="width:100%;height:100vh"></video>
36
+ <script src="${route}${PLAYER_SCRIPT_FILE}"></script>
37
+ <script>
38
+ const v = document.getElementById("v"), src = "${route}${PLAYLIST_FILE}";
39
+ const play = () => {
40
+ if (v.canPlayType("application/vnd.apple.mpegurl")) v.src = src;
41
+ else { const h = new Hls(); h.loadSource(src); h.attachMedia(v); }
42
+ };
43
+ const retry = () => setTimeout(wait, ${PLAYER_POLL_MS});
44
+ const wait = () => fetch(src, { cache: "no-store" }).then((r) => (r.ok ? play() : retry()), retry);
45
+ wait();
46
+ </script></body>`;
47
+ //# sourceMappingURL=routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yFAAyF;AACzF,6EAA6E;AAE7E,OAAO,EAAE,O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,CAAC,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAA8B,EAAE,QAAgB,aAAa,EAAiB,EAAE,CACvG,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC;AAE9C,iGAAiG;AACjG,gGAAgG;AAChG,iDAAiD;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC;;;;eAItC,KAAK,GAAG,kBAAkB;;mDAEU,KAAK,GAAG,aAAa;;;;;yCAK/B,cAAc;;;iBAGtC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { type TaskCtx } from '@ignitify-integrations/runtime';
2
+ import { type StreamOptions } from './options.js';
3
+ export type StreamResult = {
4
+ readonly success: true;
5
+ readonly cancelled: true;
6
+ readonly stage: 'before-stream';
7
+ } | {
8
+ readonly success: true;
9
+ readonly cancelled: boolean;
10
+ readonly stage: 'streamed';
11
+ readonly watch: string | null;
12
+ /** Seconds of output ffmpeg wrote (its last progress report). */
13
+ readonly streamed_s: number;
14
+ /** `null` for the audio profile. */
15
+ readonly height: number | null;
16
+ /** From the start of ffmpeg to the end of the run, replay included. */
17
+ readonly wall_ms: number;
18
+ };
19
+ /**
20
+ * Serve a live HLS stream of `options.source` from this task: player page, playlist, viewer URL,
21
+ * progress, stop on cancel. Throws on bad options and when ffmpeg fails.
22
+ */
23
+ export declare function stream(ctx: TaskCtx, options: StreamOptions): Promise<StreamResult>;
24
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AASA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAkBtE,OAAO,EAAmC,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAInF,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;CAAE,GACrF;IACE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AA4HN;;;GAGG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAoDxF"}
package/dist/stream.js ADDED
@@ -0,0 +1,165 @@
1
+ // The shell: HTTP server, ffmpeg child process, stop signal. Every decision it acts on comes from
2
+ // the pure modules (options, ffmpeg-args, progress, routes).
3
+ import { spawn } from 'node:child_process';
4
+ import { mkdir, readFile, rm } from 'node:fs/promises';
5
+ import { createServer } from 'node:http';
6
+ import { createRequire } from 'node:module';
7
+ import { join } from 'node:path';
8
+ import { setTimeout as sleep } from 'node:timers/promises';
9
+ import { unwrap } from '@ignitify-integrations/runtime';
10
+ import { FFMPEG_BIN, HLS_JS_DIST, HLS_SUBDIR, HTML_TYPE, MESSAGES, METRIC_STREAMED_SECONDS, MS_PER_SEC, NO_CACHE, PLAYLIST_FILE, READ_METHODS, SCRATCH_HOME_FALLBACK, SCRIPT_TYPE, STATUS, STDERR_TAIL_CHARS, } from './constants.js';
11
+ import { ffmpegArgs } from './ffmpeg-args.js';
12
+ import { parseOptions } from './options.js';
13
+ import { PROGRESS_START, parseProgress, roundTime, shouldEmit } from './progress.js';
14
+ import { playerPage, resolveRoute, viewerUrl } from './routes.js';
15
+ const STOP_SIGNALS = ['SIGTERM', 'SIGINT'];
16
+ const NOT_FOUND = 404;
17
+ const NOT_ALLOWED = 405;
18
+ const OK = 200;
19
+ // A run:cancel arrives as SIGTERM. Node's default would exit at once and leave ffmpeg running,
20
+ // so stream() takes the signal over for the length of the stream, then gives it back.
21
+ const processStop = () => {
22
+ const controller = new AbortController();
23
+ const abort = () => controller.abort();
24
+ STOP_SIGNALS.forEach((s) => process.once(s, abort));
25
+ return { signal: controller.signal, release: () => STOP_SIGNALS.forEach((s) => process.off(s, abort)) };
26
+ };
27
+ const whenAborted = (signal) => new Promise((resolve) => {
28
+ if (signal.aborted)
29
+ resolve();
30
+ else
31
+ signal.addEventListener('abort', () => resolve(), { once: true });
32
+ });
33
+ /** Wait `sec`, or less if the stop comes first. The only rejection of an aborted sleep is the abort. */
34
+ const sleepUnlessStopped = (sec, signal) => sleep(sec * MS_PER_SEC, undefined, { signal }).catch(() => undefined);
35
+ const hlsPaths = () => {
36
+ const hlsDir = join(process.env.HOME || SCRATCH_HOME_FALLBACK, HLS_SUBDIR);
37
+ return { hlsDir, playlist: join(hlsDir, PLAYLIST_FILE) };
38
+ };
39
+ // Resolved at run time from the installed package: never a CDN, never a copy in this repo.
40
+ const loadPlayerScript = () => readFile(createRequire(import.meta.url).resolve(HLS_JS_DIST));
41
+ const handler = (route, player, script, hlsDir) => (req, res) => {
42
+ if (!READ_METHODS.includes(req.method ?? '')) {
43
+ res.writeHead(NOT_ALLOWED, { allow: READ_METHODS.join(', ') }).end();
44
+ return;
45
+ }
46
+ // Split, not `new URL`: a malformed request line must not throw inside the server.
47
+ const path = (req.url ?? '').split(/[?#]/, 1)[0] ?? '';
48
+ const r = resolveRoute(path, route);
49
+ if (r.kind === 'player')
50
+ res.writeHead(OK, { 'content-type': HTML_TYPE }).end(player);
51
+ else if (r.kind === 'script')
52
+ res.writeHead(OK, { 'content-type': SCRIPT_TYPE }).end(script);
53
+ else if (r.kind === 'none')
54
+ res.writeHead(NOT_FOUND).end();
55
+ else
56
+ readFile(join(hlsDir, r.name)).then((body) => res.writeHead(OK, { 'content-type': r.type, 'cache-control': NO_CACHE }).end(body), () => res.writeHead(NOT_FOUND).end());
57
+ };
58
+ const listen = (server, port) => new Promise((resolve, reject) => {
59
+ server.once('error', reject);
60
+ server.listen(port, () => {
61
+ server.off('error', reject);
62
+ resolve();
63
+ });
64
+ });
65
+ const close = (server) => new Promise((resolve) => {
66
+ server.close(() => resolve());
67
+ server.closeAllConnections();
68
+ });
69
+ // Runs ffmpeg to its end. Progress → onProgress (every report) and chunk + metric (throttled).
70
+ const runEngine = (ctx, config, args, signal) => new Promise((resolve, reject) => {
71
+ const ff = spawn(FFMPEG_BIN, args, { stdio: ['ignore', 'pipe', 'pipe'] });
72
+ const kill = () => void ff.kill('SIGTERM');
73
+ signal.addEventListener('abort', kill, { once: true });
74
+ let progress = PROGRESS_START;
75
+ let lastEmitMs = null;
76
+ let streamedSec = 0;
77
+ let tail = '';
78
+ const report = (r) => {
79
+ streamedSec = r.doneSec;
80
+ // Best-effort: the tenant's progress handler is observability and must never stop the stream.
81
+ try {
82
+ config.onProgress?.(r);
83
+ }
84
+ catch (error) {
85
+ console.error(MESSAGES.progressHandlerFailed(error));
86
+ }
87
+ const now = Date.now();
88
+ if (!shouldEmit(r, lastEmitMs, now))
89
+ return;
90
+ lastEmitMs = now;
91
+ ctx.chunk({ status: STATUS.streaming, time_s: roundTime(r.doneSec), of_s: config.seconds, speed: r.speed });
92
+ ctx.metric(METRIC_STREAMED_SECONDS, r.doneSec, 'gauge');
93
+ };
94
+ ff.stdout.setEncoding('utf8').on('data', (text) => {
95
+ const parsed = parseProgress(progress, text);
96
+ progress = parsed.state;
97
+ parsed.reports.forEach(report);
98
+ });
99
+ ff.stderr.setEncoding('utf8').on('data', (text) => {
100
+ console.error(text.trimEnd());
101
+ tail = (tail + text).slice(-STDERR_TAIL_CHARS);
102
+ });
103
+ ff.once('error', (e) => {
104
+ signal.removeEventListener('abort', kill);
105
+ reject(e.code === 'ENOENT' ? new Error(MESSAGES.ffmpegMissing) : e);
106
+ });
107
+ ff.once('close', (code) => {
108
+ signal.removeEventListener('abort', kill);
109
+ resolve({ code, stderrTail: tail.trim(), streamedSec });
110
+ });
111
+ });
112
+ /**
113
+ * Serve a live HLS stream of `options.source` from this task: player page, playlist, viewer URL,
114
+ * progress, stop on cancel. Throws on bad options and when ffmpeg fails.
115
+ */
116
+ export async function stream(ctx, options) {
117
+ const config = unwrap(parseOptions(options));
118
+ const stop = options.signal === undefined ? processStop() : { signal: options.signal, release: () => undefined };
119
+ const { signal } = stop;
120
+ const paths = hlsPaths();
121
+ const script = await loadPlayerScript();
122
+ await rm(paths.hlsDir, { recursive: true, force: true });
123
+ await mkdir(paths.hlsDir, { recursive: true });
124
+ const server = createServer(handler(config.route, playerPage(config.route), script, paths.hlsDir));
125
+ try {
126
+ await listen(server, config.port);
127
+ ctx.ready();
128
+ const watch = viewerUrl(ctx.callback?.url ?? null, config.route);
129
+ ctx.chunk({ status: STATUS.live, watch, playlist: watch === null ? null : `${watch}${PLAYLIST_FILE}` });
130
+ console.log(MESSAGES.serving(config.route, config.port, watch));
131
+ // Serve the player first, so a viewer can open the link before the stream starts.
132
+ if (config.startDelaySec > 0) {
133
+ ctx.chunk({ status: STATUS.waiting, start_in_s: config.startDelaySec, watch });
134
+ console.log(MESSAGES.waiting(config.startDelaySec));
135
+ await sleepUnlessStopped(config.startDelaySec, signal);
136
+ }
137
+ if (signal.aborted)
138
+ return { success: true, cancelled: true, stage: 'before-stream' };
139
+ const started = Date.now();
140
+ const exit = await runEngine(ctx, config, ffmpegArgs(config, paths), signal);
141
+ // ffmpeg exits non-zero when it is stopped; that is a cancel, not a failure.
142
+ if (exit.code !== 0 && !signal.aborted)
143
+ throw new Error(MESSAGES.ffmpegFailed(exit.code, exit.stderrTail));
144
+ if (!signal.aborted && config.after === 'replay') {
145
+ const until = config.lingerSec === null ? MESSAGES.replayUntilCancel : MESSAGES.replayUntilLinger(config.lingerSec);
146
+ ctx.chunk({ status: STATUS.ended, replay_until: until, watch });
147
+ console.log(MESSAGES.ended(until));
148
+ await (config.lingerSec === null ? whenAborted(signal) : sleepUnlessStopped(config.lingerSec, signal));
149
+ }
150
+ return {
151
+ success: true,
152
+ cancelled: signal.aborted,
153
+ stage: 'streamed',
154
+ watch,
155
+ streamed_s: roundTime(exit.streamedSec),
156
+ height: config.profile === 'video' ? config.height : null,
157
+ wall_ms: Date.now() - started,
158
+ };
159
+ }
160
+ finally {
161
+ await close(server);
162
+ stop.release();
163
+ }
164
+ }
165
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,6DAA6D;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAgB,MAAM,gCAAgC,CAAC;AACtE,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,EACR,uBAAuB,EACvB,UAAU,EACV,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,WAAW,EACX,MAAM,EACN,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAChE,OA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AC"}
@@ -0,0 +1,16 @@
1
+ schema_version: 1
2
+ name: stream
3
+ runtimes: [node]
4
+ network:
5
+ type: bidirectional
6
+ # Only an https source needs egress; its host varies, so the plan prints this hint.
7
+ egress_hint: 'the host of an https source (for example raw.githubusercontent.com); none for a local file'
8
+ inbound_port: 8080 # must equal the `port` option (default 8080)
9
+ inbound_routes:
10
+ - prefix: /live/ # must equal the `route` option (default /live/)
11
+ inbound_max_concurrent: 16 # in-flight requests; an HLS player fetches one segment every 4 s
12
+ execution:
13
+ duration: long
14
+ interaction: continuous # ctx.chunk is dropped under boundary-only
15
+ system_packages: [ffmpeg]
16
+ min_preset: std.medium # live x264 runs out of memory on std.micro; the audio profile is not measured
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@ignitify-integrations/stream",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Live audio and video streaming (HLS over HTTPS) from an ignitify task, as glue over ffmpeg",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/ignitify-dev/ignitify-integrations.git",
9
+ "directory": "integrations/stream"
10
+ },
11
+ "type": "module",
12
+ "engines": {
13
+ "node": ">=22"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "integration.yaml",
24
+ "LICENSE",
25
+ "NOTICE",
26
+ "README.md"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc -b"
30
+ },
31
+ "dependencies": {
32
+ "@ignitify-integrations/runtime": "^0.1.0",
33
+ "hls.js": "^1.7.4"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "provenance": true
38
+ }
39
+ }