nixamp 0.24.2 → 0.25.0
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/README.md +38 -0
- package/dist/captions.d.ts +12 -0
- package/dist/captions.js +29 -2
- package/dist/hash.d.ts +12 -0
- package/dist/hash.js +139 -0
- package/dist/main.js +27 -3
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +49 -1
- package/dist/media-index.d.ts +67 -0
- package/dist/media-index.js +114 -0
- package/dist/media-local.d.ts +43 -0
- package/dist/media-local.js +88 -0
- package/dist/media-page.d.ts +18 -0
- package/dist/media-page.js +146 -0
- package/dist/media.d.ts +145 -0
- package/dist/media.js +364 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +186 -1
- package/dist/transcribe.js +20 -0
- package/dist/transcript-client.d.ts +19 -0
- package/dist/transcript-client.js +24 -0
- package/package.json +1 -1
- package/src/captions.ts +32 -2
- package/src/hash.ts +139 -0
- package/src/main.ts +27 -3
- package/src/mcp.ts +49 -1
- package/src/media-index.ts +145 -0
- package/src/media-local.ts +117 -0
- package/src/media-page.ts +159 -0
- package/src/media.ts +433 -0
- package/src/server.ts +178 -1
- package/src/transcribe.ts +17 -0
- package/src/transcript-client.ts +34 -0
- package/web/dist/assets/{hls-3VKVEQE3-B3PGV4wK.js → hls-3VKVEQE3-B4ltbKDh.js} +1 -1
- package/web/dist/assets/{index-DOOjAq1w.js → index-d7TvpeFZ.js} +1 -1
- package/web/dist/assets/{mpegts-CtxeYR5-.js → mpegts-Byy3EkfT.js} +1 -1
- package/web/dist/assets/{mpegts-LO6RVLD6-CBHUeoME.js → mpegts-LO6RVLD6-C9qqolrW.js} +1 -1
- package/web/dist/index.html +1 -1
- package/web/dist/sw.js +5 -5
package/src/server.ts
CHANGED
|
@@ -94,6 +94,10 @@ import {
|
|
|
94
94
|
Transcripts, fileFingerprint, formatOf, idFrom, languageCode, linesFrom, mediaOfLive, mediaOfUrl, toSrt, toText, toVtt, transcriptIdOf, wire,
|
|
95
95
|
} from "./transcripts.ts";
|
|
96
96
|
import { handleMessage as mcpMessage } from "./mcp.ts";
|
|
97
|
+
import { Media, factsFromRequest, holderFrom, mediaId, openFileListing, openFileOf, type MediaRecord } from "./media.ts";
|
|
98
|
+
import { mediaPage, type PageTranscript } from "./media-page.ts";
|
|
99
|
+
import { describeFile, refreshChanged } from "./media-local.ts";
|
|
100
|
+
import { WATCH_EVERY_MS, remember, watchOnce } from "./media-index.ts";
|
|
97
101
|
import { Outro } from "./outro.ts";
|
|
98
102
|
import { Profiles, Voices, spokenLine, spokenVoiceFor } from "./voices.ts";
|
|
99
103
|
import { confirm, DEFAULT_DIRECTORY, Publisher } from "./publish.ts";
|
|
@@ -1747,6 +1751,8 @@ export interface HandlerOptions {
|
|
|
1747
1751
|
transcripts?: Transcripts;
|
|
1748
1752
|
/** Stored transcripts translated, as jobs. */
|
|
1749
1753
|
translations?: StoredTranslations;
|
|
1754
|
+
/** The record of every file nixamp has met, by its SHA-256: nixamp.com/hash/<id>. */
|
|
1755
|
+
records?: Media;
|
|
1750
1756
|
/** nixamp.com's address, for the tools reached over /mcp to call. */
|
|
1751
1757
|
site?: string;
|
|
1752
1758
|
/** Other people's OpenProfiles, for the voice their lines are read in. */
|
|
@@ -2892,6 +2898,134 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2892
2898
|
return;
|
|
2893
2899
|
}
|
|
2894
2900
|
|
|
2901
|
+
/*
|
|
2902
|
+
* One address per file: /hash/<sha256>, the record of the bytes (see
|
|
2903
|
+
* media.ts). As a page for a person, as an OpenFile file object or plain
|
|
2904
|
+
* JSON for a program, and its transcript as subtitles. Reading is open:
|
|
2905
|
+
* the id is the hash of the bytes, and whoever has it has the file.
|
|
2906
|
+
* Keeping (PUT on the API) is signed in, like the ear.
|
|
2907
|
+
*/
|
|
2908
|
+
if (path === "/.well-known/openfile.json" && options.records && options.site) {
|
|
2909
|
+
json(response, 200, openFileListing(await options.records.recent(), options.site));
|
|
2910
|
+
return;
|
|
2911
|
+
}
|
|
2912
|
+
if ((path.startsWith("/hash/") || path === "/api/v1/media" || path.startsWith("/api/v1/media/")) && options.records && options.transcripts && options.site) {
|
|
2913
|
+
const media = options.records;
|
|
2914
|
+
const store = options.transcripts;
|
|
2915
|
+
const site = options.site;
|
|
2916
|
+
const viaApi = path.startsWith("/api/v1/media");
|
|
2917
|
+
const tail = viaApi ? path.slice("/api/v1/media".length).replace(/^\//, "") : path.slice("/hash/".length);
|
|
2918
|
+
const parts = /^([^/.]+)(?:\.(openfile\.json|json|srt|vtt|txt))?\/?$/.exec(tail);
|
|
2919
|
+
if (!parts) {
|
|
2920
|
+
json(response, 404, { error: "a file is /hash/<sha256>, with .json, .openfile.json, .srt, .vtt or .txt after it" });
|
|
2921
|
+
return;
|
|
2922
|
+
}
|
|
2923
|
+
let named = "";
|
|
2924
|
+
try {
|
|
2925
|
+
named = decodeURIComponent(parts[1] as string);
|
|
2926
|
+
} catch {
|
|
2927
|
+
json(response, 400, { error: "bad id" });
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2930
|
+
const format = parts[2] ?? "";
|
|
2931
|
+
try {
|
|
2932
|
+
if (request.method === "PUT" && viaApi) {
|
|
2933
|
+
const who = await options.accounts?.whoIs(tokenFrom(request.headers));
|
|
2934
|
+
if (!who) {
|
|
2935
|
+
json(response, 401, { error: "sign in to nixamp.com to keep a file's record" });
|
|
2936
|
+
return;
|
|
2937
|
+
}
|
|
2938
|
+
const id = mediaId(named);
|
|
2939
|
+
if (!id) {
|
|
2940
|
+
json(response, 400, { error: "the id is the file's SHA-256, hex" });
|
|
2941
|
+
return;
|
|
2942
|
+
}
|
|
2943
|
+
let body: { name?: unknown; size?: unknown; contentType?: unknown; updated?: unknown; facts?: unknown; holder?: unknown } = {};
|
|
2944
|
+
try {
|
|
2945
|
+
body = JSON.parse(await readBody(request, 256 * 1024)) as typeof body;
|
|
2946
|
+
} catch {
|
|
2947
|
+
json(response, 400, { error: "bad JSON" });
|
|
2948
|
+
return;
|
|
2949
|
+
}
|
|
2950
|
+
const saved = await media.save({
|
|
2951
|
+
id,
|
|
2952
|
+
...(typeof body.name === "string" ? { name: body.name.trim() } : {}),
|
|
2953
|
+
...(typeof body.size === "number" && body.size >= 0 ? { size: Math.floor(body.size) } : {}),
|
|
2954
|
+
...(typeof body.contentType === "string" ? { contentType: body.contentType.trim().slice(0, 100) } : {}),
|
|
2955
|
+
...(typeof body.updated === "string" && !Number.isNaN(Date.parse(body.updated)) ? { updated: new Date(body.updated).toISOString() } : {}),
|
|
2956
|
+
facts: factsFromRequest(body.facts),
|
|
2957
|
+
holder: holderFrom(body.holder),
|
|
2958
|
+
by: who.id,
|
|
2959
|
+
});
|
|
2960
|
+
if (!saved) {
|
|
2961
|
+
json(response, 500, { error: "the record was not kept" });
|
|
2962
|
+
return;
|
|
2963
|
+
}
|
|
2964
|
+
json(response, 200, openFileOf(saved, site, saved.facts.fingerprint ? await store.languages(transcriptIdOf(saved.facts.fingerprint)) : []));
|
|
2965
|
+
return;
|
|
2966
|
+
}
|
|
2967
|
+
if (request.method !== "GET") {
|
|
2968
|
+
json(response, 405, { error: "GET the record, or PUT what you know" });
|
|
2969
|
+
return;
|
|
2970
|
+
}
|
|
2971
|
+
// By the SHA-256, by the transcript store's fingerprint, or by a transcript id.
|
|
2972
|
+
let record: MediaRecord | null = null;
|
|
2973
|
+
const hex = mediaId(named);
|
|
2974
|
+
if (hex) record = await media.get(hex);
|
|
2975
|
+
if (!record && /^file:v1:[0-9a-f]{64}$/.test(named)) record = await media.byFingerprint(named);
|
|
2976
|
+
if (!record && hex) {
|
|
2977
|
+
const transcript = await store.get(hex);
|
|
2978
|
+
if (transcript && transcript.kind === "file") record = await media.byFingerprint(transcript.media);
|
|
2979
|
+
}
|
|
2980
|
+
if (!record) {
|
|
2981
|
+
json(response, 404, { error: "nixamp.com does not know that file yet. `nixamp hash FILE` tells it." });
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
const transcriptId = record.facts.fingerprint ? transcriptIdOf(record.facts.fingerprint) : null;
|
|
2985
|
+
const languages = transcriptId ? await store.languages(transcriptId) : [];
|
|
2986
|
+
if (format === "srt" || format === "vtt" || format === "txt") {
|
|
2987
|
+
const language = languageCode(url.searchParams.get("language"));
|
|
2988
|
+
if (language === null) {
|
|
2989
|
+
json(response, 400, { error: "language is a two-letter code" });
|
|
2990
|
+
return;
|
|
2991
|
+
}
|
|
2992
|
+
const transcript = transcriptId ? await store.get(transcriptId, language) : null;
|
|
2993
|
+
if (!transcript) {
|
|
2994
|
+
json(response, 404, { error: language ? `not written down in ${language}` : "not written down yet" });
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
const text = format === "srt" ? toSrt(transcript.lines) : format === "vtt" ? toVtt(transcript.lines) : toText(transcript.lines);
|
|
2998
|
+
const name = (record.name.replace(/\.[^.]+$/, "") || record.id.slice(0, 12)).replace(/[^\w.-]+/g, "_").slice(0, 60);
|
|
2999
|
+
response.writeHead(200, {
|
|
3000
|
+
...CORS,
|
|
3001
|
+
"content-type": `${format === "vtt" ? "text/vtt" : "text/plain"}; charset=utf-8`,
|
|
3002
|
+
"content-length": Buffer.byteLength(text),
|
|
3003
|
+
"cache-control": "public, max-age=300",
|
|
3004
|
+
"content-disposition": `inline; filename="${name}${transcript.language ? `.${transcript.language}` : ""}.${format}"`,
|
|
3005
|
+
});
|
|
3006
|
+
response.end(text);
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
const descriptor = openFileOf(record, site, languages);
|
|
3010
|
+
const accept = String(request.headers["accept"] ?? "");
|
|
3011
|
+
const wantsJson = viaApi || format === "json" || format === "openfile.json" || (accept.includes("application/json") && !accept.includes("text/html"));
|
|
3012
|
+
if (wantsJson) {
|
|
3013
|
+
json(response, 200, descriptor);
|
|
3014
|
+
return;
|
|
3015
|
+
}
|
|
3016
|
+
const original = transcriptId ? await store.get(transcriptId) : null;
|
|
3017
|
+
const forPage: PageTranscript[] = languages
|
|
3018
|
+
.slice()
|
|
3019
|
+
.sort((a, b) => (a.translatedFrom === null ? -1 : 0) - (b.translatedFrom === null ? -1 : 0))
|
|
3020
|
+
.map((one) => (original && one.language === original.language && one.translatedFrom === null ? { ...one, shown: original.lines } : one));
|
|
3021
|
+
html(response, 200, mediaPage(record, site, forPage));
|
|
3022
|
+
} catch (error) {
|
|
3023
|
+
if (error instanceof SpeechError) json(response, error.status, { error: error.message });
|
|
3024
|
+
else throw error;
|
|
3025
|
+
}
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
|
|
2895
3029
|
/*
|
|
2896
3030
|
* Translation: texts in one language, said in another, by a model on
|
|
2897
3031
|
* this CPU (see translate.ts). Signed in only, like the ear. GET says
|
|
@@ -5796,6 +5930,8 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
5796
5930
|
// What was heard, kept: where the accounts are, under the media's identity.
|
|
5797
5931
|
const transcripts = pool ? new Transcripts(pool, (message) => console.log(message)) : undefined;
|
|
5798
5932
|
const translations = transcripts ? new StoredTranslations(transcripts, translator, (message) => console.log(message)) : undefined;
|
|
5933
|
+
// The record of every file nixamp has met, by its bytes: nixamp.com/hash/<id>.
|
|
5934
|
+
const records = pool ? new Media(pool, (message) => console.log(message)) : undefined;
|
|
5799
5935
|
|
|
5800
5936
|
// nixamp as an OAuth 2.1 authorization server, and the watch parties a
|
|
5801
5937
|
// client site bridges through it. Both need the same three things -- a
|
|
@@ -6005,7 +6141,28 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
6005
6141
|
return { ...base, media: mediaOfUrl(pasted), position: info.position };
|
|
6006
6142
|
}
|
|
6007
6143
|
try {
|
|
6008
|
-
|
|
6144
|
+
const source = info.source;
|
|
6145
|
+
return {
|
|
6146
|
+
...base,
|
|
6147
|
+
media: fileFingerprint(source),
|
|
6148
|
+
position: info.position,
|
|
6149
|
+
// The file itself, for nixamp.com/hash/<id>: hashed here, once,
|
|
6150
|
+
// with what ffprobe and nichedb said and where it is on the air.
|
|
6151
|
+
describe: async () => {
|
|
6152
|
+
const listen = publishable_ ? shareLink(publishable_.url, listenKey, false) : (options.publicUrl || `http://${options.host}:${options.port}`);
|
|
6153
|
+
const described = await describeFile(source, {
|
|
6154
|
+
tools,
|
|
6155
|
+
enricher: enricher ?? null,
|
|
6156
|
+
holder: { kind: "gateway", url: listen, seenAt: new Date().toISOString(), channel: id, name: streamName },
|
|
6157
|
+
});
|
|
6158
|
+
try {
|
|
6159
|
+
remember(source, { id: described.id, fingerprint: described.fingerprint, size: described.size, mtimeMs: described.mtimeMs });
|
|
6160
|
+
} catch {
|
|
6161
|
+
// The index is a convenience.
|
|
6162
|
+
}
|
|
6163
|
+
return { id: described.id, keep: described.keep };
|
|
6164
|
+
},
|
|
6165
|
+
};
|
|
6009
6166
|
} catch {
|
|
6010
6167
|
return null;
|
|
6011
6168
|
}
|
|
@@ -6015,6 +6172,25 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
6015
6172
|
},
|
|
6016
6173
|
})
|
|
6017
6174
|
: undefined;
|
|
6175
|
+
// The files this machine has told nixamp.com about, looked at again on
|
|
6176
|
+
// their own schedule (media-index.ts): a changed file is a new record.
|
|
6177
|
+
if (tools.carries) {
|
|
6178
|
+
const watch = async (): Promise<void> => {
|
|
6179
|
+
const signed = readSession();
|
|
6180
|
+
if (!signed) return;
|
|
6181
|
+
const counts = await watchOnce({
|
|
6182
|
+
refresh: (file, before) => refreshChanged(signed, file, before, { tools, enricher: enricher ?? null }),
|
|
6183
|
+
onEvent: (message) => console.log(` ${message}`),
|
|
6184
|
+
}).catch((error: unknown) => {
|
|
6185
|
+
console.log(` the media index could not be read: ${(error as Error).message}`);
|
|
6186
|
+
return null;
|
|
6187
|
+
});
|
|
6188
|
+
if (counts && counts.changed > 0) console.log(` ${counts.changed} file(s) changed since nixamp.com last heard of them; told it`);
|
|
6189
|
+
};
|
|
6190
|
+
const watching = setInterval(() => void watch(), WATCH_EVERY_MS);
|
|
6191
|
+
watching.unref?.();
|
|
6192
|
+
setTimeout(() => void watch(), 60_000).unref?.();
|
|
6193
|
+
}
|
|
6018
6194
|
const owner = new Owner({
|
|
6019
6195
|
ownerId: options.owner || (session?.token ? await ownerIdOf(session) : ""),
|
|
6020
6196
|
site: session?.site ?? DEFAULT_DIRECTORY,
|
|
@@ -6227,6 +6403,7 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
6227
6403
|
...(translator ? { translator } : {}),
|
|
6228
6404
|
...(transcripts ? { transcripts } : {}),
|
|
6229
6405
|
...(translations ? { translations } : {}),
|
|
6406
|
+
...(records ? { records } : {}),
|
|
6230
6407
|
site: nixampSite,
|
|
6231
6408
|
// Other people's OpenProfiles, read for the voice a line is spoken in,
|
|
6232
6409
|
// and the voices to speak in: ElevenLabs when the Telnyx account holds
|
package/src/transcribe.ts
CHANGED
|
@@ -24,6 +24,8 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
24
24
|
import { basename, extname, join } from "node:path";
|
|
25
25
|
import { detectTools, type Tools } from "./audio.ts";
|
|
26
26
|
import { isQuiet } from "./captions.ts";
|
|
27
|
+
import { Enricher } from "./enrich.ts";
|
|
28
|
+
import { describeFile, keepFile } from "./media-local.ts";
|
|
27
29
|
import { readSession, type Session } from "./session.ts";
|
|
28
30
|
import { MAX_SECONDS, RATE, isWav, type Segment } from "./speech.ts";
|
|
29
31
|
import { fetchTranscript, keepLines, type Got, type StoredTranscript } from "./transcript-client.ts";
|
|
@@ -430,6 +432,21 @@ export async function transcribe(argv: string[], deps: TranscribeDeps = {}): Pro
|
|
|
430
432
|
}
|
|
431
433
|
const id = transcriptIdOf(media);
|
|
432
434
|
const title = /^https?:\/\//.test(file) ? file : basename(file, extname(file));
|
|
435
|
+
// A file gets its address at nixamp.com/hash/<sha256> too, with what this
|
|
436
|
+
// machine knows about it, so the transcript has somewhere to hang.
|
|
437
|
+
if (!/^https?:\/\//.test(file) && !deps.fingerprint) {
|
|
438
|
+
void (async () => {
|
|
439
|
+
try {
|
|
440
|
+
const tools = detectTools();
|
|
441
|
+
const described = await describeFile(file, { tools, enricher: new Enricher() });
|
|
442
|
+
const refused = await keepFile(signed, file, described, { fetcher });
|
|
443
|
+
if (refused) console.error(` The file's record was not kept: ${refused}`);
|
|
444
|
+
else console.error(` ${site}/hash/${described.id}`);
|
|
445
|
+
} catch {
|
|
446
|
+
// The transcript is the point; the record is a bonus.
|
|
447
|
+
}
|
|
448
|
+
})();
|
|
449
|
+
}
|
|
433
450
|
const wanted = (flag(argv, "--translate") ?? "").split(",").map((one) => languageCode(one)).filter((one): one is string => typeof one === "string" && one !== "");
|
|
434
451
|
if (argv.includes("--translate") && wanted.length === 0) {
|
|
435
452
|
console.error("nixamp: --translate is one or more two-letter codes, such as de,sv.");
|
package/src/transcript-client.ts
CHANGED
|
@@ -120,6 +120,40 @@ export async function translateTexts(
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/** What a machine tells nixamp.com about a file it has, for the record at /hash/<id>. */
|
|
124
|
+
export interface MediaToKeep {
|
|
125
|
+
name?: string;
|
|
126
|
+
size?: number;
|
|
127
|
+
contentType?: string;
|
|
128
|
+
updated?: string;
|
|
129
|
+
facts?: Record<string, unknown>;
|
|
130
|
+
holder?: { kind?: string; url: string; seenAt?: string; channel?: string; name?: string };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Keep what is known about a file, by its SHA-256 hex. */
|
|
134
|
+
export async function keepMedia(signed: Signed, id: string, ask: MediaToKeep, fetcher: typeof fetch = fetch): Promise<Got<Record<string, unknown>>> {
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetcher(`${base(signed.site)}/api/v1/media/${encodeURIComponent(id)}`, {
|
|
137
|
+
method: "PUT",
|
|
138
|
+
headers: { authorization: `Bearer ${signed.token}`, "content-type": "application/json" },
|
|
139
|
+
body: JSON.stringify(ask),
|
|
140
|
+
});
|
|
141
|
+
return await asJson(response);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return unreachable(signed.site, error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The record of a file, by id, fingerprint or transcript id. Public: no token needed. */
|
|
148
|
+
export async function fetchMedia(site: string, id: string, fetcher: typeof fetch = fetch): Promise<Got<Record<string, unknown>>> {
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetcher(`${base(site)}/api/v1/media/${encodeURIComponent(id)}`, { headers: { accept: "application/json" } });
|
|
151
|
+
return await asJson(response);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return unreachable(site, error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
123
157
|
/** Forget some media's transcripts. Only whoever stored them may. */
|
|
124
158
|
export async function forgetTranscript(signed: Signed, id: string, fetcher: typeof fetch = fetch): Promise<Got<{ ok: true }>> {
|
|
125
159
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./index-
|
|
1
|
+
import{t as e}from"./index-d7TvpeFZ.js";var t=3;async function n(n){let{media:r,src:i,isTv:a}=n,{default:o}=await e(async()=>{let{default:e}=await import(`./hls-n74Cnh8A.js`);return{default:e}},[]);if(!o.isSupported())return n.onError(`This browser cannot play HLS streams.`),{destroy:()=>void 0,levels:()=>[]};let s=new o({...a?{maxBufferLength:60,maxMaxBufferLength:120,backBufferLength:30,liveSyncDurationCount:4}:{backBufferLength:90},enableWorker:!0}),c=0,l=!1;s.on(o.Events.ERROR,(e,r)=>{if(!l&&r.fatal){if(c>=t){n.onError(`This stream kept failing and has been stopped.`),s.destroy();return}switch(c+=1,r.type){case o.ErrorTypes.NETWORK_ERROR:n.onNotice(`Reconnecting…`),s.startLoad();break;case o.ErrorTypes.MEDIA_ERROR:n.onNotice(`Recovering…`),s.recoverMediaError();break;default:n.onError(`This stream could not be played.`),s.destroy()}}}),s.on(o.Events.MANIFEST_PARSED,()=>{l||(n.onNotice(null),n.onReady?.({live:s.levels.length>0&&!Number.isFinite(r.duration),levels:u()}))}),s.on(o.Events.LEVEL_LOADED,(e,t)=>{l||n.onReady?.({live:t.details.live,levels:u()})}),s.on(o.Events.FRAG_BUFFERED,()=>{l||n.onNotice(null)});function u(){return s.levels.map((e,t)=>({index:t,height:e.height||null,bitrate:e.bitrate||null,label:e.height?`${String(e.height)}p`:`${String(Math.round((e.bitrate||0)/1e3))}k`}))}return s.loadSource(i),s.attachMedia(r),{destroy(){l=!0,s.destroy()},levels:u,setLevel(e){s.currentLevel=e},currentLevel:()=>s.autoLevelEnabled?-1:s.currentLevel}}export{n as createHlsEngine};
|