@ziplayer/net 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +136 -2
  2. package/dist/NetNode.d.ts +124 -0
  3. package/dist/NetNode.js +593 -0
  4. package/dist/NetNode.js.map +1 -0
  5. package/dist/ZiNet.d.ts +165 -0
  6. package/dist/ZiNet.js +599 -0
  7. package/dist/ZiNet.js.map +1 -0
  8. package/dist/crypto/handshake.d.ts +84 -0
  9. package/dist/crypto/handshake.js +204 -0
  10. package/dist/crypto/handshake.js.map +1 -0
  11. package/dist/crypto/identity.d.ts +44 -0
  12. package/dist/crypto/identity.js +92 -0
  13. package/dist/crypto/identity.js.map +1 -0
  14. package/dist/crypto/session.d.ts +56 -0
  15. package/dist/crypto/session.js +148 -0
  16. package/dist/crypto/session.js.map +1 -0
  17. package/dist/debug.d.ts +56 -0
  18. package/dist/debug.js +51 -0
  19. package/dist/debug.js.map +1 -0
  20. package/dist/ext/NetExtension.d.ts +15 -0
  21. package/dist/ext/NetExtension.js +39 -0
  22. package/dist/ext/NetExtension.js.map +1 -0
  23. package/dist/index.d.ts +28 -0
  24. package/dist/index.js +52 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/protocol/frames.d.ts +22 -0
  27. package/dist/protocol/frames.js +45 -0
  28. package/dist/protocol/frames.js.map +1 -0
  29. package/dist/router.d.ts +38 -0
  30. package/dist/router.js +51 -0
  31. package/dist/router.js.map +1 -0
  32. package/dist/search.d.ts +72 -0
  33. package/dist/search.js +94 -0
  34. package/dist/search.js.map +1 -0
  35. package/dist/stream/StreamImporter.d.ts +37 -0
  36. package/dist/stream/StreamImporter.js +138 -0
  37. package/dist/stream/StreamImporter.js.map +1 -0
  38. package/dist/stream/StreamProvider.d.ts +49 -0
  39. package/dist/stream/StreamProvider.js +157 -0
  40. package/dist/stream/StreamProvider.js.map +1 -0
  41. package/dist/transport/MemoryTransport.d.ts +36 -0
  42. package/dist/transport/MemoryTransport.js +84 -0
  43. package/dist/transport/MemoryTransport.js.map +1 -0
  44. package/dist/transport/MqttTransport.d.ts +26 -0
  45. package/dist/transport/MqttTransport.js +104 -0
  46. package/dist/transport/MqttTransport.js.map +1 -0
  47. package/dist/transport/Transport.d.ts +21 -0
  48. package/dist/transport/Transport.js +18 -0
  49. package/dist/transport/Transport.js.map +1 -0
  50. package/dist/voice/Gateway.d.ts +16 -0
  51. package/dist/voice/Gateway.js +35 -0
  52. package/dist/voice/Gateway.js.map +1 -0
  53. package/dist/voice/RemoteVoice.d.ts +29 -0
  54. package/dist/voice/RemoteVoice.js +80 -0
  55. package/dist/voice/RemoteVoice.js.map +1 -0
  56. package/package.json +53 -5
@@ -0,0 +1,165 @@
1
+ import { PassThrough } from "node:stream";
2
+ import { NetNode, type NetNodeOptions } from "./NetNode";
3
+ import { NetExtension } from "./ext/NetExtension";
4
+ import { StreamImporter, type StreamImporterOptions } from "./stream/StreamImporter";
5
+ import { StreamProvider } from "./stream/StreamProvider";
6
+ import { RemoteVoiceHub } from "./voice/RemoteVoice";
7
+ import { type RoutePlan } from "./router";
8
+ import { type NetSearchOptions, type NetSearchResult, type ServeSearchOptions } from "./search";
9
+ import type { GatewayLike } from "./voice/Gateway";
10
+ export interface ZiNetOptions extends NetNodeOptions {
11
+ /** The local PlayerManager (needed to provide streams and to accept voice). */
12
+ manager?: any;
13
+ /** Required on a node that hands voice off (it owns the Discord gateway). */
14
+ gateway?: GatewayLike;
15
+ importer?: StreamImporterOptions;
16
+ /** Source (plugin) names this node can resolve. Defaults to the manager's registered plugin names. */
17
+ sources?: string[];
18
+ /** Extra / overriding query prefixes for `search()`: `{ ytm: "youtube" }` makes `ytm:lofi` search the youtube plugin. */
19
+ searchAliases?: Record<string, string>;
20
+ }
21
+ export interface DelegateVoiceOptions {
22
+ /** Channel object to reconnect locally if the hand-off fails or is reclaimed. Defaults to `gateway.resolveChannel`. */
23
+ channel?: any;
24
+ /**
25
+ * Where the executor gets audio: `"executor"` (default) resolves with its own plugins; `"owner"` pulls
26
+ * from this node, which must call `provideStreams()`. Tracks already marked with `markTrack` keep their owner.
27
+ */
28
+ streamFrom?: "executor" | "owner";
29
+ }
30
+ interface Delegation {
31
+ executor: string;
32
+ channelId: string;
33
+ channel: any;
34
+ streamFrom: "executor" | "owner";
35
+ stopRelay: () => void;
36
+ }
37
+ export declare function markTrack<T extends {
38
+ metadata?: Record<string, any>;
39
+ }>(track: T, ownerNodeId: string): T;
40
+ /**
41
+ * High level entry point: wires a {@link NetNode} to a PlayerManager.
42
+ *
43
+ * - Owner streamInfo: `provideStreams()`; consumers just play tracks marked with `markTrack(track, nodeId)`.
44
+ * - Owner connection: `player.connect()` as usual; `delegateVoice()` hands the voice session to another node.
45
+ */
46
+ export declare class ZiNet {
47
+ private readonly options;
48
+ readonly node: NetNode;
49
+ readonly importer: StreamImporter;
50
+ readonly hub: RemoteVoiceHub;
51
+ private provider?;
52
+ private readonly delegations;
53
+ private readonly executions;
54
+ private readonly manager;
55
+ private readonly gateway?;
56
+ private voiceAccepting;
57
+ private searchProvider?;
58
+ private readonly aliases;
59
+ private allowVoice?;
60
+ constructor(options: ZiNetOptions);
61
+ private readonly capsCache;
62
+ localSources(): string[];
63
+ peerCapabilities(peerId: string, maxAgeMs?: number): Promise<{
64
+ at: number;
65
+ sources: string[];
66
+ players: number;
67
+ search?: boolean;
68
+ }>;
69
+ /**
70
+ * Plans where each track should be resolved and, with `apply` (default), marks tracks with their owner node
71
+ * and moves or reclaims the voice when the plan calls for it.
72
+ *
73
+ * - `relay`: voice stays here; foreign tracks are pulled from the node that can resolve them.
74
+ * - `handoff`: voice moves to the node that can play most tracks; others are pulled from their owners.
75
+ */
76
+ routeTracks(player: any, tracks: any[], options?: {
77
+ handoffThreshold?: number;
78
+ apply?: boolean;
79
+ peers?: string[];
80
+ delegate?: DelegateVoiceOptions;
81
+ }): Promise<RoutePlan & {
82
+ applied: boolean;
83
+ error?: Error;
84
+ }>;
85
+ get nodeId(): string;
86
+ start(): Promise<void>;
87
+ stop(): Promise<void>;
88
+ /** Extension class to pass in `manager.create(guild, { extensions: [net.extensionClass()] })`. */
89
+ extensionClass(): new (player?: any) => NetExtension;
90
+ /**
91
+ * Serve search results from this node's plugins to trusted peers that hold the `provide-search` role
92
+ * (the default `*` role includes it). Opt-in, like `provideStreams()`.
93
+ */
94
+ provideSearch(options?: ServeSearchOptions): void;
95
+ /**
96
+ * Searches across the cluster. Tracks found by another node come back already marked with that node as owner
97
+ * (`track.metadata.net.owner`), so `player.play(track)` pulls the audio from it.
98
+ *
99
+ * `yt:lofi`, `sc:…`, `sp:…`, `tts:…` target the node that has that plugin; anything else (a plain query or a URL)
100
+ * is tried on this node first and, if nothing is found, on every node that serves search.
101
+ */
102
+ search(text: string, options?: NetSearchOptions): Promise<NetSearchResult>;
103
+ /** Searches on one specific node (it must run `provideSearch()` and trust this node). */
104
+ searchOn(peerId: string, text: string, options?: NetSearchOptions): Promise<NetSearchResult>;
105
+ private searchCandidates;
106
+ /** Runs the query on this node's plugins. With a `plugins` filter it goes straight to the shared plugin manager. */
107
+ private searchLocal;
108
+ private onSearch;
109
+ /** Serve streams resolved by this node's plugins to trusted peers that hold the `provide-stream` role. */
110
+ provideStreams(options?: {
111
+ allow?: (track: any, peerId: string) => boolean | Promise<boolean>;
112
+ chunkBytes?: number;
113
+ }): StreamProvider;
114
+ /** Open a remote stream as a ziplayer `StreamInfo`. */
115
+ openRemoteStream(ownerId: string, track: any, position?: number, signal?: AbortSignal): Promise<{
116
+ stream: import("stream").Readable;
117
+ track: any;
118
+ streamType: string;
119
+ type: string;
120
+ recreate: (positionMs: number) => Promise<import("stream").Readable>;
121
+ cacheable: boolean;
122
+ metadata: {
123
+ net: {
124
+ owner: string;
125
+ };
126
+ };
127
+ }>;
128
+ delegationFor(guildId: string): Delegation | undefined;
129
+ /**
130
+ * Hands the player's Discord voice session to `executorId`. This node keeps the gateway and the queue; the
131
+ * executor joins voice (through a relay adapter) and plays. Call it while nothing is playing.
132
+ */
133
+ delegateVoice(player: any, executorId: string, options?: DelegateVoiceOptions): Promise<void>;
134
+ /** Takes the voice session back and reconnects locally. */
135
+ reclaimVoice(player: any, options?: {
136
+ channel?: any;
137
+ }): Promise<void>;
138
+ private dropDelegation;
139
+ /** Remote playback handle for a delegated player (same contract Lavalink uses). */
140
+ buildRemoteStream(player: any, track: any): {
141
+ stream: PassThrough;
142
+ track: any;
143
+ streamType: string;
144
+ type: string;
145
+ remote: boolean;
146
+ handle: {
147
+ play: () => Promise<undefined>;
148
+ pause: () => Promise<undefined>;
149
+ resume: () => Promise<undefined>;
150
+ stop: () => Promise<void>;
151
+ seek: (position: number) => Promise<undefined>;
152
+ setVolume: (volume: number) => Promise<undefined>;
153
+ destroy: () => Promise<undefined>;
154
+ };
155
+ } | null;
156
+ private onExecutorEvent;
157
+ private onPeerGone;
158
+ /** Accept voice hand-offs from trusted owners that hold the `delegate-voice` role. */
159
+ acceptVoice(options?: {
160
+ allow?: (guildId: string, from: string) => boolean | Promise<boolean>;
161
+ }): void;
162
+ private onDelegate;
163
+ private endExecution;
164
+ }
165
+ export {};