@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.
@@ -62,6 +62,10 @@ export declare function buildLrclibSearchUrl(query: LyricsQuery, origin?: string
62
62
  /**
63
63
  * Lyrics for a track from LRCLIB: the exact record when the track, artist, album and duration match, otherwise the
64
64
  * closest of the search results. Returns null when the database has nothing, and for instrumental tracks.
65
+ *
66
+ * It throws when the database could not be reached. A database that answered "nothing" and one that did not answer
67
+ * at all are different things, and a caller that cannot tell them apart ends up filing the second as a miss — which
68
+ * is how one moment offline used to leave a track wordless for as long as the miss was kept.
65
69
  */
66
70
  export declare function fetchLrclibLyrics(query: LyricsQuery, options?: LyricsRequestOptions): Promise<Lyrics | null>;
67
71
  /** Closest record: a duration within 5 seconds first, then the title and artist that look most alike. */
@@ -62,6 +62,104 @@ export type PlaybackTransferOutcome = {
62
62
  accepted: false;
63
63
  reason: 'refused' | 'busy' | 'timeout' | 'disabled' | 'other-app' | 'invalid' | 'unreachable';
64
64
  };
65
+ /**
66
+ * What a peer may ask another for, instead of being handed something.
67
+ *
68
+ * A transfer is pushed: the sender POSTs what it plays to the receiver, which means the
69
+ * receiver has to be a server. A phone is not one — there is no way to listen on a port from a
70
+ * WebView, and nothing on iOS or Android gives the app one. So the phone asks instead, and the
71
+ * answer comes back in the reply to its own request. The desktop, which already runs a server
72
+ * for the push, is the one that answers.
73
+ *
74
+ * - `playback`: what are you playing — the queue, the item, the position — with its media at
75
+ * addresses this peer can fetch.
76
+ * - `converted`: that same medium in a form I can read. Asked only after the engine has
77
+ * actually refused one, never guessed in advance: a container's verdict belongs to the
78
+ * engine that failed on it, and `canPlayType` has been measured answering empty for files it
79
+ * then plays.
80
+ * - `library`: what do you hold — a page of it, so a shelf of thousands answers in bounded
81
+ * pieces rather than one reply nobody can hold.
82
+ * - `item`: one of those, resolved to something playable. Asked when the viewer opens it, so
83
+ * a library is browsed without a share being minted for every file it holds.
84
+ */
85
+ export type PlaybackPullWant = 'playback' | 'converted' | 'library' | 'item';
86
+ export interface PlaybackPull {
87
+ version: number;
88
+ from: NgxspAppIdentity;
89
+ want: PlaybackPullWant;
90
+ /** For `converted` only: the medium, at the address this peer was given for it. */
91
+ url?: string;
92
+ /** For `item` only: which one, as the library page named it. */
93
+ id?: string;
94
+ /** For `library`: what to look for, and which slice. */
95
+ query?: string;
96
+ offset?: number;
97
+ limit?: number;
98
+ }
99
+ /**
100
+ * One of the holdings, as another device is told about it.
101
+ *
102
+ * What is *not* here is the point of the type. A library entry on this side carries the file's
103
+ * address on this machine, the folder it was found in and its path within it; none of that is
104
+ * any of the asking device's business, and none of it would mean anything there. What travels
105
+ * is what a person reads to choose a film, plus the id needed to ask for it.
106
+ */
107
+ export interface PlaybackLibraryEntry {
108
+ /** Opaque here: it means something only to the app that answered. */
109
+ id: string;
110
+ title: string;
111
+ /** What the holding is: a film, an episode, something else. */
112
+ category?: string;
113
+ /**
114
+ * Where the holding sits, in the words of the app kind that answered — the two apps never
115
+ * read each other's pages, since a pull from the other kind is refused before this is looked
116
+ * at. A video app says `series`, `season` and `episode`; an audio app says `artist` and
117
+ * `album`, and numbers its tracks with `episode` as it numbers its discs with `season`.
118
+ */
119
+ artist?: string;
120
+ album?: string;
121
+ series?: string;
122
+ season?: number;
123
+ episode?: number;
124
+ year?: number;
125
+ durationSec?: number;
126
+ description?: string;
127
+ /** Kept: two versions of one film are told apart by it, and nothing else would. */
128
+ fileName?: string;
129
+ /** Whether a picture comes with the item when it is asked for. */
130
+ artwork?: boolean;
131
+ }
132
+ export interface PlaybackLibraryPage {
133
+ entries: PlaybackLibraryEntry[];
134
+ /** What the question matches in all, so the asker knows there is more. */
135
+ total: number;
136
+ offset: number;
137
+ }
138
+ export type PlaybackPullOutcome = {
139
+ got: true;
140
+ want: 'playback';
141
+ transfer: PlaybackTransfer;
142
+ token?: string;
143
+ } | {
144
+ got: true;
145
+ want: 'converted';
146
+ url: string;
147
+ durationSec?: number;
148
+ token?: string;
149
+ } | {
150
+ got: true;
151
+ want: 'library';
152
+ page: PlaybackLibraryPage;
153
+ token?: string;
154
+ } | {
155
+ got: true;
156
+ want: 'item';
157
+ item: PlaybackTransferItem;
158
+ token?: string;
159
+ } | {
160
+ got: false;
161
+ reason: 'refused' | 'busy' | 'timeout' | 'disabled' | 'other-app' | 'invalid' | 'unreachable' | 'nothing';
162
+ };
65
163
  /** The TXT entries an app advertises. */
66
164
  export declare function ngxspTxt(identity: NgxspAppIdentity): Record<string, string>;
67
165
  /** The records an app answers `_ngxsp._tcp` questions with, for each of its addresses. */
@@ -73,16 +171,66 @@ export declare function ngxspPeersFromMdns(answers: ReadonlyArray<{
73
171
  }>, self: Pick<NgxspAppIdentity, 'id' | 'app'>): NgxspPeer[];
74
172
  /** A transfer as received, checked and trimmed; null when it is not one. */
75
173
  export declare function readPlaybackTransfer(value: unknown): PlaybackTransfer | null;
174
+ /** One item as a peer sent it, checked the same way as those inside a transfer. */
175
+ export declare function readPlaybackTransferItem(value: unknown): PlaybackTransferItem | null;
176
+ /**
177
+ * A pull as received, checked; null when it is not one. Both shapes arrive on the same
178
+ * endpoint, and `want` is what tells them apart — a transfer carries items and no `want`.
179
+ */
180
+ export declare function readPlaybackPull(value: unknown): PlaybackPull | null;
181
+ /** A library page as a peer sent it, bounded and checked; null when it is not one. */
182
+ export declare function readPlaybackLibraryPage(value: unknown): PlaybackLibraryPage | null;
76
183
  export interface PlaybackTransferReceiverOptions {
77
184
  app: NgxspAppKind;
78
185
  /** Off, the app refuses every transfer without asking. */
79
186
  enabled: () => boolean;
80
187
  trusted: () => readonly TrustedSender[];
81
188
  saveTrusted: (senders: TrustedSender[]) => void;
82
- /** Asks the user whether `from` may send its playback here: true to allow. */
83
- ask: (from: NgxspAppIdentity) => Promise<boolean>;
189
+ /**
190
+ * Asks the user whether `from` may be served: true to allow. `want` says what for — left out
191
+ * when a transfer is being pushed here, so the question can be worded for what is happening.
192
+ * Being asked for what this app plays is not the same as being handed something.
193
+ */
194
+ /**
195
+ * Asks this device's user. `expired` fires when the asking device has stopped waiting, so the
196
+ * question can be taken off the screen: left up, it is one nobody can usefully answer, and the
197
+ * answer it finally gets resolves a promise no one is holding.
198
+ */
199
+ ask: (from: NgxspAppIdentity, want?: PlaybackPullWant, expired?: AbortSignal) => Promise<boolean>;
84
200
  /** Plays what was transferred. */
85
201
  apply: (transfer: PlaybackTransfer) => void;
202
+ /**
203
+ * What this app plays, for a peer that asks, with its media at addresses that peer can
204
+ * fetch — which is why it is given the peer's own address. Null when nothing is playing.
205
+ * Left out by an app that cannot be asked, and it then answers so.
206
+ */
207
+ offer?: (from: NgxspAppIdentity, peerAddress: string) => Promise<PlaybackTransfer | null>;
208
+ /**
209
+ * The same medium in a form the asking peer can read. Null when this one cannot be converted
210
+ * — no converter here, or it failed. Left out by an app that converts nothing.
211
+ */
212
+ convert?: (url: string, from: NgxspAppIdentity, peerAddress: string) => Promise<{
213
+ url: string;
214
+ durationSec?: number;
215
+ } | null>;
216
+ /**
217
+ * A page of what this app holds, for a peer that asks. Null when there is no library here.
218
+ *
219
+ * **Left out is how a library stays private.** Answering this hands a device the whole
220
+ * shelf, which is more than being asked what is playing: an app only passes it once its
221
+ * user has said that other devices may read this library, and an app that does not pass it
222
+ * answers that it cannot be asked — without putting the question to anyone.
223
+ */
224
+ browse?: (from: NgxspAppIdentity, peerAddress: string, page: {
225
+ query?: string;
226
+ offset: number;
227
+ limit: number;
228
+ }) => Promise<PlaybackLibraryPage | null>;
229
+ /**
230
+ * One of those holdings, resolved to something the asking peer can fetch — which is why a
231
+ * share is minted here, at the moment it is opened, and not for every file of a page.
232
+ */
233
+ item?: (from: NgxspAppIdentity, peerAddress: string, id: string) => Promise<PlaybackTransferItem | null>;
86
234
  sha256Hex: (value: string) => Promise<string>;
87
235
  randomToken: () => string;
88
236
  promptMs?: number;
@@ -93,6 +241,8 @@ export interface PlaybackTransferRequest {
93
241
  body: string;
94
242
  /** The `Authorization` header: `NGXSP <token>` from a sender allowed before. */
95
243
  authorization?: string;
244
+ /** Where the request came from, so media can be shared at an address it can reach. */
245
+ address?: string;
96
246
  }
97
247
  export interface PlaybackTransferResponse {
98
248
  status: number;
@@ -104,3 +254,11 @@ export declare function createPlaybackTransferReceiver(options: PlaybackTransfer
104
254
  };
105
255
  /** Sends a transfer to a peer, with the token it gave the last time if there is one. */
106
256
  export declare function sendPlaybackTransfer(http: MediaSourceHttp, peer: Pick<NgxspPeer, 'address' | 'port'>, transfer: PlaybackTransfer, token?: string): Promise<PlaybackTransferOutcome>;
257
+ /**
258
+ * Asks a peer for what it plays, or for a medium in a form this app can read, with the token it
259
+ * gave the last time if there is one.
260
+ *
261
+ * What comes back is read with the same checks as anything else off the network: a peer's reply
262
+ * is data, and a transfer it sends is passed through `readPlaybackTransfer` before it is used.
263
+ */
264
+ export declare function pullFromPeer(http: MediaSourceHttp, peer: Pick<NgxspPeer, 'address' | 'port'>, pull: PlaybackPull, token?: string): Promise<PlaybackPullOutcome>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngxsp/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1-next.561",
4
4
  "license": "MIT",
5
5
  "description": "Composable core runtime for audio and video playback workflows.",
6
6
  "keywords": [
@@ -1,5 +1,5 @@
1
1
  export type TelemetryLevel = 'debug' | 'info' | 'warn' | 'error';
2
- export type TelemetryEvent = 'player:init' | 'player:attach' | 'player:source_set' | 'player:engine_selected' | 'player:load_start' | 'player:load_ok' | 'player:load_fail' | 'player:play_request' | 'player:play_ok' | 'player:play_fail' | 'player:play_aborted' | 'player:pause' | 'player:timeupdate' | 'player:ended' | 'player:error_nonfatal' | 'player:error_fatal' | 'player:playing' | 'qoe:first_frame' | 'qoe:rebuffer_start' | 'qoe:rebuffer_end' | 'qoe:summary' | 'player:auto_next' | 'player:playlist_index' | 'ads:break_start' | 'ads:break_end' | 'ads:ad_start' | 'ads:ad_end' | 'ssai:manifest_rewrite';
2
+ export type TelemetryEvent = 'player:init' | 'player:attach' | 'player:source_set' | 'player:engine_selected' | 'player:load_start' | 'player:load_ok' | 'player:load_fail' | 'player:load_superseded' | 'player:play_request' | 'player:play_ok' | 'player:play_fail' | 'player:play_aborted' | 'player:pause' | 'player:timeupdate' | 'player:ended' | 'player:error_nonfatal' | 'player:error_fatal' | 'player:playing' | 'qoe:first_frame' | 'qoe:rebuffer_start' | 'qoe:rebuffer_end' | 'qoe:summary' | 'player:auto_next' | 'player:playlist_index' | 'ads:break_start' | 'ads:break_end' | 'ads:ad_start' | 'ads:ad_end' | 'ssai:manifest_rewrite';
3
3
  export interface TelemetrySample {
4
4
  ts: number;
5
5
  level: TelemetryLevel;
package/types.d.ts CHANGED
@@ -49,6 +49,15 @@ export interface PlayerSource {
49
49
  drm?: DrmConfig;
50
50
  /** Optional engine profile for default tuning (can be set at `PlayerConfig.profile`). */
51
51
  profile?: EngineProfileId;
52
+ /**
53
+ * How long the medium is, when the caller knows and the stream will not say.
54
+ *
55
+ * A hint, and only used while the engine has nothing better: an HLS playlist that is still
56
+ * growing declares no length, so the transport read `0:00` for the whole of a film another
57
+ * machine was converting — although that machine had announced its length when it answered.
58
+ * Anything the engine reports outranks this.
59
+ */
60
+ durationSec?: number;
52
61
  /**
53
62
  * Optional ABR hints for adaptive engines (e.g. Shaka).
54
63
  *
@@ -60,7 +69,22 @@ export interface PlayerSource {
60
69
  /** Hard cap for bitrate (bits/s). */
61
70
  maxBandwidth?: number;
62
71
  };
63
- /** Internal engine hints (best-effort). */
72
+ /**
73
+ * How much of the stream is kept ahead, in seconds, and whether latency is chased.
74
+ *
75
+ * These are *hints*: an engine that cannot honour them ignores them, and an engine that plays
76
+ * a local file has nothing to keep ahead at all. What is set here outranks the profile's own
77
+ * defaults — the profile fills what is left out, it does not decide for a caller who asked.
78
+ */
79
+ streaming?: {
80
+ /** Chases the live edge, at the cost of a thinner buffer. */
81
+ lowLatencyMode?: boolean;
82
+ /** How far ahead to keep, in seconds. */
83
+ bufferingGoalSec?: number;
84
+ /** How much has to be back before playback resumes after a stall, in seconds. */
85
+ rebufferingGoalSec?: number;
86
+ };
87
+ /** Internal engine hints (best-effort); `streaming` is the way to set these. */
64
88
  _shakaStreaming?: {
65
89
  lowLatencyMode?: boolean;
66
90
  bufferingGoalSec?: number;
@@ -305,6 +329,28 @@ export interface PlayerError {
305
329
  fatal?: boolean;
306
330
  details?: unknown;
307
331
  }
332
+ /**
333
+ * Whether an error means "this engine cannot read this source at all" — a container it does not
334
+ * open, rather than a file it failed to fetch.
335
+ *
336
+ * The same verdict reaches hosts under three spellings, because the browsers disagree on how they
337
+ * deliver it: Chromium fires the element's `error` with MEDIA_ERR_SRC_NOT_SUPPORTED, which the
338
+ * native engine passes on as `HTML5_4` and the facade maps to `SRC_NOT_SUPPORTED`; WebKit instead
339
+ * rejects `play()` and never fires that event. A host that tests one spelling therefore works on
340
+ * the desktop and does nothing on the phone, which is where an unreadable container actually turns
341
+ * up. Ask here rather than comparing a code by hand.
342
+ */
343
+ /**
344
+ * The length to show: what the engine reports, and the caller's announced figure while it
345
+ * reports nothing usable.
346
+ *
347
+ * Neither 0 nor Infinity is a length. A stream that has not said yet reports 0, and an HLS
348
+ * playlist that is still growing reports Infinity until it ends — so a film another machine was
349
+ * converting read `0:00` for the whole of the playback, although that machine had announced its
350
+ * length when it answered. Whatever the engine knows outranks what the caller was told.
351
+ */
352
+ export declare function playableDurationSec(reported: number | undefined | null, announced: number | undefined | null): number;
353
+ export declare function meansSourceNotSupported(code: string | undefined | null): boolean;
308
354
  export interface MediaTrack {
309
355
  id: string;
310
356
  kind: 'audio' | 'text' | 'video';