nixamp 0.7.5 → 0.7.7

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/dist/admin.js CHANGED
@@ -21,7 +21,15 @@ export function resolveTarget(argv) {
21
21
  }
22
22
  const state = readState();
23
23
  if (state === null) {
24
- throw new Error("nixamp: no daemon is running. Start one with `nixamp daemon start`, or pass --url.");
24
+ // Named, with an example. "or pass --url" is only an instruction if you
25
+ // already know what belongs after it, and the whole point of this message
26
+ // is that you are looking at a machine you have no handle on.
27
+ throw new Error("nixamp: no daemon is running on this machine.\n" +
28
+ " Start one: nixamp daemon start ~/Music\n" +
29
+ " Or administer another machine, with its share link:\n" +
30
+ " nixamp admin --url https://server1.you.nixamp.com:4321 --key KEY\n" +
31
+ " The URL and key are the two halves of the link that server printed:\n" +
32
+ " https://host:4321/s/KEY");
25
33
  }
26
34
  const url_ = daemonUrl(state);
27
35
  // Talking to our own daemon, whose certificate names somewhere else. Nothing
package/dist/audio.d.ts CHANGED
@@ -78,6 +78,17 @@ export interface Codecs {
78
78
  video: string;
79
79
  /** e.g. "aac", "ac3", "dts". Empty when there is no audio stream. */
80
80
  audio: string;
81
+ /**
82
+ * What is wrapped around them: "mpegts", "matroska,webm", "mov,mp4,...".
83
+ *
84
+ * It matters for one reason. A transport stream -- which is what every IPTV
85
+ * channel is -- frames its AAC as ADTS, and copying that into MP4 needs a
86
+ * bitstream filter or ffmpeg refuses the whole muxing and writes nothing.
87
+ * They also tend to carry several audio tracks, so the one ffmpeg picks can
88
+ * be AC-3 on the same URL that offered AAC a minute earlier, and AC-3 in MP4
89
+ * is a track no browser will play.
90
+ */
91
+ container: string;
81
92
  }
82
93
  /**
83
94
  * Ask ffprobe what the streams are, without holding the event loop.
package/dist/audio.js CHANGED
@@ -284,7 +284,7 @@ function readTags(stdout, fallback) {
284
284
  */
285
285
  export async function codecsOf(tools, path) {
286
286
  const [cmd, ...rest] = tools.ffprobe;
287
- const empty = { video: "", audio: "" };
287
+ const empty = { video: "", audio: "", container: "" };
288
288
  if (!cmd)
289
289
  return empty;
290
290
  return new Promise((done) => {
@@ -292,7 +292,7 @@ export async function codecsOf(tools, path) {
292
292
  ...rest,
293
293
  "-v", "quiet",
294
294
  "-print_format", "json",
295
- "-show_entries", "stream=codec_type,codec_name",
295
+ "-show_entries", "format=format_name:stream=codec_type,codec_name",
296
296
  path,
297
297
  ], { stdio: ["ignore", "pipe", "ignore"] });
298
298
  let out = "";
@@ -307,6 +307,7 @@ export async function codecsOf(tools, path) {
307
307
  return done({
308
308
  video: streams.find((s) => s.codec_type === "video")?.codec_name ?? "",
309
309
  audio: streams.find((s) => s.codec_type === "audio")?.codec_name ?? "",
310
+ container: parsed.format?.format_name ?? "",
310
311
  });
311
312
  }
312
313
  catch {
@@ -331,7 +332,13 @@ export function videoArgs(codecs, capKbps = 0) {
331
332
  return cappedArgs(capKbps);
332
333
  // What a browser can play inside MP4 without help.
333
334
  const keepVideo = codecs.video === "h264";
334
- const keepAudio = codecs.audio === "aac" || codecs.audio === "mp3";
335
+ // A transport stream's audio is never copied. Its AAC is ADTS-framed, which
336
+ // MP4 refuses without a bitstream filter -- ffmpeg writes nothing at all and
337
+ // says "Malformed AAC bitstream detected" -- and the track ffmpeg picks off
338
+ // a channel with several of them can be AC-3, which that filter rejects and
339
+ // no browser plays. Re-encoding audio is cheap; this failing is total.
340
+ const transportStream = codecs.container.includes("mpegts");
341
+ const keepAudio = !transportStream && (codecs.audio === "aac" || codecs.audio === "mp3");
335
342
  return [
336
343
  "-c:v", keepVideo ? "copy" : "libx264",
337
344
  ...(keepVideo ? [] : ["-preset", "veryfast", "-crf", "23", "-pix_fmt", "yuv420p"]),
package/dist/daemon.d.ts CHANGED
@@ -27,6 +27,15 @@ export interface DaemonState {
27
27
  * interface, so it names the router and not this port.
28
28
  */
29
29
  guessedPublic?: boolean;
30
+ /**
31
+ * What it was started with, so it can be started that way again.
32
+ *
33
+ * A daemon serving TLS on a public name is six flags, and restarting it
34
+ * meant finding them again -- from shell history, or from `ps`, or not at
35
+ * all. Absent on a state file written by an older nixamp, which is why
36
+ * `restart` says so rather than starting something different.
37
+ */
38
+ argv?: string[];
30
39
  }
31
40
  /** XDG, with the usual fallback. One daemon per user, which is one too few for nobody. */
32
41
  export declare function stateDir(): string;
@@ -75,5 +84,16 @@ export declare function daemonLines(state: DaemonState, uptimeMs?: number): stri
75
84
  * log file is the thing this is meant to avoid.
76
85
  */
77
86
  export declare function start(argv: string[], entry: string): Promise<DaemonState>;
87
+ /**
88
+ * Stop it and start it again, the way it was started.
89
+ *
90
+ * The flags are replayed from the state file rather than retyped, because the
91
+ * interesting daemons are the ones with the most flags: a certificate, a key,
92
+ * a public URL. Given arguments of its own it uses those instead, which is how
93
+ * you change one thing without stopping and starting by hand.
94
+ */
95
+ export declare function restart(argv: string[], entry: string,
96
+ /** Injected so a test can see which arguments would be replayed. */
97
+ starter?: typeof start): Promise<DaemonState>;
78
98
  /** Stop it, and wait for it to actually be gone. */
79
99
  export declare function stop(timeoutMs?: number): Promise<boolean>;
package/dist/daemon.js CHANGED
@@ -178,10 +178,30 @@ export async function start(argv, entry) {
178
178
  }
179
179
  throw new Error(`nixamp: the daemon did not start. See ${log}`);
180
180
  }
181
- const state = { ...announced, pid: child.pid, startedAt: Date.now(), log };
181
+ const state = { ...announced, pid: child.pid, startedAt: Date.now(), log, argv };
182
182
  writeState(state);
183
183
  return state;
184
184
  }
185
+ /**
186
+ * Stop it and start it again, the way it was started.
187
+ *
188
+ * The flags are replayed from the state file rather than retyped, because the
189
+ * interesting daemons are the ones with the most flags: a certificate, a key,
190
+ * a public URL. Given arguments of its own it uses those instead, which is how
191
+ * you change one thing without stopping and starting by hand.
192
+ */
193
+ export async function restart(argv, entry,
194
+ /** Injected so a test can see which arguments would be replayed. */
195
+ starter = start) {
196
+ const { state } = status();
197
+ const before = state?.argv;
198
+ if (argv.length === 0 && before === undefined && state !== null) {
199
+ throw new Error("nixamp: this daemon was started by an older nixamp, which did not record its flags. " +
200
+ "Stop it and start it again with the flags you want.");
201
+ }
202
+ await stop();
203
+ return starter(argv.length > 0 ? argv : (before ?? []), entry);
204
+ }
185
205
  /** Poll the log for the announce line. */
186
206
  async function waitForAnnounce(log, timeoutMs) {
187
207
  const deadline = Date.now() + timeoutMs;
package/dist/invite.d.ts CHANGED
@@ -2,9 +2,11 @@
2
2
  * Asking somebody to watch, when that somebody is not technical.
3
3
  *
4
4
  * A share link is a URL with a key in it, which is fine for the person who
5
- * runs the server and useless as a thing to text your mother. An invite is the
6
- * three ways in, written as a sentence: a link that opens a player, a phone
7
- * number, and the code to key once it answers.
5
+ * runs the server and useless as a thing to text your mother. An invite is two
6
+ * things written as a sentence: a link that opens a player, and a phone number
7
+ * with a code, which is the line where everyone watching talks to each other.
8
+ * The phone is not another way to hear the stream -- it is the 800 number
9
+ * beside a podcast. The show is on the screen; the call is the company.
8
10
  *
9
11
  * The sender is signed in, because sending is an action with a cost: a text
10
12
  * message is money and somebody's phone. The recipient signs in too, but only
@@ -21,7 +23,7 @@ export interface Invite {
21
23
  link: string;
22
24
  /** The phone number, when this stream is one the line knows about. */
23
25
  phone: string;
24
- /** The six digits that reach this stream, when it has been published. */
26
+ /** The six digits that reach this stream's room, once it has been published. */
25
27
  code: string;
26
28
  }
27
29
  /** Looks like a phone number rather than an address. */
package/dist/invite.js CHANGED
@@ -2,9 +2,11 @@
2
2
  * Asking somebody to watch, when that somebody is not technical.
3
3
  *
4
4
  * A share link is a URL with a key in it, which is fine for the person who
5
- * runs the server and useless as a thing to text your mother. An invite is the
6
- * three ways in, written as a sentence: a link that opens a player, a phone
7
- * number, and the code to key once it answers.
5
+ * runs the server and useless as a thing to text your mother. An invite is two
6
+ * things written as a sentence: a link that opens a player, and a phone number
7
+ * with a code, which is the line where everyone watching talks to each other.
8
+ * The phone is not another way to hear the stream -- it is the 800 number
9
+ * beside a podcast. The show is on the screen; the call is the company.
8
10
  *
9
11
  * The sender is signed in, because sending is an action with a cost: a text
10
12
  * message is money and somebody's phone. The recipient signs in too, but only
@@ -32,7 +34,10 @@ export function isEmail(value) {
32
34
  export function inviteText(invite) {
33
35
  const lines = [`${invite.name} is streaming.`, "", `Watch: ${invite.link}`];
34
36
  if (invite.phone && invite.code) {
35
- lines.push("", `Or call ${invite.phone} and key ${invite.code} to listen.`);
37
+ // "to talk about it", not "to listen": the line is a room full of the
38
+ // other people watching, and telling somebody they will hear the stream
39
+ // down the phone is telling them something that is not true.
40
+ lines.push("", `To talk about it: call ${invite.phone} and key ${invite.code}.`);
36
41
  }
37
42
  return lines.join("\n");
38
43
  }
package/dist/main.js CHANGED
@@ -45,7 +45,7 @@ const HELP = `nixamp — it really whips the terminal's ass.
45
45
 
46
46
  nixamp [source] play it in the terminal
47
47
  nixamp serve [source] [options] play here, and hand out a browser remote
48
- nixamp daemon start|stop|status serve in the background, and let go of it
48
+ nixamp daemon start|restart|stop|status serve in the background, and let go of it
49
49
  nixamp attach put the player back in front of the daemon
50
50
  nixamp admin [--url U] [--key K] who is connected, and re-stream to them
51
51
  nixamp login [--with github] sign in to nixamp.com, in a browser or here
@@ -162,9 +162,13 @@ Signing out does not touch it: that is what it is for.
162
162
  daemon: `nixamp daemon — a nixamp that outlives the terminal that started it.
163
163
 
164
164
  nixamp daemon start [source] [serve options] start it, detached
165
+ nixamp daemon restart [source] [serve options] stop it and start it again
165
166
  nixamp daemon status where it is, and how long
166
167
  nixamp daemon stop stop it
167
168
 
169
+ Restart with no arguments replays the ones it was started with, certificate
170
+ and public URL included, so picking up a new version costs one command.
171
+
168
172
  It is \`nixamp serve\` with nobody holding its terminal, so it keeps playing and
169
173
  keeps serving its browser remote. One per user.
170
174
 
@@ -228,6 +232,18 @@ async function runDaemon(argv) {
228
232
  console.log(stopped ? "nixamp daemon stopped" : "nixamp: no daemon was running");
229
233
  return 0;
230
234
  }
235
+ if (action === "restart") {
236
+ try {
237
+ const state = await d.restart(rest, entry);
238
+ for (const line of d.daemonLines(state))
239
+ console.log(line);
240
+ return 0;
241
+ }
242
+ catch (error) {
243
+ console.error(error.message);
244
+ return 1;
245
+ }
246
+ }
231
247
  if (action === "status") {
232
248
  const { running, state } = d.status();
233
249
  if (!state) {
@@ -253,7 +269,7 @@ async function runDaemon(argv) {
253
269
  const { attach } = await import("./attach.js");
254
270
  return attach(rest);
255
271
  }
256
- console.error(`nixamp daemon: unknown action ${action}. Try start, stop, status or attach.`);
272
+ console.error(`nixamp daemon: unknown action ${action}. Try start, restart, stop, status or attach.`);
257
273
  return 64;
258
274
  }
259
275
  /**
@@ -605,7 +621,11 @@ export function view({ ui, theme, height }, state) {
605
621
  }
606
622
  if (import.meta.main) {
607
623
  main().catch((error) => {
608
- console.error(error);
624
+ // The same rule the installed launcher uses: a message we wrote is one the
625
+ // reader can act on, and printing a stack over it buries the sentence that
626
+ // says what to do.
627
+ const message = error instanceof Error ? error.message : String(error);
628
+ console.error(message.startsWith("nixamp:") ? message : error);
609
629
  process.exit(1);
610
630
  });
611
631
  }
@@ -134,15 +134,6 @@ export declare class PartyLine {
134
134
  add: (code: string, phone: string) => void;
135
135
  take: (code: string) => Promise<string[]>;
136
136
  }, waiting?: ReadonlyMap<string, ReadonlySet<string>>): void;
137
- /**
138
- * Legs listening to a stream, by its code.
139
- *
140
- * Separate from the rooms because a stream listener is not in a conference:
141
- * they are a leg with an MP3 playing into it. Nothing else was counting
142
- * them, so the directory had no way to say how many people were on the
143
- * phone for a broadcast.
144
- */
145
- private readonly streamLegs;
146
137
  private readonly key;
147
138
  private readonly fetch;
148
139
  private readonly now;
@@ -199,6 +190,14 @@ export declare class PartyLine {
199
190
  * room code still works: this line was a party line before it was a way into
200
191
  * a broadcast, and a code that means nothing to the directory should still
201
192
  * mean a room.
193
+ *
194
+ * Keying a stream's code puts you in a room with the other people watching
195
+ * it. It does not play the stream at you, which is what it used to do: this
196
+ * is the phone line beside a broadcast, the way a podcast has an 800 number
197
+ * -- the show is on your screen and the phone is where you talk about it.
198
+ * Playing the audio down the phone was both the worse half of the idea and
199
+ * the one that kept failing, because a share link answers a 302 and a cookie
200
+ * rather than an MP3.
202
201
  */
203
202
  private stream;
204
203
  /** Whether the caller took the reminder that was offered. */
@@ -220,7 +219,13 @@ export declare class PartyLine {
220
219
  /** Put a leg into a room, making the conference if it is the first one there. */
221
220
  private join;
222
221
  private enter;
223
- /** How many people are listening to a stream by phone. */
222
+ /**
223
+ * How many people are on the phone for a stream.
224
+ *
225
+ * The room's own count, now that a stream's code is a room like any other.
226
+ * It used to count legs with an MP3 playing into them, which is a thing that
227
+ * no longer happens.
228
+ */
224
229
  listenersOn(code: string): number;
225
230
  /** A leg that hung up or was dropped, wherever it was. */
226
231
  private release;
package/dist/partyline.js CHANGED
@@ -155,15 +155,6 @@ export class PartyLine {
155
155
  this.reminders.set(code, set);
156
156
  }
157
157
  }
158
- /**
159
- * Legs listening to a stream, by its code.
160
- *
161
- * Separate from the rooms because a stream listener is not in a conference:
162
- * they are a leg with an MP3 playing into it. Nothing else was counting
163
- * them, so the directory had no way to say how many people were on the
164
- * phone for a broadcast.
165
- */
166
- streamLegs = new Map();
167
158
  key;
168
159
  fetch;
169
160
  now;
@@ -318,6 +309,14 @@ export class PartyLine {
318
309
  * room code still works: this line was a party line before it was a way into
319
310
  * a broadcast, and a code that means nothing to the directory should still
320
311
  * mean a room.
312
+ *
313
+ * Keying a stream's code puts you in a room with the other people watching
314
+ * it. It does not play the stream at you, which is what it used to do: this
315
+ * is the phone line beside a broadcast, the way a podcast has an 800 number
316
+ * -- the show is on your screen and the phone is where you talk about it.
317
+ * Playing the audio down the phone was both the worse half of the idea and
318
+ * the one that kept failing, because a share link answers a 302 and a cookie
319
+ * rather than an MP3.
321
320
  */
322
321
  async stream(leg, code) {
323
322
  const streams = this.options.streams;
@@ -326,39 +325,12 @@ export class PartyLine {
326
325
  const live = streams.liveByCode(code);
327
326
  if (live !== undefined) {
328
327
  const what = live.nowPlaying ? ` of ${live.nowPlaying}` : "";
329
- // The share link is not playable. It answers 302 with a cookie and sends
330
- // a browser to the player page; Telnyx fetches once with no cookie jar
331
- // and gets a 401 in JSON. Playing it means a caller who is told "here it
332
- // is" and then hears nothing at all, which is how this was found. Say
333
- // what is true instead, and hang up rather than bill for silence.
334
- if (!live.audio) {
335
- await this.command(leg, "speak", {
336
- payload: `${live.name} is live right now${what}, but this stream cannot be played over the phone. ` +
337
- "You can listen to it at nixamp dot com slash directory. Goodbye.",
338
- voice: this.voice,
339
- });
340
- await this.command(leg, "hangup", {});
341
- this.options.onEvent?.(` ${code} is live but announced no audio address; nothing to play.`);
342
- return true;
343
- }
344
328
  await this.command(leg, "speak", {
345
- payload: `Welcome to ${live.name}'s live stream${what}. It started at ${pacificTime(live.startedAt)}. Here it is.`,
329
+ payload: `You're on the line for ${live.name}${what}. ` +
330
+ "Everyone here is watching it too. Say hello.",
346
331
  voice: this.voice,
347
332
  });
348
- // A nixamp stream is an MP3 over HTTP and Telnyx will play a URL into a
349
- // call, so listening by phone costs no audio handling here at all.
350
- const playing = await this.command(leg, "playback_start", {
351
- audio_url: live.audio,
352
- loop: "infinity",
353
- });
354
- // Counted only once the audio is actually going. A leg we failed to
355
- // start is not somebody listening, and the directory would be saying so.
356
- if (playing) {
357
- const legs = this.streamLegs.get(code) ?? new Set();
358
- legs.add(leg);
359
- this.streamLegs.set(code, legs);
360
- this.options.onEvent?.(` a caller is listening to ${code} (${legs.size} on the phone).`);
361
- }
333
+ await this.join(leg, code);
362
334
  return true;
363
335
  }
364
336
  const ended = streams.endedByCode(code);
@@ -490,16 +462,18 @@ export class PartyLine {
490
462
  room.callers = room.legs.size;
491
463
  this.options.onEvent?.(` a caller joined a room (${room.callers} on the line).`);
492
464
  }
493
- /** How many people are listening to a stream by phone. */
465
+ /**
466
+ * How many people are on the phone for a stream.
467
+ *
468
+ * The room's own count, now that a stream's code is a room like any other.
469
+ * It used to count legs with an MP3 playing into them, which is a thing that
470
+ * no longer happens.
471
+ */
494
472
  listenersOn(code) {
495
- return this.streamLegs.get(code)?.size ?? 0;
473
+ return this.rooms.get(code)?.callers ?? 0;
496
474
  }
497
475
  /** A leg that hung up or was dropped, wherever it was. */
498
476
  release(leg) {
499
- for (const [code, legs] of this.streamLegs) {
500
- if (legs.delete(leg) && legs.size === 0)
501
- this.streamLegs.delete(code);
502
- }
503
477
  const code = this.legRoom.get(leg);
504
478
  this.legRoom.delete(leg);
505
479
  if (code === undefined)
package/dist/server.d.ts CHANGED
@@ -134,6 +134,16 @@ export declare function safeJoin(rootDir: string, urlPath: string): string | nul
134
134
  */
135
135
  export type Loaded = Track & {
136
136
  group?: string;
137
+ /**
138
+ * Whether this has a picture, when the name could not say.
139
+ *
140
+ * A file on disk is named `film.mkv` and that is answer enough. A live
141
+ * stream is `http://host/tipoffsport/KEY/301`, which says nothing at all --
142
+ * so it was treated as audio, transcoded with `-vn`, and arrived as a
143
+ * football match somebody could only listen to. Asked of ffprobe once, when
144
+ * the source is added, rather than guessed from a URL that has no opinion.
145
+ */
146
+ picture?: boolean;
137
147
  };
138
148
  /** What the HTTP layer needs from a player. Tests hand it a fake. */
139
149
  export interface Engine {
@@ -150,6 +160,8 @@ export interface Engine {
150
160
  * this server somewhere else", which throws the library away on purpose.
151
161
  */
152
162
  replace(tracks: Track[], root: string): void;
163
+ /** The library, arriving after the server was already listening. */
164
+ fill(tracks: Track[], root: string): void;
153
165
  /**
154
166
  * Play something as well as everything here.
155
167
  *
@@ -181,6 +193,14 @@ export interface Engine {
181
193
  }
182
194
  export declare function toRemoteTracks(tracks: Loaded[]): RemoteTrack[];
183
195
  export declare function hasPicture(path: string): boolean;
196
+ /**
197
+ * Whether the name of a source tells us anything about what is inside it.
198
+ *
199
+ * A remote address with no extension -- an IPTV channel, a stream key, a
200
+ * redirect -- is the case where it does not, and the only way to find out is
201
+ * to look.
202
+ */
203
+ export declare function nameSaysNothing(path: string): boolean;
184
204
  /**
185
205
  * The headless player: the terminal app's engine without the terminal.
186
206
  * One ffmpeg decodes, ffplay makes the sound, and every sample is measured on
@@ -252,6 +272,21 @@ export declare class PlayerEngine implements Engine {
252
272
  */
253
273
  drop(group: string): number;
254
274
  groups(): string[];
275
+ /**
276
+ * The library, arriving after the server was already listening.
277
+ *
278
+ * Walking a directory is the slow part of starting -- eighty thousand files
279
+ * under a home directory takes far longer than the fifteen seconds
280
+ * `nixamp daemon start` waits for the server to say it is up, so starting a
281
+ * daemon with no source given looked exactly like hanging and then failed
282
+ * about a server that was working. The port opens first now and this puts
283
+ * the library in behind it.
284
+ *
285
+ * Unlike `replace` it stops nothing and clears no listeners: whoever
286
+ * connected in the first second is still connected, and simply sees the
287
+ * playlist appear.
288
+ */
289
+ fill(tracks: Loaded[], root: string): void;
255
290
  retag(tracks: Track[], root: string): void;
256
291
  }
257
292
  /** An engine with no library behind it, for the hosted PWA. */
@@ -263,6 +298,7 @@ export declare class EmptyEngine implements Engine {
263
298
  subscribe(listener: (snapshot: Snapshot) => void): () => void;
264
299
  trackPath(): undefined;
265
300
  replace(): void;
301
+ fill(): void;
266
302
  add(): number;
267
303
  drop(): number;
268
304
  groups(): string[];
@@ -321,6 +357,18 @@ export interface HandlerOptions {
321
357
  destinations: Destination[];
322
358
  settings: EncoderSettings;
323
359
  };
360
+ /**
361
+ * Where OBS should point, one entry per stream this server will accept.
362
+ *
363
+ * There is deliberately no single link. ffmpeg's RTMP listener serves one
364
+ * connection per process, so three people going live at once is three ports
365
+ * and three URLs -- and a panel offering one address for all of them would
366
+ * be offering an address that works exactly once.
367
+ */
368
+ publishUrls?: () => {
369
+ id: string;
370
+ url: string;
371
+ }[];
324
372
  /** Accounts, on the instance that keeps them. Only nixamp.com passes this. */
325
373
  accounts?: Accounts;
326
374
  /** Providers to sign in with, and the terminals waiting to be connected. */