@ngxsp/core 0.3.0 → 0.3.1-next.561
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/domain/media-library-model.d.ts +20 -1
- package/domain/media-share.d.ts +15 -0
- package/domain/plural.d.ts +11 -0
- package/domain/superseded-load.d.ts +1 -0
- package/engine/remote-playback.engine.d.ts +0 -6
- package/facade/player-facade.d.ts +10 -0
- package/index.cjs +297 -31
- package/index.cjs.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +289 -32
- package/index.js.map +1 -1
- package/online/lyrics.d.ts +4 -0
- package/online/playback-transfer.d.ts +160 -2
- package/package.json +1 -1
- package/telemetry/telemetry.types.d.ts +1 -1
- package/types.d.ts +47 -1
package/index.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export * from './domain/media-library-model';
|
|
|
37
37
|
export * from './domain/media-source';
|
|
38
38
|
export * from './domain/queue';
|
|
39
39
|
export * from './domain/ringtone';
|
|
40
|
+
export * from './domain/media-share';
|
|
41
|
+
export * from './domain/plural';
|
|
40
42
|
export * from './domain/shake';
|
|
41
43
|
export * from './domain/device-playback';
|
|
42
44
|
export * from './domain/remote-playback';
|
package/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
2
2
|
|
|
3
|
+
// src/types.ts
|
|
4
|
+
function playableDurationSec(reported, announced) {
|
|
5
|
+
if (typeof reported === "number" && Number.isFinite(reported) && reported > 0) return reported;
|
|
6
|
+
if (typeof announced === "number" && Number.isFinite(announced) && announced > 0) return announced;
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
function meansSourceNotSupported(code) {
|
|
10
|
+
return code === "SRC_NOT_SUPPORTED" || code === "HTML5_4";
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
// src/config/default-config.ts
|
|
4
14
|
var DEFAULT_PROGRESS_CONFIG = {
|
|
5
15
|
mode: "local",
|
|
@@ -94,6 +104,16 @@ function parseRemoteClock(value) {
|
|
|
94
104
|
return Number(match[1]) * 3600 + Number(match[2]) * 60 + Number(match[3]) + (match[4] ? Number(`0.${match[4]}`) : 0);
|
|
95
105
|
}
|
|
96
106
|
|
|
107
|
+
// src/domain/superseded-load.ts
|
|
108
|
+
var SHAKA_SUPERSEDED_LOAD_CODES = /* @__PURE__ */ new Set([7e3, 7001, 7003]);
|
|
109
|
+
function isSupersededLoad(error) {
|
|
110
|
+
const candidate = error;
|
|
111
|
+
if (candidate?.name === "AbortError") return true;
|
|
112
|
+
if (SHAKA_SUPERSEDED_LOAD_CODES.has(Number(candidate?.code))) return true;
|
|
113
|
+
const message = String(candidate?.message ?? "").toLowerCase();
|
|
114
|
+
return message.includes("interrupted by a new load request") || message.includes("operation was aborted");
|
|
115
|
+
}
|
|
116
|
+
|
|
97
117
|
// src/engine/engine-factory.ts
|
|
98
118
|
function selectEngine(config, factories, caps) {
|
|
99
119
|
const candidates = (factories ?? []).filter((f) => {
|
|
@@ -329,10 +349,11 @@ function applyEngineProfileToSource(source, profile) {
|
|
|
329
349
|
profile: p
|
|
330
350
|
};
|
|
331
351
|
if (Object.keys(abrOut).length) out.abr = abrOut;
|
|
332
|
-
|
|
352
|
+
const streamingIn = { ...anySrc._shakaStreaming ?? {}, ...anySrc.streaming ?? {} };
|
|
353
|
+
if (hints.shakaStreaming || Object.keys(streamingIn).length) {
|
|
333
354
|
out._shakaStreaming = {
|
|
334
|
-
...
|
|
335
|
-
...
|
|
355
|
+
...hints.shakaStreaming ?? {},
|
|
356
|
+
...streamingIn
|
|
336
357
|
};
|
|
337
358
|
}
|
|
338
359
|
return out;
|
|
@@ -629,6 +650,16 @@ var PlayerFacade = class {
|
|
|
629
650
|
engineFactories = [createNativeEngineFactory()];
|
|
630
651
|
engineId = "native";
|
|
631
652
|
lastNonFatal = null;
|
|
653
|
+
/**
|
|
654
|
+
* Which load has already had its failure reported.
|
|
655
|
+
*
|
|
656
|
+
* One unreadable file used to be reported three times over, by three doors: the media element's
|
|
657
|
+
* own error event, the rejection of `play()`, and the engine's error event. Three codes, three
|
|
658
|
+
* messages, nothing a host could tell apart from three broken files — so a listener was told
|
|
659
|
+
* three times, and a host that moves on after a failure heard three reasons to move.
|
|
660
|
+
*/
|
|
661
|
+
failureReportedForLoad = -1;
|
|
662
|
+
loadCount = 0;
|
|
632
663
|
// Optional MediaCapabilities decoding probes (async, best-effort)
|
|
633
664
|
mediaDecodingSub = new BehaviorSubject(null);
|
|
634
665
|
video;
|
|
@@ -688,6 +719,8 @@ var PlayerFacade = class {
|
|
|
688
719
|
async load(config, opts) {
|
|
689
720
|
if (!this.video) throw new Error("PlayerFacade not attached");
|
|
690
721
|
if (!this.ctx) throw new Error("PlayerFacade context missing");
|
|
722
|
+
this.loadCount += 1;
|
|
723
|
+
const loadId = this.loadCount;
|
|
691
724
|
const rc = await applyRemoteConfig(config, this.ports);
|
|
692
725
|
if (rc.applied) {
|
|
693
726
|
this.ports.telemetry?.add?.({
|
|
@@ -772,6 +805,11 @@ var PlayerFacade = class {
|
|
|
772
805
|
this.stateSub.next({ kind: "paused" });
|
|
773
806
|
this.emitTelemetry("player:load_ok", "info");
|
|
774
807
|
} catch (err) {
|
|
808
|
+
const replaced = this.loadCount !== loadId || this.engine !== engine;
|
|
809
|
+
if (replaced && isSupersededLoad(err)) {
|
|
810
|
+
this.emitTelemetry("player:load_superseded", "info", {}, err?.message);
|
|
811
|
+
throw err;
|
|
812
|
+
}
|
|
775
813
|
this.emitTelemetry("player:load_fail", "error", {}, err?.message);
|
|
776
814
|
this.emitFatal(err, "UNKNOWN");
|
|
777
815
|
throw err;
|
|
@@ -850,6 +888,17 @@ var PlayerFacade = class {
|
|
|
850
888
|
emitFatal(err, code = "UNKNOWN") {
|
|
851
889
|
const pe = this.toPlayerError(err, true, code);
|
|
852
890
|
this.emitTelemetry("player:error_fatal", "error", { code: pe.code }, pe.message);
|
|
891
|
+
if (this.failureReportedForLoad === this.loadCount) {
|
|
892
|
+
this.errorSub.next(pe);
|
|
893
|
+
if (this.ctx) for (const p of this.plugins) {
|
|
894
|
+
try {
|
|
895
|
+
void p.onError?.(this.ctx, pe);
|
|
896
|
+
} catch {
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
this.failureReportedForLoad = this.loadCount;
|
|
853
902
|
this.stateSub.next({ kind: "error", error: pe });
|
|
854
903
|
this.errorSub.next(pe);
|
|
855
904
|
if (this.ctx) {
|
|
@@ -980,6 +1029,7 @@ var PlayerFacade = class {
|
|
|
980
1029
|
}
|
|
981
1030
|
async play() {
|
|
982
1031
|
this.emitTelemetry("player:play_request", "info");
|
|
1032
|
+
this.failureReportedForLoad = -1;
|
|
983
1033
|
try {
|
|
984
1034
|
await this.engine?.play();
|
|
985
1035
|
this.emitTelemetry("player:play_ok", "info");
|
|
@@ -992,6 +1042,9 @@ var PlayerFacade = class {
|
|
|
992
1042
|
if (name === "NotAllowedError") {
|
|
993
1043
|
this.emitNonFatal(err, "AUTOPLAY_BLOCKED");
|
|
994
1044
|
this.emitTelemetry("player:play_fail", "warn", { code: "AUTOPLAY_BLOCKED" }, err?.message);
|
|
1045
|
+
} else if (name === "NotSupportedError") {
|
|
1046
|
+
this.emitFatal(err, "SRC_NOT_SUPPORTED");
|
|
1047
|
+
this.emitTelemetry("player:play_fail", "error", { code: "SRC_NOT_SUPPORTED" }, err?.message);
|
|
995
1048
|
} else if (name === "RemotePlaybackError") {
|
|
996
1049
|
const code = remotePlaybackErrorCode(err.code);
|
|
997
1050
|
this.emitFatal(err, code);
|
|
@@ -1191,7 +1244,10 @@ var PlayerFacade = class {
|
|
|
1191
1244
|
}
|
|
1192
1245
|
if (ev.type === "error") {
|
|
1193
1246
|
const pe = { code: ev.error.code, message: ev.error.message, fatal: ev.error.fatal, details: ev.error.details };
|
|
1194
|
-
this.
|
|
1247
|
+
if (this.failureReportedForLoad !== this.loadCount) {
|
|
1248
|
+
this.failureReportedForLoad = this.loadCount;
|
|
1249
|
+
this.stateSub.next({ kind: "error", error: pe });
|
|
1250
|
+
}
|
|
1195
1251
|
this.errorSub.next(pe);
|
|
1196
1252
|
try {
|
|
1197
1253
|
this.ctx?.ports.telemetry.add({ t: Date.now(), kind: "error", code: pe.code, fatal: !!pe.fatal });
|
|
@@ -1585,6 +1641,7 @@ function createSsaiManifestRewritePlugin() {
|
|
|
1585
1641
|
}
|
|
1586
1642
|
|
|
1587
1643
|
// src/engine/remote-playback.engine.ts
|
|
1644
|
+
var DURATION_SLACK_SEC = 1;
|
|
1588
1645
|
function createRemotePlaybackEngineFactory(options) {
|
|
1589
1646
|
return {
|
|
1590
1647
|
id: "remote",
|
|
@@ -1726,9 +1783,10 @@ var RemotePlaybackEngine = class {
|
|
|
1726
1783
|
const status = await this.session.status();
|
|
1727
1784
|
if (this.destroyed) return;
|
|
1728
1785
|
this.failures = 0;
|
|
1729
|
-
if (status.durationSec && !this.media?.conversion) this.durationSec = status.durationSec;
|
|
1786
|
+
if (status.durationSec && !this.media?.conversion && !this.media?.durationSec) this.durationSec = status.durationSec;
|
|
1730
1787
|
if (status.positionSec !== void 0) this.positionSec = this.offsetSec + status.positionSec;
|
|
1731
1788
|
this.furthestSec = Math.max(this.furthestSec, this.positionSec - this.offsetSec);
|
|
1789
|
+
if (this.durationSec > 0 && this.positionSec > this.durationSec + DURATION_SLACK_SEC) this.durationSec = 0;
|
|
1732
1790
|
const wasPlaying = this.lastState === "playing" || this.lastState === "buffering";
|
|
1733
1791
|
const refused = (status.ended || status.state === "stopped") && this.furthestSec < 1 && !this.source?.live && (status.ended || wasPlaying);
|
|
1734
1792
|
if ((refused || status.error) && this.convertible(this.media)) {
|
|
@@ -2536,23 +2594,27 @@ function audioFieldsFromTags({ relativePath, common = {}, format = {} }) {
|
|
|
2536
2594
|
const numbered = LEADING_TRACK_NUMBER.exec(stem);
|
|
2537
2595
|
const ancestors = ancestorNames(relativePath);
|
|
2538
2596
|
const artists = Array.isArray(common.artists) ? common.artists.filter(Boolean) : [];
|
|
2539
|
-
const
|
|
2540
|
-
const
|
|
2597
|
+
const genreTag = common.genres ?? common.genre;
|
|
2598
|
+
const genre = Array.isArray(genreTag) ? genreTag.find(Boolean) : genreTag;
|
|
2599
|
+
const albumArtistTag = nonEmpty(common.albumArtist) ?? nonEmpty(common.albumartist);
|
|
2600
|
+
const trackNoTag = positiveInteger(common.trackNumber) ?? positiveInteger(common.track?.no);
|
|
2601
|
+
const discNoTag = positiveInteger(common.discNumber) ?? positiveInteger(common.disk?.no);
|
|
2602
|
+
const taggedArtist = nonEmpty(common.artist) ?? nonEmpty(artists.join(", ")) ?? albumArtistTag;
|
|
2541
2603
|
const inferredFields = [
|
|
2542
2604
|
!nonEmpty(common.title) && "title",
|
|
2543
2605
|
!taggedArtist && "artist",
|
|
2544
|
-
!
|
|
2606
|
+
!albumArtistTag && !nonEmpty(common.artist) && "albumArtist",
|
|
2545
2607
|
!nonEmpty(common.album) && "album",
|
|
2546
|
-
!
|
|
2608
|
+
!trackNoTag && numbered && "trackNo"
|
|
2547
2609
|
].filter((field) => typeof field === "string");
|
|
2548
2610
|
return {
|
|
2549
2611
|
title: nonEmpty(common.title) ?? cleanMediaTitle(numbered ? numbered[2] : stem),
|
|
2550
2612
|
artist: taggedArtist ?? (ancestors[1] ? tidy2(ancestors[1]) : void 0),
|
|
2551
|
-
albumArtist:
|
|
2613
|
+
albumArtist: albumArtistTag ?? nonEmpty(common.artist) ?? (ancestors[1] ? tidy2(ancestors[1]) : void 0),
|
|
2552
2614
|
album: nonEmpty(common.album) ?? (ancestors[0] ? tidy2(ancestors[0]) : void 0),
|
|
2553
2615
|
genre: nonEmpty(genre),
|
|
2554
|
-
trackNo:
|
|
2555
|
-
discNo:
|
|
2616
|
+
trackNo: trackNoTag ?? (numbered ? positiveInteger(numbered[1]) : void 0),
|
|
2617
|
+
discNo: discNoTag,
|
|
2556
2618
|
year: positiveInteger(common.year),
|
|
2557
2619
|
durationSec: durationOf(format),
|
|
2558
2620
|
inferredFields: inferredFields.length ? inferredFields : void 0
|
|
@@ -2748,6 +2810,29 @@ function writeText(view, offset, text6) {
|
|
|
2748
2810
|
for (let index = 0; index < text6.length; index += 1) view.setUint8(offset + index, text6.charCodeAt(index));
|
|
2749
2811
|
}
|
|
2750
2812
|
|
|
2813
|
+
// src/domain/media-share.ts
|
|
2814
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
2815
|
+
function shareableSourceUrl(source) {
|
|
2816
|
+
if (!source) return null;
|
|
2817
|
+
let url;
|
|
2818
|
+
try {
|
|
2819
|
+
url = new URL(source);
|
|
2820
|
+
} catch {
|
|
2821
|
+
return null;
|
|
2822
|
+
}
|
|
2823
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
|
|
2824
|
+
if (LOOPBACK_HOSTS.has(url.hostname.toLowerCase())) return null;
|
|
2825
|
+
return url.href;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// src/domain/plural.ts
|
|
2829
|
+
function pluralWord(locale, count, singular, plural) {
|
|
2830
|
+
return (locale === "fr" ? count > 1 : count !== 1) ? plural : singular;
|
|
2831
|
+
}
|
|
2832
|
+
function countLabel(locale, count, singular, plural) {
|
|
2833
|
+
return `${count} ${pluralWord(locale, count, singular, plural)}`;
|
|
2834
|
+
}
|
|
2835
|
+
|
|
2751
2836
|
// src/domain/shake.ts
|
|
2752
2837
|
var DEFAULTS = {
|
|
2753
2838
|
force: 12,
|
|
@@ -4215,6 +4300,8 @@ var NGXSP_SERVICE_TYPE = "_ngxsp._tcp.local";
|
|
|
4215
4300
|
var PLAYBACK_TRANSFER_PATH = "/ngxsp/transfer";
|
|
4216
4301
|
var PLAYBACK_TRANSFER_VERSION = 1;
|
|
4217
4302
|
var PLAYBACK_TRANSFER_PROMPT_MS = 6e4;
|
|
4303
|
+
var MAX_PAGE = 200;
|
|
4304
|
+
var DEFAULT_PAGE = 50;
|
|
4218
4305
|
var MAX_ITEMS = 200;
|
|
4219
4306
|
var MAX_TEXT = 300;
|
|
4220
4307
|
function ngxspTxt(identity) {
|
|
@@ -4262,6 +4349,9 @@ function readPlaybackTransfer(value) {
|
|
|
4262
4349
|
playing: input["playing"] !== false
|
|
4263
4350
|
};
|
|
4264
4351
|
}
|
|
4352
|
+
function readPlaybackTransferItem(value) {
|
|
4353
|
+
return readItem(value);
|
|
4354
|
+
}
|
|
4265
4355
|
function readItem(value) {
|
|
4266
4356
|
if (!value || typeof value !== "object") return null;
|
|
4267
4357
|
const input = value;
|
|
@@ -4282,6 +4372,78 @@ function readItem(value) {
|
|
|
4282
4372
|
function text2(value, max = MAX_TEXT) {
|
|
4283
4373
|
return typeof value === "string" ? value.replace(/[\u0000-\u001f]/g, " ").trim().slice(0, max) : "";
|
|
4284
4374
|
}
|
|
4375
|
+
function readPlaybackPull(value) {
|
|
4376
|
+
if (!value || typeof value !== "object") return null;
|
|
4377
|
+
const input = value;
|
|
4378
|
+
const want = input["want"];
|
|
4379
|
+
if (want !== "playback" && want !== "converted" && want !== "library" && want !== "item") return null;
|
|
4380
|
+
const from = input["from"];
|
|
4381
|
+
const app = from?.["app"];
|
|
4382
|
+
if (input["version"] !== PLAYBACK_TRANSFER_VERSION || !from || typeof from["id"] !== "string" || !from["id"] || app !== "audio" && app !== "video") return null;
|
|
4383
|
+
const url = text2(input["url"], 4e3);
|
|
4384
|
+
if (want === "converted" && !/^https?:\/\//i.test(url)) return null;
|
|
4385
|
+
const id = text2(input["id"], 200);
|
|
4386
|
+
if (want === "item" && !id) return null;
|
|
4387
|
+
const offset = Number(input["offset"]);
|
|
4388
|
+
const limit = Number(input["limit"]);
|
|
4389
|
+
return {
|
|
4390
|
+
version: PLAYBACK_TRANSFER_VERSION,
|
|
4391
|
+
from: { id: text2(from["id"]).slice(0, 64), name: text2(from["name"]) || text2(from["id"]).slice(0, 8), app },
|
|
4392
|
+
want,
|
|
4393
|
+
...want === "converted" ? { url } : {},
|
|
4394
|
+
...want === "item" ? { id } : {},
|
|
4395
|
+
// Whatever is asked for, the slice is this app's to bound: a peer does not get to ask for
|
|
4396
|
+
// ten thousand entries in one reply.
|
|
4397
|
+
...want === "library" ? {
|
|
4398
|
+
...text2(input["query"]) ? { query: text2(input["query"]) } : {},
|
|
4399
|
+
offset: Number.isInteger(offset) && offset > 0 ? offset : 0,
|
|
4400
|
+
limit: Number.isInteger(limit) && limit > 0 ? Math.min(limit, MAX_PAGE) : DEFAULT_PAGE
|
|
4401
|
+
} : {}
|
|
4402
|
+
};
|
|
4403
|
+
}
|
|
4404
|
+
function readPlaybackLibraryPage(value) {
|
|
4405
|
+
if (!value || typeof value !== "object") return null;
|
|
4406
|
+
const input = value;
|
|
4407
|
+
if (!Array.isArray(input["entries"])) return null;
|
|
4408
|
+
const entries = input["entries"].slice(0, MAX_PAGE).flatMap((entry) => {
|
|
4409
|
+
const read = readLibraryEntry(entry);
|
|
4410
|
+
return read ? [read] : [];
|
|
4411
|
+
});
|
|
4412
|
+
const total = Number(input["total"]);
|
|
4413
|
+
const offset = Number(input["offset"]);
|
|
4414
|
+
return {
|
|
4415
|
+
entries,
|
|
4416
|
+
total: Number.isInteger(total) && total >= 0 ? total : entries.length,
|
|
4417
|
+
offset: Number.isInteger(offset) && offset > 0 ? offset : 0
|
|
4418
|
+
};
|
|
4419
|
+
}
|
|
4420
|
+
function readLibraryEntry(value) {
|
|
4421
|
+
if (!value || typeof value !== "object") return null;
|
|
4422
|
+
const input = value;
|
|
4423
|
+
const id = text2(input["id"], 200);
|
|
4424
|
+
const title = text2(input["title"]);
|
|
4425
|
+
if (!id || !title) return null;
|
|
4426
|
+
const whole = (key, max) => {
|
|
4427
|
+
const read = Number(input[key]);
|
|
4428
|
+
return Number.isInteger(read) && read >= 0 && read <= max ? read : void 0;
|
|
4429
|
+
};
|
|
4430
|
+
const durationSec = Number(input["durationSec"]);
|
|
4431
|
+
return {
|
|
4432
|
+
id,
|
|
4433
|
+
title,
|
|
4434
|
+
...text2(input["category"], 40) ? { category: text2(input["category"], 40) } : {},
|
|
4435
|
+
...text2(input["artist"]) ? { artist: text2(input["artist"]) } : {},
|
|
4436
|
+
...text2(input["album"]) ? { album: text2(input["album"]) } : {},
|
|
4437
|
+
...text2(input["series"]) ? { series: text2(input["series"]) } : {},
|
|
4438
|
+
...whole("season", 9999) !== void 0 ? { season: whole("season", 9999) } : {},
|
|
4439
|
+
...whole("episode", 99999) !== void 0 ? { episode: whole("episode", 99999) } : {},
|
|
4440
|
+
...whole("year", 9999) !== void 0 ? { year: whole("year", 9999) } : {},
|
|
4441
|
+
...Number.isFinite(durationSec) && durationSec > 0 ? { durationSec } : {},
|
|
4442
|
+
...text2(input["description"], 2e3) ? { description: text2(input["description"], 2e3) } : {},
|
|
4443
|
+
...text2(input["fileName"]) ? { fileName: text2(input["fileName"]) } : {},
|
|
4444
|
+
...input["artwork"] === true ? { artwork: true } : {}
|
|
4445
|
+
};
|
|
4446
|
+
}
|
|
4285
4447
|
function createPlaybackTransferReceiver(options) {
|
|
4286
4448
|
let asking = false;
|
|
4287
4449
|
async function isTrusted(from, authorization) {
|
|
@@ -4289,41 +4451,87 @@ function createPlaybackTransferReceiver(options) {
|
|
|
4289
4451
|
const sender = options.trusted().find((entry) => entry.id === from.id);
|
|
4290
4452
|
return !!token && !!sender && await options.sha256Hex(token) === sender.tokenHash;
|
|
4291
4453
|
}
|
|
4292
|
-
async function
|
|
4293
|
-
if (
|
|
4294
|
-
if (!options.enabled()) return { status: 403, body: { accepted: false, reason: "disabled" } };
|
|
4295
|
-
let transfer = null;
|
|
4296
|
-
try {
|
|
4297
|
-
transfer = readPlaybackTransfer(JSON.parse(request2.body));
|
|
4298
|
-
} catch {
|
|
4299
|
-
transfer = null;
|
|
4300
|
-
}
|
|
4301
|
-
if (!transfer) return { status: 400, body: { accepted: false, reason: "invalid" } };
|
|
4302
|
-
if (transfer.from.app !== options.app) return { status: 422, body: { accepted: false, reason: "other-app" } };
|
|
4303
|
-
if (await isTrusted(transfer.from, request2.authorization)) {
|
|
4304
|
-
const from = transfer.from;
|
|
4454
|
+
async function admit(from, authorization, want) {
|
|
4455
|
+
if (await isTrusted(from, authorization)) {
|
|
4305
4456
|
options.saveTrusted(options.trusted().map((entry) => entry.id === from.id ? { ...entry, name: from.name } : entry));
|
|
4306
|
-
|
|
4307
|
-
return { status: 200, body: { accepted: true } };
|
|
4457
|
+
return { allowed: true };
|
|
4308
4458
|
}
|
|
4309
4459
|
if (asking) return { status: 409, body: { accepted: false, reason: "busy" } };
|
|
4310
4460
|
asking = true;
|
|
4311
4461
|
let allowed;
|
|
4462
|
+
const expired = new AbortController();
|
|
4312
4463
|
try {
|
|
4313
4464
|
allowed = await Promise.race([
|
|
4314
|
-
options.ask(
|
|
4465
|
+
options.ask(from, want, expired.signal),
|
|
4315
4466
|
new Promise((resolve) => setTimeout(() => resolve("timeout"), options.promptMs ?? PLAYBACK_TRANSFER_PROMPT_MS))
|
|
4316
4467
|
]);
|
|
4317
4468
|
} finally {
|
|
4318
4469
|
asking = false;
|
|
4470
|
+
expired.abort();
|
|
4319
4471
|
}
|
|
4320
4472
|
if (allowed === "timeout") return { status: 408, body: { accepted: false, reason: "timeout" } };
|
|
4321
4473
|
if (!allowed) return { status: 403, body: { accepted: false, reason: "refused" } };
|
|
4322
4474
|
const token = options.randomToken();
|
|
4323
|
-
const sender = { id:
|
|
4475
|
+
const sender = { id: from.id, name: from.name, tokenHash: await options.sha256Hex(token), since: Date.now() };
|
|
4324
4476
|
options.saveTrusted([...options.trusted().filter((entry) => entry.id !== sender.id), sender]);
|
|
4477
|
+
return { allowed: true, token };
|
|
4478
|
+
}
|
|
4479
|
+
async function answerPull(pull, request2) {
|
|
4480
|
+
if (pull.from.app !== options.app) return { status: 422, body: { accepted: false, reason: "other-app" } };
|
|
4481
|
+
const answers = { playback: options.offer, converted: options.convert, library: options.browse, item: options.item }[pull.want];
|
|
4482
|
+
if (!answers) return { status: 501, body: { accepted: false, reason: "disabled" } };
|
|
4483
|
+
const verdict = await admit(pull.from, request2.authorization, pull.want);
|
|
4484
|
+
if (!("allowed" in verdict)) return verdict;
|
|
4485
|
+
const token = verdict.token ? { token: verdict.token } : {};
|
|
4486
|
+
const address = text2(request2.address, 60);
|
|
4487
|
+
try {
|
|
4488
|
+
if (pull.want === "playback") {
|
|
4489
|
+
const transfer = await options.offer(pull.from, address);
|
|
4490
|
+
if (!transfer) return { status: 404, body: { accepted: false, reason: "nothing", ...token } };
|
|
4491
|
+
return { status: 200, body: { accepted: true, transfer, ...token } };
|
|
4492
|
+
}
|
|
4493
|
+
if (pull.want === "library") {
|
|
4494
|
+
const page = await options.browse(pull.from, address, {
|
|
4495
|
+
...pull.query ? { query: pull.query } : {},
|
|
4496
|
+
offset: pull.offset ?? 0,
|
|
4497
|
+
limit: pull.limit ?? DEFAULT_PAGE
|
|
4498
|
+
});
|
|
4499
|
+
if (!page) return { status: 404, body: { accepted: false, reason: "nothing", ...token } };
|
|
4500
|
+
return { status: 200, body: { accepted: true, page, ...token } };
|
|
4501
|
+
}
|
|
4502
|
+
if (pull.want === "item") {
|
|
4503
|
+
const item = await options.item(pull.from, address, pull.id);
|
|
4504
|
+
if (!item) return { status: 404, body: { accepted: false, reason: "nothing", ...token } };
|
|
4505
|
+
return { status: 200, body: { accepted: true, item, ...token } };
|
|
4506
|
+
}
|
|
4507
|
+
const converted = await options.convert(pull.url, pull.from, address);
|
|
4508
|
+
if (!converted) return { status: 404, body: { accepted: false, reason: "nothing", ...token } };
|
|
4509
|
+
return {
|
|
4510
|
+
status: 200,
|
|
4511
|
+
body: { accepted: true, url: converted.url, ...converted.durationSec ? { durationSec: converted.durationSec } : {}, ...token }
|
|
4512
|
+
};
|
|
4513
|
+
} catch {
|
|
4514
|
+
return { status: 404, body: { accepted: false, reason: "nothing", ...token } };
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
async function handle(request2) {
|
|
4518
|
+
if (request2.method.toUpperCase() !== "POST") return { status: 405, body: { accepted: false, reason: "invalid" } };
|
|
4519
|
+
if (!options.enabled()) return { status: 403, body: { accepted: false, reason: "disabled" } };
|
|
4520
|
+
let parsed = null;
|
|
4521
|
+
try {
|
|
4522
|
+
parsed = JSON.parse(request2.body);
|
|
4523
|
+
} catch {
|
|
4524
|
+
return { status: 400, body: { accepted: false, reason: "invalid" } };
|
|
4525
|
+
}
|
|
4526
|
+
const pull = readPlaybackPull(parsed);
|
|
4527
|
+
if (pull) return answerPull(pull, request2);
|
|
4528
|
+
const transfer = readPlaybackTransfer(parsed);
|
|
4529
|
+
if (!transfer) return { status: 400, body: { accepted: false, reason: "invalid" } };
|
|
4530
|
+
if (transfer.from.app !== options.app) return { status: 422, body: { accepted: false, reason: "other-app" } };
|
|
4531
|
+
const verdict = await admit(transfer.from, request2.authorization);
|
|
4532
|
+
if (!("allowed" in verdict)) return verdict;
|
|
4325
4533
|
options.apply(transfer);
|
|
4326
|
-
return { status: 200, body: { accepted: true, token } };
|
|
4534
|
+
return { status: 200, body: { accepted: true, ...verdict.token ? { token: verdict.token } : {} } };
|
|
4327
4535
|
}
|
|
4328
4536
|
return { handle };
|
|
4329
4537
|
}
|
|
@@ -4354,6 +4562,55 @@ async function sendPlaybackTransfer(http, peer, transfer, token) {
|
|
|
4354
4562
|
const reason = reasons.find((entry) => entry === body["reason"]);
|
|
4355
4563
|
return { accepted: false, reason: reason ?? "unreachable" };
|
|
4356
4564
|
}
|
|
4565
|
+
async function pullFromPeer(http, peer, pull, token) {
|
|
4566
|
+
let response;
|
|
4567
|
+
try {
|
|
4568
|
+
response = await http.send({
|
|
4569
|
+
url: `http://${peer.address}:${peer.port}${PLAYBACK_TRANSFER_PATH}`,
|
|
4570
|
+
method: "POST",
|
|
4571
|
+
headers: { "Content-Type": "application/json", ...token ? { Authorization: `NGXSP ${token}` } : {} },
|
|
4572
|
+
body: JSON.stringify(pull),
|
|
4573
|
+
// The other device may be waiting for its user, and a conversion starts with a probe.
|
|
4574
|
+
timeoutMs: PLAYBACK_TRANSFER_PROMPT_MS + 15e3
|
|
4575
|
+
});
|
|
4576
|
+
} catch {
|
|
4577
|
+
return { got: false, reason: "unreachable" };
|
|
4578
|
+
}
|
|
4579
|
+
let body = {};
|
|
4580
|
+
try {
|
|
4581
|
+
body = JSON.parse(await response.text());
|
|
4582
|
+
} catch {
|
|
4583
|
+
body = {};
|
|
4584
|
+
}
|
|
4585
|
+
const given = typeof body["token"] === "string" ? { token: body["token"] } : {};
|
|
4586
|
+
if (response.status === 200 && body["accepted"] === true) {
|
|
4587
|
+
if (pull.want === "playback") {
|
|
4588
|
+
const transfer = readPlaybackTransfer(body["transfer"]);
|
|
4589
|
+
return transfer ? { got: true, want: "playback", transfer, ...given } : { got: false, reason: "invalid" };
|
|
4590
|
+
}
|
|
4591
|
+
if (pull.want === "library") {
|
|
4592
|
+
const page = readPlaybackLibraryPage(body["page"]);
|
|
4593
|
+
return page ? { got: true, want: "library", page, ...given } : { got: false, reason: "invalid" };
|
|
4594
|
+
}
|
|
4595
|
+
if (pull.want === "item") {
|
|
4596
|
+
const item = readPlaybackTransferItem(body["item"]);
|
|
4597
|
+
return item ? { got: true, want: "item", item, ...given } : { got: false, reason: "invalid" };
|
|
4598
|
+
}
|
|
4599
|
+
const url = typeof body["url"] === "string" ? body["url"] : "";
|
|
4600
|
+
if (!/^https?:\/\//i.test(url)) return { got: false, reason: "invalid" };
|
|
4601
|
+
const durationSec = Number(body["durationSec"]);
|
|
4602
|
+
return {
|
|
4603
|
+
got: true,
|
|
4604
|
+
want: "converted",
|
|
4605
|
+
url,
|
|
4606
|
+
...Number.isFinite(durationSec) && durationSec > 0 ? { durationSec } : {},
|
|
4607
|
+
...given
|
|
4608
|
+
};
|
|
4609
|
+
}
|
|
4610
|
+
const reasons = ["refused", "busy", "timeout", "disabled", "other-app", "invalid", "nothing"];
|
|
4611
|
+
const reason = reasons.find((entry) => entry === body["reason"]);
|
|
4612
|
+
return { got: false, reason: reason ?? "unreachable" };
|
|
4613
|
+
}
|
|
4357
4614
|
|
|
4358
4615
|
// src/online/md5.ts
|
|
4359
4616
|
function md5Hex(input) {
|
|
@@ -5256,7 +5513,7 @@ async function fetchLrclibLyrics(query, options = {}) {
|
|
|
5256
5513
|
const exact = await http.getJson(buildLrclibGetUrl({ ...query, title }, options.origin), request2).catch(() => null);
|
|
5257
5514
|
const direct = lyricsFromRecord(exact);
|
|
5258
5515
|
if (direct) return direct;
|
|
5259
|
-
const results = await http.getJson(buildLrclibSearchUrl({ ...query, title }, options.origin), request2)
|
|
5516
|
+
const results = await http.getJson(buildLrclibSearchUrl({ ...query, title }, options.origin), request2);
|
|
5260
5517
|
if (!Array.isArray(results)) return null;
|
|
5261
5518
|
const best = bestLrclibMatch(results, { ...query, title });
|
|
5262
5519
|
return best ? lyricsFromRecord(best) : null;
|
|
@@ -5346,6 +5603,6 @@ async function lookupAcoustId(query, request2 = {}) {
|
|
|
5346
5603
|
});
|
|
5347
5604
|
}
|
|
5348
5605
|
|
|
5349
|
-
export { ACOUSTID_ORIGIN, AUDIO_IDENTIFICATION_RETRY_MS, AUDIO_IDENTIFICATION_VERSION, CAST_DEFAULT_MEDIA_RECEIVER, CAST_MDNS_SERVICE, CAST_PORT, ConsoleLogPort, DEFAULT_ADS_CONFIG, DEFAULT_METADATA_CONFIG, DEFAULT_PROGRESS_CONFIG, DEFAULT_RESILIENCE_CONFIG, DEFAULT_SUBTITLES_CONFIG, DEFAULT_UI_CONFIG, DLNA_MEDIA_RENDERER_SEARCH_TARGET, DLNA_MEDIA_SERVER_SEARCH_TARGET, DefaultCacheStore, INTERNET_ARCHIVE_ORIGIN, INTERNET_ARCHIVE_PLAYABLE_FILTERS, JELLYFIN_CLIENT, LRCLIB_ORIGIN, LocalMetadataProvider, LocalSubtitleProvider, MDNS_ADDRESS, MDNS_PORT, MEDIA_LIBRARY_MODEL_VERSION, MUSICBRAINZ_ORIGIN, MemoryStoragePort, NGXSP_SERVICE_TYPE, NativeEngine, NoopTelemetryPort, PLAYBACK_TRANSFER_PATH, PLAYBACK_TRANSFER_PROMPT_MS, PLAYBACK_TRANSFER_VERSION, PlayerFacade, ProgressPlugin, RADIO_BROWSER_ORIGIN, RINGTONE_FADE_SEC, RINGTONE_MAX_SEC, RemotePlaybackEngine, RemotePlaybackError, ResiliencePlugin, SUBSONIC_API_VERSION, SUBSONIC_CLIENT, SimpleEventBus, UpnpActionError, applyAudioIdentification, applyEngineProfileToSource, applyRemoteConfig, audioFieldsFromTags, audioIdentificationDoubts, audioTrackMatchesSearch, bestLrclibMatch, browseDlna, browseJellyfin, browseSubsonic, browseWebDav, buildAcoustIdLookupUrl, buildInternetArchiveSearchUrl, buildLrclibGetUrl, buildLrclibSearchUrl, buildMusicBrainzRecordingSearchUrl, buildRadioBrowserSearchUrl, castContentType, castDevicesFromMdns, cleanAudioArtistName, cleanMediaTitle, connectDlna, connectJellyfin, connectSubsonic, connectWebDav, createAudioLibrarySnapshot, createCapabilityReport, createCastSession, createDefaultCapabilities, createDefaultConfig, createDefaultPorts, createDlnaConnector, createDlnaRendererSession, createFetchOnlineJsonHttp, createIdentificationRoutine, createIdleDevicePlaybackState, createJellyfinConnector, createMediaCache, createMediaDecodingReport, createNativeEngineFactory, createPlaybackTransferReceiver, createRemotePlaybackEngineFactory, createShakeDetector, createSsaiManifestRewritePlugin, createSubsonicConnector, createWebDavConnector, decodeCastFrames, decodeSubtitleBytes, describeSubtitleFile, detectPlaybackCapabilities, encodeCastMessage, encodeMdnsQuery, encodeMdnsResponse, encodeWav, fadeEdges, fetchInternetArchiveItem, fetchLrclibLyrics, fileKeyFor, findUpnpService, folderArtworkRank, formatRemoteClock, getEngineProfileHints, harmonizeAudioMetadata, internetArchiveAudioTracks, internetArchiveDetailsUrl, internetArchiveDownloadUrl, internetArchiveThumbnailUrl, isCategorizedEventType, isIgnoredDirectoryName, isImageFileName, isMediaFileName, jellyfinClientHeader, jellyfinImageUrl, jellyfinStreamUrl, lookupAcoustId, lookupMusicBrainzRecording, lyricsFromTags, lyricsLineIndexAt, matchFingerprintedRecording, matchMusicBrainzRecording, md5Hex, mdnsServices, mediaContentType, mediaFileExtension, mediaMetadataKey, mediaSourceItemId, needsAudioIdentification, ngxspPeersFromMdns, ngxspServiceRecords, ngxspTxt, normalizeAudioSearchText, normalizeMediaSourceAddress, parseDidlLite, parseEpisodeFileName, parseInternetArchiveItem, parseInternetArchiveLength, parseJellyfinItem, parseLrc, parseMdnsMessage, parseMdnsQuestions, parseMediaSourceItemId, parseMusicBrainzRecording, parseRadioStation, parseRemoteClock, parseSubsonicSong, parseUpnpDeviceDescription, parseWebDavMultistatus, pickAcoustIdRecording, planMediaCacheEviction, readDlnaRenderer, readJellyfinLyrics, readPlaybackTransfer, readWebDavLyrics, reduceDevicePlaybackState, remotePlaybackErrorCode, remotePlaybackFailure, ringtoneFileName, ringtoneSegment, searchAudioLibrarySnapshot, searchInternetArchive, searchMusicBrainzRecordings, searchRadioStations, selectEngine, selectInternetArchiveVideo, sendPlaybackTransfer, subsonicCoverUrl, subsonicStreamUrl, subtitleTextToVtt, ticksToSeconds, upnpAction, videoFieldsFromTags, webDavAuthorization };
|
|
5606
|
+
export { ACOUSTID_ORIGIN, AUDIO_IDENTIFICATION_RETRY_MS, AUDIO_IDENTIFICATION_VERSION, CAST_DEFAULT_MEDIA_RECEIVER, CAST_MDNS_SERVICE, CAST_PORT, ConsoleLogPort, DEFAULT_ADS_CONFIG, DEFAULT_METADATA_CONFIG, DEFAULT_PROGRESS_CONFIG, DEFAULT_RESILIENCE_CONFIG, DEFAULT_SUBTITLES_CONFIG, DEFAULT_UI_CONFIG, DLNA_MEDIA_RENDERER_SEARCH_TARGET, DLNA_MEDIA_SERVER_SEARCH_TARGET, DefaultCacheStore, INTERNET_ARCHIVE_ORIGIN, INTERNET_ARCHIVE_PLAYABLE_FILTERS, JELLYFIN_CLIENT, LRCLIB_ORIGIN, LocalMetadataProvider, LocalSubtitleProvider, MDNS_ADDRESS, MDNS_PORT, MEDIA_LIBRARY_MODEL_VERSION, MUSICBRAINZ_ORIGIN, MemoryStoragePort, NGXSP_SERVICE_TYPE, NativeEngine, NoopTelemetryPort, PLAYBACK_TRANSFER_PATH, PLAYBACK_TRANSFER_PROMPT_MS, PLAYBACK_TRANSFER_VERSION, PlayerFacade, ProgressPlugin, RADIO_BROWSER_ORIGIN, RINGTONE_FADE_SEC, RINGTONE_MAX_SEC, RemotePlaybackEngine, RemotePlaybackError, ResiliencePlugin, SUBSONIC_API_VERSION, SUBSONIC_CLIENT, SimpleEventBus, UpnpActionError, applyAudioIdentification, applyEngineProfileToSource, applyRemoteConfig, audioFieldsFromTags, audioIdentificationDoubts, audioTrackMatchesSearch, bestLrclibMatch, browseDlna, browseJellyfin, browseSubsonic, browseWebDav, buildAcoustIdLookupUrl, buildInternetArchiveSearchUrl, buildLrclibGetUrl, buildLrclibSearchUrl, buildMusicBrainzRecordingSearchUrl, buildRadioBrowserSearchUrl, castContentType, castDevicesFromMdns, cleanAudioArtistName, cleanMediaTitle, connectDlna, connectJellyfin, connectSubsonic, connectWebDav, countLabel, createAudioLibrarySnapshot, createCapabilityReport, createCastSession, createDefaultCapabilities, createDefaultConfig, createDefaultPorts, createDlnaConnector, createDlnaRendererSession, createFetchOnlineJsonHttp, createIdentificationRoutine, createIdleDevicePlaybackState, createJellyfinConnector, createMediaCache, createMediaDecodingReport, createNativeEngineFactory, createPlaybackTransferReceiver, createRemotePlaybackEngineFactory, createShakeDetector, createSsaiManifestRewritePlugin, createSubsonicConnector, createWebDavConnector, decodeCastFrames, decodeSubtitleBytes, describeSubtitleFile, detectPlaybackCapabilities, encodeCastMessage, encodeMdnsQuery, encodeMdnsResponse, encodeWav, fadeEdges, fetchInternetArchiveItem, fetchLrclibLyrics, fileKeyFor, findUpnpService, folderArtworkRank, formatRemoteClock, getEngineProfileHints, harmonizeAudioMetadata, internetArchiveAudioTracks, internetArchiveDetailsUrl, internetArchiveDownloadUrl, internetArchiveThumbnailUrl, isCategorizedEventType, isIgnoredDirectoryName, isImageFileName, isMediaFileName, jellyfinClientHeader, jellyfinImageUrl, jellyfinStreamUrl, lookupAcoustId, lookupMusicBrainzRecording, lyricsFromTags, lyricsLineIndexAt, matchFingerprintedRecording, matchMusicBrainzRecording, md5Hex, mdnsServices, meansSourceNotSupported, mediaContentType, mediaFileExtension, mediaMetadataKey, mediaSourceItemId, needsAudioIdentification, ngxspPeersFromMdns, ngxspServiceRecords, ngxspTxt, normalizeAudioSearchText, normalizeMediaSourceAddress, parseDidlLite, parseEpisodeFileName, parseInternetArchiveItem, parseInternetArchiveLength, parseJellyfinItem, parseLrc, parseMdnsMessage, parseMdnsQuestions, parseMediaSourceItemId, parseMusicBrainzRecording, parseRadioStation, parseRemoteClock, parseSubsonicSong, parseUpnpDeviceDescription, parseWebDavMultistatus, pickAcoustIdRecording, planMediaCacheEviction, playableDurationSec, pluralWord, pullFromPeer, readDlnaRenderer, readJellyfinLyrics, readPlaybackLibraryPage, readPlaybackPull, readPlaybackTransfer, readPlaybackTransferItem, readWebDavLyrics, reduceDevicePlaybackState, remotePlaybackErrorCode, remotePlaybackFailure, ringtoneFileName, ringtoneSegment, searchAudioLibrarySnapshot, searchInternetArchive, searchMusicBrainzRecordings, searchRadioStations, selectEngine, selectInternetArchiveVideo, sendPlaybackTransfer, shareableSourceUrl, subsonicCoverUrl, subsonicStreamUrl, subtitleTextToVtt, ticksToSeconds, upnpAction, videoFieldsFromTags, webDavAuthorization };
|
|
5350
5607
|
//# sourceMappingURL=index.js.map
|
|
5351
5608
|
//# sourceMappingURL=index.js.map
|