@open-orpheus/plugin-api 0.0.0-stage → 0.21.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/LICENSE +7 -0
- package/README.md +191 -2
- package/dist/client/index.d.ts +37 -0
- package/dist/client/index.js +53 -0
- package/dist/client/index.js.map +1 -0
- package/dist/configuration/host/src/shared/plugin/configuration/index.d.ts +21 -0
- package/dist/configuration/index.d.ts +5 -0
- package/dist/host/_native/open-orpheus__database.d.ts +50 -0
- package/dist/host/_native/open-orpheus__window.d.ts +284 -0
- package/dist/host/src/constants.d.ts +6 -0
- package/dist/host/src/main/afp.d.ts +1 -0
- package/dist/host/src/main/arguments.d.ts +4 -0
- package/dist/host/src/main/assets.d.ts +2 -0
- package/dist/host/src/main/audio/ChunkTracker.d.ts +23 -0
- package/dist/host/src/main/audio/DownloadScheduler.d.ts +53 -0
- package/dist/host/src/main/audio/MediaEngine.d.ts +47 -0
- package/dist/host/src/main/audio/OnlineStreamer.d.ts +66 -0
- package/dist/host/src/main/audio/StorageManager.d.ts +18 -0
- package/dist/host/src/main/audio.d.ts +6 -0
- package/dist/host/src/main/av3a/Av3aEngine.d.ts +24 -0
- package/dist/host/src/main/av3a/Av3aM4aSession.d.ts +101 -0
- package/dist/host/src/main/av3a/Av3aPlaybackProcess.d.ts +52 -0
- package/dist/host/src/main/av3a/detect.d.ts +6 -0
- package/dist/host/src/main/av3a/sources.d.ts +13 -0
- package/dist/host/src/main/av3a/types.d.ts +54 -0
- package/dist/host/src/main/bridge/ipc-main-bridge.d.ts +24 -0
- package/dist/host/src/main/bridge/modules/inputRegion.d.ts +1 -0
- package/dist/host/src/main/bridge/modules/lyrics.d.ts +1 -0
- package/dist/host/src/main/bridge/modules/settings.d.ts +1 -0
- package/dist/host/src/main/bridge/register.d.ts +9 -0
- package/dist/host/src/main/bridge/window.d.ts +7 -0
- package/dist/host/src/main/cache/HttpCacheStorage.d.ts +10 -0
- package/dist/host/src/main/cache/LyricCahceManager.d.ts +21 -0
- package/dist/host/src/main/cache/PlayCacheManager.d.ts +72 -0
- package/dist/host/src/main/cache.d.ts +7 -0
- package/dist/host/src/main/calls/app.d.ts +1 -0
- package/dist/host/src/main/calls/audioeffect.d.ts +1 -0
- package/dist/host/src/main/calls/browser.d.ts +1 -0
- package/dist/host/src/main/calls/desktop.d.ts +2 -0
- package/dist/host/src/main/calls/desktoppet.d.ts +1 -0
- package/dist/host/src/main/calls/download.d.ts +1 -0
- package/dist/host/src/main/calls/index.d.ts +16 -0
- package/dist/host/src/main/calls/musiclibrary.d.ts +1 -0
- package/dist/host/src/main/calls/network.d.ts +1 -0
- package/dist/host/src/main/calls/os.d.ts +1 -0
- package/dist/host/src/main/calls/player.d.ts +22 -0
- package/dist/host/src/main/calls/process.d.ts +1 -0
- package/dist/host/src/main/calls/rtc.d.ts +1 -0
- package/dist/host/src/main/calls/storage.d.ts +1 -0
- package/dist/host/src/main/calls/trayicon.d.ts +1 -0
- package/dist/host/src/main/calls/update.d.ts +1 -0
- package/dist/host/src/main/calls/winhelper.d.ts +1 -0
- package/dist/host/src/main/calls.d.ts +5 -0
- package/dist/host/src/main/channel.d.ts +1 -0
- package/dist/host/src/main/cookie.d.ts +13 -0
- package/dist/host/src/main/crypto.d.ts +46 -0
- package/dist/host/src/main/database/KeyvSqliteDriver.d.ts +6 -0
- package/dist/host/src/main/database.d.ts +5 -0
- package/dist/host/src/main/dawn.d.ts +31 -0
- package/dist/host/src/main/device.d.ts +3 -0
- package/dist/host/src/main/download.d.ts +40 -0
- package/dist/host/src/main/error.d.ts +1 -0
- package/dist/host/src/main/folders.d.ts +18 -0
- package/dist/host/src/main/fonts.d.ts +1 -0
- package/dist/host/src/main/gui.d.ts +4 -0
- package/dist/host/src/main/id3.d.ts +42 -0
- package/dist/host/src/main/lifecycle.d.ts +127 -0
- package/dist/host/src/main/logger.d.ts +12 -0
- package/dist/host/src/main/lyrics/DbusLyricsService.d.ts +115 -0
- package/dist/host/src/main/lyrics/LyricsDispatcher.d.ts +26 -0
- package/dist/host/src/main/lyrics/dbus.d.ts +16 -0
- package/dist/host/src/main/lyrics/parse.d.ts +21 -0
- package/dist/host/src/main/lyrics.d.ts +2 -0
- package/dist/host/src/main/mediaSession.d.ts +42 -0
- package/dist/host/src/main/menu/AppMenu.d.ts +35 -0
- package/dist/host/src/main/menu/anchor.d.ts +13 -0
- package/dist/host/src/main/menu/backend/DesktopWindowBackend.d.ts +30 -0
- package/dist/host/src/main/menu/backend/MenuBackend.d.ts +28 -0
- package/dist/host/src/main/menu/backend/WaylandLayerShellBackend.d.ts +35 -0
- package/dist/host/src/main/menu/backend/WaylandOverlayBackend.d.ts +15 -0
- package/dist/host/src/main/menu/backend/WaylandPopupBackend.d.ts +31 -0
- package/dist/host/src/main/menu/constants.d.ts +14 -0
- package/dist/host/src/main/menu/index.d.ts +2 -0
- package/dist/host/src/main/menu/native-popup.d.ts +16 -0
- package/dist/host/src/main/menu/patch.d.ts +3 -0
- package/dist/host/src/main/menu/skin.d.ts +3 -0
- package/dist/host/src/main/menu/surface/BaseWindowMenuSurface.d.ts +81 -0
- package/dist/host/src/main/menu/surface/CaptureLayerSurface.d.ts +22 -0
- package/dist/host/src/main/menu/surface/MenuSurface.d.ts +29 -0
- package/dist/host/src/main/menu/surface/MenuSurfacePath.d.ts +29 -0
- package/dist/host/src/main/menu/surface/SurfacePool.d.ts +15 -0
- package/dist/host/src/main/menu/workaround.d.ts +12 -0
- package/dist/host/src/main/ncae.d.ts +8 -0
- package/dist/host/src/main/network/handler.d.ts +3 -0
- package/dist/host/src/main/network/interceptor.d.ts +2 -0
- package/dist/host/src/main/network/interceptors/anonymous.d.ts +2 -0
- package/dist/host/src/main/network/pipeline.d.ts +8 -0
- package/dist/host/src/main/network/types.d.ts +70 -0
- package/dist/host/src/main/orpheus.d.ts +10 -0
- package/dist/host/src/main/pack.d.ts +27 -0
- package/dist/host/src/main/packs/Pack.d.ts +12 -0
- package/dist/host/src/main/packs/SkinPack.d.ts +6 -0
- package/dist/host/src/main/packs/WebPack.d.ts +6 -0
- package/dist/host/src/main/playback/PlaybackController.d.ts +57 -0
- package/dist/host/src/main/playback/PlayerCommandRouter.d.ts +85 -0
- package/dist/host/src/main/playback/adapters/MediaSessionAdapter.d.ts +61 -0
- package/dist/host/src/main/playback/adapters/MprisAdapter.d.ts +48 -0
- package/dist/host/src/main/playback/adapters/NowPlayingAdapter.d.ts +23 -0
- package/dist/host/src/main/playback/adapters/SmtcAdapter.d.ts +23 -0
- package/dist/host/src/main/playback/artwork.d.ts +47 -0
- package/dist/host/src/main/playback/modes.d.ts +8 -0
- package/dist/host/src/main/playback/types.d.ts +59 -0
- package/dist/host/src/main/plugin/assets.d.ts +8 -0
- package/dist/host/src/main/plugin/catalog.d.ts +42 -0
- package/dist/host/src/main/plugin/discover.d.ts +33 -0
- package/dist/host/src/main/plugin/index.d.ts +15 -0
- package/dist/host/src/main/plugin/loader.d.ts +90 -0
- package/dist/host/src/main/plugin/manager.d.ts +61 -0
- package/dist/host/src/main/plugin/metadata.d.ts +34 -0
- package/dist/host/src/main/plugin/state.d.ts +27 -0
- package/dist/host/src/main/plugin/tree.d.ts +13 -0
- package/dist/host/src/main/protocol.d.ts +4 -0
- package/dist/host/src/main/request.d.ts +16 -0
- package/dist/host/src/main/settings.d.ts +21 -0
- package/dist/host/src/main/shortcuts.d.ts +10 -0
- package/dist/host/src/main/shutdown.d.ts +50 -0
- package/dist/host/src/main/skin/color.d.ts +2 -0
- package/dist/host/src/main/skin/dui.d.ts +15 -0
- package/dist/host/src/main/tray.d.ts +8 -0
- package/dist/host/src/main/update.d.ts +2 -0
- package/dist/host/src/main/util/color.d.ts +7 -0
- package/dist/host/src/main/util/display.d.ts +3 -0
- package/dist/host/src/main/util/env.d.ts +1 -0
- package/dist/host/src/main/util/fs.d.ts +21 -0
- package/dist/host/src/main/util/image.d.ts +1 -0
- package/dist/host/src/main/util/musicFile.d.ts +1 -0
- package/dist/host/src/main/util/musicPicture.d.ts +2 -0
- package/dist/host/src/main/util/path.d.ts +2 -0
- package/dist/host/src/main/util/send.d.ts +13 -0
- package/dist/host/src/main/util/url.d.ts +19 -0
- package/dist/host/src/main/util/window.d.ts +2 -0
- package/dist/host/src/main/window.d.ts +316 -0
- package/dist/host/src/main/windows/color-picker.d.ts +3 -0
- package/dist/host/src/main/windows/desktop-lyrics.d.ts +12 -0
- package/dist/host/src/main/windows/desktop-pet.d.ts +8 -0
- package/dist/host/src/main/windows/main.d.ts +6 -0
- package/dist/host/src/main/windows/manage.d.ts +2 -0
- package/dist/host/src/main/windows/mini-player.d.ts +16 -0
- package/dist/host/src/main/windows/music-desktop.d.ts +13 -0
- package/dist/host/src/main/windows/package-download.d.ts +2 -0
- package/dist/host/src/main/windows/plugin-manager-events.d.ts +7 -0
- package/dist/host/src/main/windows/plugin-manager.d.ts +5 -0
- package/dist/host/src/main/xeapi.d.ts +48 -0
- package/dist/host/src/preload/AudioEffectManager.d.ts +124 -0
- package/dist/host/src/preload/PlaybackBackend.d.ts +34 -0
- package/dist/host/src/preload/Player.d.ts +229 -0
- package/dist/host/src/preload/av3a/Av3aPcmPlayer.d.ts +84 -0
- package/dist/host/src/preload/av3a/bridge.d.ts +21 -0
- package/dist/host/src/preload/av3a/channel.d.ts +40 -0
- package/dist/host/src/preload/av3a/detect.d.ts +6 -0
- package/dist/host/src/preload/backends/Av3aPlaybackBackend.d.ts +32 -0
- package/dist/host/src/preload/backends/MediaPlaybackBackend.d.ts +25 -0
- package/dist/host/src/shared/CallDispatcher.d.ts +12 -0
- package/dist/host/src/shared/bridge/constants.d.ts +2 -0
- package/dist/host/src/shared/bridge/endpoint.d.ts +29 -0
- package/dist/host/src/shared/bridge/hub.d.ts +136 -0
- package/dist/host/src/shared/bridge/protocol.d.ts +91 -0
- package/dist/host/src/shared/bridge/realm.d.ts +14 -0
- package/dist/host/src/shared/bridge/routes.d.ts +37 -0
- package/dist/host/src/shared/contracts/av3a-api.d.ts +50 -0
- package/dist/host/src/shared/contracts/av3a-process.d.ts +56 -0
- package/dist/host/src/shared/contracts/color-picker-api.d.ts +17 -0
- package/dist/host/src/shared/contracts/desktop-lyrics-api.d.ts +22 -0
- package/dist/host/src/shared/contracts/input-region-api.d.ts +5 -0
- package/dist/host/src/shared/contracts/lyrics-api.d.ts +11 -0
- package/dist/host/src/shared/contracts/manage-api.d.ts +31 -0
- package/dist/host/src/shared/contracts/menu-surface-api.d.ts +35 -0
- package/dist/host/src/shared/contracts/mini-player-api.d.ts +19 -0
- package/dist/host/src/shared/contracts/plugin-manager-api.d.ts +223 -0
- package/dist/host/src/shared/contracts/settings-api.d.ts +15 -0
- package/dist/host/src/shared/playbackMode.d.ts +2 -0
- package/dist/host/src/shared/plugin/cache-bust.d.ts +8 -0
- package/dist/host/src/shared/plugin/lifecycle.d.ts +217 -0
- package/dist/host/src/shared/plugin/realms/main/index.d.ts +18 -0
- package/dist/host/src/shared/plugin/registry.d.ts +69 -0
- package/dist/host/src/shared/plugin/runtime-state.d.ts +4 -0
- package/dist/host/src/shared/settings/defaults.d.ts +35 -0
- package/dist/host/src/shared/settings/index.d.ts +3 -0
- package/dist/host/src/shared/settings/keys.d.ts +21 -0
- package/dist/host/src/shared/settings/values.d.ts +13 -0
- package/dist/host/src/shared/types/desktop-lyrics.d.ts +61 -0
- package/dist/host/src/shared/types/dui.d.ts +37 -0
- package/dist/host/src/shared/types/input-region.d.ts +6 -0
- package/dist/host/src/shared/types/lyrics.d.ts +15 -0
- package/dist/host/src/shared/types/manage.d.ts +14 -0
- package/dist/host/src/shared/types/menu-surface.d.ts +43 -0
- package/dist/host/src/shared/types/menu.d.ts +29 -0
- package/dist/host/src/shared/types/mini-player.d.ts +97 -0
- package/dist/host/src/shared/types/ncae.d.ts +29 -0
- package/dist/host/src/shared/types/package-download.d.ts +14 -0
- package/dist/host/src/shared/types/playback-mode.d.ts +3 -0
- package/dist/host/src/shared/types/settings.d.ts +9 -0
- package/dist/host/src/shared/types/update.d.ts +6 -0
- package/dist/host/src/shared/util.d.ts +22 -0
- package/dist/index.d.ts +7 -0
- package/dist/plugin-manager/host/src/preload/logger.d.ts +10 -0
- package/dist/plugin-manager/host/src/preload/util.d.ts +1 -0
- package/dist/plugin-manager/host/src/shared/bridge/constants.d.ts +2 -0
- package/dist/plugin-manager/host/src/shared/bridge/endpoint.d.ts +29 -0
- package/dist/plugin-manager/host/src/shared/bridge/hub.d.ts +136 -0
- package/dist/plugin-manager/host/src/shared/bridge/protocol.d.ts +91 -0
- package/dist/plugin-manager/host/src/shared/bridge/routes.d.ts +37 -0
- package/dist/plugin-manager/host/src/shared/contracts/plugin-manager-api.d.ts +223 -0
- package/dist/plugin-manager/host/src/shared/plugin/lifecycle.d.ts +217 -0
- package/dist/plugin-manager/host/src/shared/plugin/realms/common/index.d.ts +34 -0
- package/dist/plugin-manager/host/src/shared/plugin/realms/plugin-manager/index.d.ts +11 -0
- package/dist/plugin-manager/host/src/shared/plugin/registry.d.ts +69 -0
- package/dist/plugin-manager/host/src/shared/util.d.ts +22 -0
- package/dist/plugin-manager/index.d.ts +7 -0
- package/dist/plugin-manager/registry-map.d.ts +16 -0
- package/dist/preload/host/src/constants.d.ts +6 -0
- package/dist/preload/host/src/main/network/types.d.ts +70 -0
- package/dist/preload/host/src/preload/AudioEffectManager.d.ts +124 -0
- package/dist/preload/host/src/preload/MusicRecognizer.d.ts +25 -0
- package/dist/preload/host/src/preload/PlaybackBackend.d.ts +34 -0
- package/dist/preload/host/src/preload/Player.d.ts +229 -0
- package/dist/preload/host/src/preload/YunxinIM.d.ts +15 -0
- package/dist/preload/host/src/preload/audioplayer.d.ts +4 -0
- package/dist/preload/host/src/preload/av3a/Av3aPcmPlayer.d.ts +84 -0
- package/dist/preload/host/src/preload/av3a/bridge.d.ts +21 -0
- package/dist/preload/host/src/preload/av3a/channel.d.ts +40 -0
- package/dist/preload/host/src/preload/av3a/detect.d.ts +6 -0
- package/dist/preload/host/src/preload/backends/Av3aPlaybackBackend.d.ts +32 -0
- package/dist/preload/host/src/preload/backends/MediaPlaybackBackend.d.ts +25 -0
- package/dist/preload/host/src/preload/calls/app.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/audioeffect.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/audioplayer.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/im.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/index.d.ts +6 -0
- package/dist/preload/host/src/preload/calls/network.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/nimsys.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/os.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/player.d.ts +1 -0
- package/dist/preload/host/src/preload/calls/update.d.ts +1 -0
- package/dist/preload/host/src/preload/calls.d.ts +4 -0
- package/dist/preload/host/src/preload/channel.d.ts +1 -0
- package/dist/preload/host/src/preload/logger.d.ts +10 -0
- package/dist/preload/host/src/preload/playbackMode.d.ts +13 -0
- package/dist/preload/host/src/preload/util.d.ts +1 -0
- package/dist/preload/host/src/shared/CallDispatcher.d.ts +12 -0
- package/dist/preload/host/src/shared/bridge/endpoint.d.ts +29 -0
- package/dist/preload/host/src/shared/bridge/hub.d.ts +136 -0
- package/dist/preload/host/src/shared/bridge/protocol.d.ts +91 -0
- package/dist/preload/host/src/shared/bridge/routes.d.ts +37 -0
- package/dist/preload/host/src/shared/contracts/av3a-api.d.ts +50 -0
- package/dist/preload/host/src/shared/contracts/av3a-process.d.ts +56 -0
- package/dist/preload/host/src/shared/contracts/plugin-manager-api.d.ts +223 -0
- package/dist/preload/host/src/shared/playbackMode.d.ts +2 -0
- package/dist/preload/host/src/shared/plugin/lifecycle.d.ts +217 -0
- package/dist/preload/host/src/shared/plugin/realms/common/index.d.ts +34 -0
- package/dist/preload/host/src/shared/plugin/realms/preload/index.d.ts +11 -0
- package/dist/preload/host/src/shared/plugin/registry.d.ts +69 -0
- package/dist/preload/host/src/shared/types/ncae.d.ts +29 -0
- package/dist/preload/host/src/shared/types/playback-mode.d.ts +3 -0
- package/dist/preload/host/src/shared/util.d.ts +22 -0
- package/dist/preload/index.d.ts +7 -0
- package/dist/preload/registry-map.d.ts +43 -0
- package/dist/registry-map.d.ts +164 -0
- package/package.json +73 -3
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import Emittery from "emittery";
|
|
2
|
+
import AudioEffectManager from "./AudioEffectManager.js";
|
|
3
|
+
export declare const AudioPlayerState: {
|
|
4
|
+
readonly Null: 0;
|
|
5
|
+
readonly Playing: 1;
|
|
6
|
+
readonly Paused: 2;
|
|
7
|
+
readonly Error: 3;
|
|
8
|
+
readonly [x: number]: string;
|
|
9
|
+
};
|
|
10
|
+
export type AudioPlayerState = 0 | 1 | 2 | 3;
|
|
11
|
+
export declare namespace AudioPlayerState {
|
|
12
|
+
type Null = 0;
|
|
13
|
+
type Playing = 1;
|
|
14
|
+
type Paused = 2;
|
|
15
|
+
type Error = 3;
|
|
16
|
+
}
|
|
17
|
+
export type SongInfo = {
|
|
18
|
+
playId: string;
|
|
19
|
+
songName: string;
|
|
20
|
+
artistName: string;
|
|
21
|
+
albumId: string;
|
|
22
|
+
albumName: string;
|
|
23
|
+
songType: string;
|
|
24
|
+
artworkUrl: string;
|
|
25
|
+
cover: string;
|
|
26
|
+
totalTime: number;
|
|
27
|
+
liked: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type LyricContent = {
|
|
30
|
+
krc: string;
|
|
31
|
+
lrc: string;
|
|
32
|
+
romalrc: string;
|
|
33
|
+
tlrc: string;
|
|
34
|
+
yrc: string;
|
|
35
|
+
};
|
|
36
|
+
export type PlaylistItem = {
|
|
37
|
+
id: string;
|
|
38
|
+
from: string;
|
|
39
|
+
title: string;
|
|
40
|
+
track_id: string;
|
|
41
|
+
program: unknown | null;
|
|
42
|
+
mv: string;
|
|
43
|
+
album: string;
|
|
44
|
+
artist: string;
|
|
45
|
+
alias: string;
|
|
46
|
+
cloud: number;
|
|
47
|
+
};
|
|
48
|
+
export type Playlist = {
|
|
49
|
+
items: PlaylistItem[];
|
|
50
|
+
currentPlay: string;
|
|
51
|
+
};
|
|
52
|
+
export type AudioPlayInfo = {
|
|
53
|
+
playId: string;
|
|
54
|
+
aiprocessorRatio: number;
|
|
55
|
+
destLevel: string;
|
|
56
|
+
songId: string;
|
|
57
|
+
songQuality: "standard" | "exhigh" | "hires" | "jyeffect" | "vivid" | "sky" | "jymaster" | string;
|
|
58
|
+
} & ({
|
|
59
|
+
type: 0;
|
|
60
|
+
bitrate: "exhigh" | "hires" | string;
|
|
61
|
+
path: string;
|
|
62
|
+
playbrt: number;
|
|
63
|
+
} | {
|
|
64
|
+
type: 4;
|
|
65
|
+
songId: string;
|
|
66
|
+
audioFormat: "m4a" | "flac" | "av3a" | string;
|
|
67
|
+
audioType: "track" | string;
|
|
68
|
+
bitrate: number;
|
|
69
|
+
br: string;
|
|
70
|
+
expireTime: number;
|
|
71
|
+
extHeader: string;
|
|
72
|
+
fileSize: number;
|
|
73
|
+
format: unknown;
|
|
74
|
+
freeTrialInfo: unknown | null;
|
|
75
|
+
freeTrialPrivilege: {
|
|
76
|
+
resConsumable: boolean;
|
|
77
|
+
userConsumable: boolean;
|
|
78
|
+
listenType: unknown | null;
|
|
79
|
+
playReason: unknown | null;
|
|
80
|
+
cannotListenReason: unknown | null;
|
|
81
|
+
freeLimitTagType: unknown | null;
|
|
82
|
+
};
|
|
83
|
+
level: string;
|
|
84
|
+
md5: string;
|
|
85
|
+
playInfoStr: string;
|
|
86
|
+
podcastCtrp: unknown | null;
|
|
87
|
+
rightSource: number;
|
|
88
|
+
songDuration: string;
|
|
89
|
+
musicurl: string;
|
|
90
|
+
});
|
|
91
|
+
export type PlayerEvents = {
|
|
92
|
+
volumechange: number;
|
|
93
|
+
audiodata: {
|
|
94
|
+
data: ArrayBuffer;
|
|
95
|
+
pts: number;
|
|
96
|
+
};
|
|
97
|
+
lyricstyleupdate: {
|
|
98
|
+
key: string | symbol;
|
|
99
|
+
value: unknown;
|
|
100
|
+
};
|
|
101
|
+
playinfoupdate: AudioPlayInfo;
|
|
102
|
+
load: {
|
|
103
|
+
id: string;
|
|
104
|
+
};
|
|
105
|
+
play: undefined;
|
|
106
|
+
playing: undefined;
|
|
107
|
+
pause: undefined;
|
|
108
|
+
ended: undefined;
|
|
109
|
+
/** Decode error (Error, AV3A) or a media-element error event. */
|
|
110
|
+
error: Error | Event;
|
|
111
|
+
stalled: undefined;
|
|
112
|
+
seeking: undefined;
|
|
113
|
+
seeked: undefined;
|
|
114
|
+
timeupdate: undefined;
|
|
115
|
+
durationchange: undefined;
|
|
116
|
+
ratechange: undefined;
|
|
117
|
+
};
|
|
118
|
+
export default class Player extends Emittery<PlayerEvents> {
|
|
119
|
+
private _audioCtx;
|
|
120
|
+
private _audioEffectManager;
|
|
121
|
+
private _honeyPotPromise;
|
|
122
|
+
private _media;
|
|
123
|
+
private _av3a;
|
|
124
|
+
private _backend;
|
|
125
|
+
private _playInfo;
|
|
126
|
+
/**
|
|
127
|
+
* The user's desired playing state: the last explicit transport command
|
|
128
|
+
* (`play`/`pause`/`stop`). Device-change recovery reads it to decide whether
|
|
129
|
+
* an interruption should be undone.
|
|
130
|
+
*
|
|
131
|
+
* Only a transport command writes it, and only before that command awaits.
|
|
132
|
+
* The backend pause a sink change causes is an interruption, not intent, so
|
|
133
|
+
* deriving intent from `paused` mid-switch is what let a second switch erase
|
|
134
|
+
* the intent the first one was going to restore.
|
|
135
|
+
*
|
|
136
|
+
* `_intentSeq` bumps with every command, so a caller that had to await can
|
|
137
|
+
* tell that a newer command took over while it waited.
|
|
138
|
+
*/
|
|
139
|
+
private _desiredPlayingState;
|
|
140
|
+
private _intentSeq;
|
|
141
|
+
/**
|
|
142
|
+
* Sink switches currently awaiting `setSinkId`. Overlapping switches observe
|
|
143
|
+
* the same transient pause, so only the last one to settle restores playback
|
|
144
|
+
* (an earlier one would resume in the middle of a newer device change).
|
|
145
|
+
*/
|
|
146
|
+
private _sinkSwitchesInFlight;
|
|
147
|
+
private _volume;
|
|
148
|
+
/**
|
|
149
|
+
* Monotonic sequence for `load` requests; only the newest request may win.
|
|
150
|
+
* Sniffing (local format detection) and engine disposal are async, so an
|
|
151
|
+
* older request could otherwise resume after a newer one finished and
|
|
152
|
+
* overwrite it (stale load replacing the freshly chosen song). Each `load`
|
|
153
|
+
* claims a sequence at entry and drops itself once stale, checked at every
|
|
154
|
+
* await boundary before it mutates state or notifies main.
|
|
155
|
+
*/
|
|
156
|
+
private loadRequestSeq;
|
|
157
|
+
get audioContext(): AudioContext;
|
|
158
|
+
get currentTime(): number;
|
|
159
|
+
set currentTime(value: number);
|
|
160
|
+
get duration(): number;
|
|
161
|
+
get paused(): boolean;
|
|
162
|
+
get ended(): boolean;
|
|
163
|
+
get playbackRate(): number;
|
|
164
|
+
set playbackRate(value: number);
|
|
165
|
+
get isAv3aActive(): boolean;
|
|
166
|
+
get gainNode(): GainNode;
|
|
167
|
+
get currentId(): string;
|
|
168
|
+
get currentPlayInfo(): AudioPlayInfo | null;
|
|
169
|
+
get volume(): number;
|
|
170
|
+
set volume(value: number);
|
|
171
|
+
get replayGain(): GainNode;
|
|
172
|
+
/**
|
|
173
|
+
* The audio effect manager of the player.
|
|
174
|
+
*
|
|
175
|
+
* Note that its input is currently being used as replay gain, and
|
|
176
|
+
* its output is currently being used as volume gain.
|
|
177
|
+
*/
|
|
178
|
+
get audioEffectManager(): AudioEffectManager;
|
|
179
|
+
constructor();
|
|
180
|
+
private ensureAudioContextState;
|
|
181
|
+
/**
|
|
182
|
+
* Record a transport command as the user's intent and return that intent's
|
|
183
|
+
* epoch. A caller that must await before acting compares the epoch
|
|
184
|
+
* afterwards: a different value means a newer command owns playback, so the
|
|
185
|
+
* caller must not force its now-stale intent onto the backend.
|
|
186
|
+
*/
|
|
187
|
+
private claimPlaybackIntent;
|
|
188
|
+
/** Whether no transport command has changed the intent since `epoch`. */
|
|
189
|
+
private isIntentCurrent;
|
|
190
|
+
/**
|
|
191
|
+
* Whether `playInfo` should play through the AV3A decode backend. URL av3a
|
|
192
|
+
* is signalled by `audioFormat`; a local file's codec is not part of the
|
|
193
|
+
* play info, so it is sniffed (in main, which owns `fs`).
|
|
194
|
+
*/
|
|
195
|
+
private resolveAv3a;
|
|
196
|
+
/**
|
|
197
|
+
* Switch the output device.
|
|
198
|
+
*
|
|
199
|
+
* The switch can transiently suspend the audio context, and `statechange`
|
|
200
|
+
* turns a suspended context into a backend pause, so a device change can stop
|
|
201
|
+
* playback without the user asking. Undo that here, without ever overriding a
|
|
202
|
+
* transport command issued while the switch was in flight.
|
|
203
|
+
*/
|
|
204
|
+
setSinkId(sinkId: string): Promise<void>;
|
|
205
|
+
load(playInfo: AudioPlayInfo): Promise<void>;
|
|
206
|
+
play(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Claim the playback intent, wait for the audio context, then start the
|
|
209
|
+
* backend.
|
|
210
|
+
*
|
|
211
|
+
* The claim happens before the wait, so a pause/stop/play issued meanwhile
|
|
212
|
+
* wins: this call drops out instead of starting a stale play — possibly on a
|
|
213
|
+
* different song. `mayStart` is checked last and covers conditions that are
|
|
214
|
+
* not a change of intent; sink-change recovery uses it to hand a resume over
|
|
215
|
+
* to a switch that started while the context was resuming. That switch
|
|
216
|
+
* re-reads the intent claimed here when it settles, so it restores playback
|
|
217
|
+
* itself and nothing is lost by dropping out.
|
|
218
|
+
*/
|
|
219
|
+
private playWhen;
|
|
220
|
+
pause(): void;
|
|
221
|
+
stop(): void;
|
|
222
|
+
setAudioDataEnabled(enabled: boolean): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* Route a media event from `source` into the typed Player event stream, but
|
|
225
|
+
* only when `source` is the currently active backend (so a retired backend's
|
|
226
|
+
* late events never leak through).
|
|
227
|
+
*/
|
|
228
|
+
private onBackendEvent;
|
|
229
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { AudioPlayInfo } from "../Player.js";
|
|
2
|
+
import type { Av3aTrackInfo } from "../../shared/contracts/av3a-api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders the AV3A decode stream inside the player window's AudioContext.
|
|
5
|
+
*
|
|
6
|
+
* Decoded PCM16 frames arrive on the direct channel from the AV3A decode
|
|
7
|
+
* utility process (`av3aChannel`) — not through main — and this class converts
|
|
8
|
+
* them to stereo Float32 and pushes them into the `av3a-player` AudioWorklet.
|
|
9
|
+
* The worklet reports consumed frames back, giving an accurate `currentTime`
|
|
10
|
+
* and letting us pause/resume the decode (over the same direct channel) when
|
|
11
|
+
* the buffer grows or shrinks past watermarks. Because the decode + PCM path
|
|
12
|
+
* bypasses main, playback keeps flowing even while main is busy (e.g. a window
|
|
13
|
+
* drag on Windows blocking the main process).
|
|
14
|
+
*/
|
|
15
|
+
export interface Av3aPcmPlayerEvents {
|
|
16
|
+
onOpened?: (info: Av3aTrackInfo) => void;
|
|
17
|
+
onEnded?: () => void;
|
|
18
|
+
onError?: (message: string) => void;
|
|
19
|
+
onBuffering?: (buffering: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare class Av3aPcmPlayer {
|
|
22
|
+
private readonly ctx;
|
|
23
|
+
private readonly events;
|
|
24
|
+
private node;
|
|
25
|
+
private active;
|
|
26
|
+
private playing;
|
|
27
|
+
private stopped;
|
|
28
|
+
private flowPaused;
|
|
29
|
+
private streamEnded;
|
|
30
|
+
private endedEmitted;
|
|
31
|
+
private buffering;
|
|
32
|
+
/** Output rate = the shared AudioContext's sample rate. */
|
|
33
|
+
private readonly outputRate;
|
|
34
|
+
/** Source (decoded) sample rate; known once the track is opened. */
|
|
35
|
+
private sourceRate;
|
|
36
|
+
/** Resamples decoded (e.g. 44.1k) PCM up to the context rate. */
|
|
37
|
+
private resampler;
|
|
38
|
+
private durationSeconds;
|
|
39
|
+
private pushedFrames;
|
|
40
|
+
private consumedFrames;
|
|
41
|
+
private startToken;
|
|
42
|
+
/** Content time (seconds) playback started / last seeked to. */
|
|
43
|
+
private baseTimeSeconds;
|
|
44
|
+
/** Frames with an index below this are stale (emitted before a seek). */
|
|
45
|
+
private dropUntilFrame;
|
|
46
|
+
private playbackRate;
|
|
47
|
+
constructor(ctx: AudioContext, events?: Av3aPcmPlayerEvents);
|
|
48
|
+
get isActive(): boolean;
|
|
49
|
+
get isPlaying(): boolean;
|
|
50
|
+
get currentTime(): number;
|
|
51
|
+
get duration(): number;
|
|
52
|
+
/** The worklet node; connect this into the effect chain / honeypot. */
|
|
53
|
+
get sourceNode(): AudioWorkletNode | null;
|
|
54
|
+
/**
|
|
55
|
+
* Load the worklet and connect it to `destination`. Safe to call once per
|
|
56
|
+
* `start()`/`stop()` cycle (re-attaches to the same node).
|
|
57
|
+
*/
|
|
58
|
+
attach(destination: AudioNode): Promise<void>;
|
|
59
|
+
start(playInfo: AudioPlayInfo): Promise<void>;
|
|
60
|
+
stop(): Promise<void>;
|
|
61
|
+
play(): Promise<void>;
|
|
62
|
+
pause(): void;
|
|
63
|
+
/** Mirror `playing` into the worklet so it stops consuming while paused. */
|
|
64
|
+
private setWorkletPlaying;
|
|
65
|
+
/**
|
|
66
|
+
* Set the playback rate. The resampler step changes from the current
|
|
67
|
+
* position onward; already-buffered audio finishes at the old tempo.
|
|
68
|
+
*/
|
|
69
|
+
setPlaybackRate(rate: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* Seek to a content time (seconds). Flushes buffered audio, resets the
|
|
72
|
+
* resampler, and repositions the main-process decode to the target frame.
|
|
73
|
+
*/
|
|
74
|
+
seekTo(seconds: number): Promise<void>;
|
|
75
|
+
/** (Re)build or update the resampler for the current source/output/rate. */
|
|
76
|
+
private updateResamplerStep;
|
|
77
|
+
private av3aEventBound;
|
|
78
|
+
private bindEvents;
|
|
79
|
+
private onWorkletMessage;
|
|
80
|
+
private queuedSeconds;
|
|
81
|
+
private evaluateFlow;
|
|
82
|
+
private maybeEmitEnded;
|
|
83
|
+
private pushFrame;
|
|
84
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AudioPlayInfo } from "../Player.js";
|
|
2
|
+
import type { Av3aContract } from "../../shared/contracts/av3a-api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Typed client for the main-process `av3a` bridge (the player window).
|
|
5
|
+
*
|
|
6
|
+
* Mirrors `Av3aContract` on top of `ipcRenderer`: methods become
|
|
7
|
+
* `ipcRenderer.invoke("av3a.<method>", ...)`, events become
|
|
8
|
+
* `ipcRenderer.on("av3a.<event>", ...)`.
|
|
9
|
+
*
|
|
10
|
+
* Decode events/frames + pause/resume/seek are NOT here — they use the direct
|
|
11
|
+
* renderer <-> decode-utility channel (`av3aChannel`).
|
|
12
|
+
*/
|
|
13
|
+
export declare const av3aBridge: {
|
|
14
|
+
start(playInfo: AudioPlayInfo): Promise<void>;
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
/** Fallback terminal errors originating in main (e.g. process crash). */
|
|
17
|
+
onError(callback: (message: string) => void): void;
|
|
18
|
+
onProgress(callback: (loaded: number, total: number) => void): void;
|
|
19
|
+
};
|
|
20
|
+
export type Av3aBridge = typeof av3aBridge;
|
|
21
|
+
export type { Av3aContract };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Av3aChannelServiceToRenderer } from "../../shared/contracts/av3a-process.js";
|
|
2
|
+
import type { Av3aTrackInfo } from "../../shared/contracts/av3a-api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renderer end of the direct channel to the AV3A decode utility process.
|
|
5
|
+
*
|
|
6
|
+
* Each `av3a.start` makes main fork a fresh decode process and hand the player
|
|
7
|
+
* window one end of a `MessageChannelMain` over the `av3a.channel` IPC event
|
|
8
|
+
* (`event.ports[0]`, a real DOM `MessagePort`). The utility process holds the
|
|
9
|
+
* other end. All decode events travel on this port, in order:
|
|
10
|
+
*
|
|
11
|
+
* utility -> window: opened | pcm | done | error
|
|
12
|
+
* window -> utility: pause | resume | seek
|
|
13
|
+
*
|
|
14
|
+
* Main is not on this path, so a busy main process can't stall playback.
|
|
15
|
+
* The `av3a` IPC bridge still owns `start`/`stop` and main-origin errors +
|
|
16
|
+
* download progress.
|
|
17
|
+
*/
|
|
18
|
+
type OpenedHandler = (info: Av3aTrackInfo) => void;
|
|
19
|
+
type PcmFrame = Extract<Av3aChannelServiceToRenderer, {
|
|
20
|
+
type: "pcm";
|
|
21
|
+
}>;
|
|
22
|
+
type DoneHandler = () => void;
|
|
23
|
+
type ErrorHandler = (message: string) => void;
|
|
24
|
+
export declare const av3aChannel: {
|
|
25
|
+
/** The `moov` box was indexed (fires before the first `pcm`). */
|
|
26
|
+
onOpened(handler: OpenedHandler): void;
|
|
27
|
+
/** Register the per-frame PCM consumer (kept across sessions). */
|
|
28
|
+
onPcm(handler: (frame: PcmFrame) => void): void;
|
|
29
|
+
/** The last frame of the track was decoded. */
|
|
30
|
+
onDone(handler: DoneHandler): void;
|
|
31
|
+
/** A decode error from the utility process. */
|
|
32
|
+
onError(handler: ErrorHandler): void;
|
|
33
|
+
/** Pause decoding after the current frame (consumer backpressure). */
|
|
34
|
+
pause(): void;
|
|
35
|
+
/** Resume decoding. */
|
|
36
|
+
resume(): void;
|
|
37
|
+
/** Seek the decode session to an absolute track frame index. */
|
|
38
|
+
seek(frameIndex: number): void;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ask main whether a local file is AV3A-encoded. Local play info does not
|
|
3
|
+
* signal the codec (unlike URL play info's `audioFormat`), so the file must be
|
|
4
|
+
* sniffed in main (which owns `fs`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function isAv3aLocalFile(path: string): Promise<boolean>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AudioPlayInfo } from "../Player.js";
|
|
2
|
+
import type { PlaybackBackend, PlaybackEventSink } from "../PlaybackBackend.js";
|
|
3
|
+
/**
|
|
4
|
+
* The AV3A decode backend. Owns an `Av3aPcmPlayer` (worklet playback, PCM
|
|
5
|
+
* resampling/downmix, seek/rate) plus the AV3A timeupdate clock, and raises
|
|
6
|
+
* the same media events as the media-element backend through the sink.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Av3aPlaybackBackend implements PlaybackBackend {
|
|
9
|
+
private readonly player;
|
|
10
|
+
private readonly sink;
|
|
11
|
+
private readonly effectInput;
|
|
12
|
+
private attached;
|
|
13
|
+
private clock;
|
|
14
|
+
private openResolve;
|
|
15
|
+
private playbackRateValue;
|
|
16
|
+
constructor(ctx: AudioContext, effectInput: AudioNode, sink: PlaybackEventSink);
|
|
17
|
+
get sourceNode(): AudioNode | null;
|
|
18
|
+
get currentTime(): number;
|
|
19
|
+
get duration(): number;
|
|
20
|
+
get paused(): boolean;
|
|
21
|
+
get ended(): boolean;
|
|
22
|
+
get playbackRate(): number;
|
|
23
|
+
setPlaybackRate(rate: number): void;
|
|
24
|
+
load(playInfo: AudioPlayInfo): Promise<void>;
|
|
25
|
+
play(): Promise<void>;
|
|
26
|
+
pause(): void;
|
|
27
|
+
stop(): void;
|
|
28
|
+
seek(seconds: number): void;
|
|
29
|
+
private startClock;
|
|
30
|
+
private stopClock;
|
|
31
|
+
dispose(): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PlaybackBackend, PlaybackEventSink } from "../PlaybackBackend.js";
|
|
2
|
+
/**
|
|
3
|
+
* The media-element backend. Owns the hidden `<audio>` element and its
|
|
4
|
+
* `MediaElementAudioSourceNode` so its output flows through the shared WebAudio
|
|
5
|
+
* graph. Real element events are raised through the sink (which `Player` gates
|
|
6
|
+
* to the active backend).
|
|
7
|
+
*/
|
|
8
|
+
export declare class MediaPlaybackBackend implements PlaybackBackend {
|
|
9
|
+
readonly sourceNode: MediaElementAudioSourceNode;
|
|
10
|
+
private readonly element;
|
|
11
|
+
private readonly sink;
|
|
12
|
+
constructor(ctx: AudioContext, sink: PlaybackEventSink);
|
|
13
|
+
load(): Promise<void>;
|
|
14
|
+
play(): Promise<void>;
|
|
15
|
+
pause(): void;
|
|
16
|
+
stop(): void;
|
|
17
|
+
seek(seconds: number): void;
|
|
18
|
+
get currentTime(): number;
|
|
19
|
+
get duration(): number;
|
|
20
|
+
get paused(): boolean;
|
|
21
|
+
get ended(): boolean;
|
|
22
|
+
get playbackRate(): number;
|
|
23
|
+
setPlaybackRate(rate: number): void;
|
|
24
|
+
dispose(): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type HandlerFunction<Args extends unknown[] = unknown[], Return extends unknown[] | void = void> = (...args: Args) => Return | Promise<Return>;
|
|
2
|
+
export type CallbackHandlerFunction<Args extends unknown[] = unknown[]> = (callback: (...args: unknown[]) => void, ...args: Args) => void | Promise<void>;
|
|
3
|
+
export default class CallDispatcher {
|
|
4
|
+
private handlers;
|
|
5
|
+
private callbackHandlers;
|
|
6
|
+
registerHandler<Args extends unknown[], Return extends unknown[] | void>(cmd: string, handler: HandlerFunction<Args, Return>): void;
|
|
7
|
+
registerHandlers(handlers: {
|
|
8
|
+
[cmd: string]: HandlerFunction;
|
|
9
|
+
}): void;
|
|
10
|
+
registerCallbackHandler<Args extends unknown[]>(cmd: string, handler: CallbackHandlerFunction<Args>): void;
|
|
11
|
+
dispatch(cmd: string, callback: (...args: unknown[]) => void, ...args: unknown[]): Promise<void | false>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed client surface over a mount.
|
|
3
|
+
*
|
|
4
|
+
* Property access builds a route; calling a leaf sends a request, and leaves
|
|
5
|
+
* under `events` create subscriptions. The proxy is path-based, so nested
|
|
6
|
+
* contract groups work without codegen.
|
|
7
|
+
*/
|
|
8
|
+
import type { BridgeError } from "./protocol.js";
|
|
9
|
+
type AnyFunction = (...args: any[]) => any;
|
|
10
|
+
export type EventArgs<F> = F extends (callback: (...args: infer A) => void) => unknown ? A : never;
|
|
11
|
+
export type EventEndpoint<E> = {
|
|
12
|
+
[K in keyof E]: E[K] extends (callback: (payload: any) => void) => unknown ? (callback: (...args: EventArgs<E[K]>) => void, onError?: (error: BridgeError) => void) => () => void : E[K] extends object ? EventEndpoint<E[K]> : never;
|
|
13
|
+
};
|
|
14
|
+
export type Endpoint<T> = {
|
|
15
|
+
[K in keyof T as K extends "events" ? never : T[K] extends AnyFunction ? K : T[K] extends object ? K : never]: T[K] extends AnyFunction ? (...args: Parameters<T[K]>) => Promise<Awaited<ReturnType<T[K]>>> : T[K] extends object ? Endpoint<T[K]> : never;
|
|
16
|
+
} & (T extends {
|
|
17
|
+
events: infer E;
|
|
18
|
+
} ? {
|
|
19
|
+
events: EventEndpoint<E>;
|
|
20
|
+
} : {});
|
|
21
|
+
export interface EndpointHooks {
|
|
22
|
+
/** Send a request for the route suffix (for example `cache.getStats`). */
|
|
23
|
+
request(route: string, args: unknown[]): Promise<unknown>;
|
|
24
|
+
/** Subscribe to an event route suffix (for example `timeUpdate`). */
|
|
25
|
+
subscribe(route: string, callback: (...args: unknown[]) => void, onError?: (error: BridgeError) => void): () => void;
|
|
26
|
+
}
|
|
27
|
+
export declare function createEndpoint<T>(hooks: EndpointHooks): Endpoint<T>;
|
|
28
|
+
declare const joinRoute: (mount: string, suffix: string) => string;
|
|
29
|
+
export { joinRoute };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hub: the per-realm router.
|
|
3
|
+
*
|
|
4
|
+
* A hub owns three things:
|
|
5
|
+
* - mounts: routes served by this realm,
|
|
6
|
+
* - ports: bridges attached to this realm (one per outside peer),
|
|
7
|
+
* - links: explicit relay rules between two attached ports.
|
|
8
|
+
*
|
|
9
|
+
* Routes are resolved locally first, then through a link, and rejected
|
|
10
|
+
* otherwise. All frames are correlated with ids owned by the sending hop; a
|
|
11
|
+
* link rewrites ids on the way through and remembers how to send the response
|
|
12
|
+
* back.
|
|
13
|
+
*/
|
|
14
|
+
import { type Endpoint, type EventArgs } from "./endpoint.js";
|
|
15
|
+
import { BridgeError, type Frame } from "./protocol.js";
|
|
16
|
+
type AnyFunction = (...args: any[]) => unknown;
|
|
17
|
+
export interface BridgeInfo<Meta = unknown> {
|
|
18
|
+
/** Stable id of this port, unique within the hub. */
|
|
19
|
+
readonly id: string;
|
|
20
|
+
/**
|
|
21
|
+
* Opaque transport metadata (realm, window, session, ...). The hub never
|
|
22
|
+
* interprets it; it is forwarded to `authorize` and diagnostics verbatim.
|
|
23
|
+
*/
|
|
24
|
+
readonly meta: Meta;
|
|
25
|
+
}
|
|
26
|
+
/** A transport across one boundary. Inert until attached to a hub. */
|
|
27
|
+
export interface Bridge<Meta = unknown> {
|
|
28
|
+
readonly info: BridgeInfo<Meta>;
|
|
29
|
+
send(frame: Frame): void;
|
|
30
|
+
onFrame(handler: (frame: Frame) => void): () => void;
|
|
31
|
+
close(): void;
|
|
32
|
+
}
|
|
33
|
+
export interface Origin<Meta = unknown> {
|
|
34
|
+
readonly bridgeId: string;
|
|
35
|
+
/** Port ids the frame traversed, oldest first. */
|
|
36
|
+
readonly chain: readonly string[];
|
|
37
|
+
/** The peer metadata supplied by the transport that opened this port. */
|
|
38
|
+
readonly meta: Meta;
|
|
39
|
+
}
|
|
40
|
+
export interface CallContext<Meta = unknown> {
|
|
41
|
+
readonly route: string;
|
|
42
|
+
readonly origin: Origin<Meta>;
|
|
43
|
+
readonly signal: AbortSignal;
|
|
44
|
+
/** Id of the port the call arrived on. */
|
|
45
|
+
readonly peer: string;
|
|
46
|
+
}
|
|
47
|
+
export type Handler<Meta = unknown> = (ctx: CallContext<Meta>, ...args: unknown[]) => unknown;
|
|
48
|
+
export type Handlers<T, Meta = unknown> = {
|
|
49
|
+
[K in keyof T as K extends "events" ? never : T[K] extends AnyFunction ? K : T[K] extends object ? K : never]: T[K] extends AnyFunction ? (ctx: CallContext<Meta>, ...args: Parameters<T[K]>) => ReturnType<T[K]> : T[K] extends object ? Handlers<T[K], Meta> : never;
|
|
50
|
+
};
|
|
51
|
+
export type Emitter<T> = {
|
|
52
|
+
[K in keyof T]: T[K] extends (callback: (...args: any) => void) => unknown ? (...args: EventArgs<T[K]>) => void : T[K] extends object ? Emitter<T[K]> : never;
|
|
53
|
+
};
|
|
54
|
+
export interface Mount<T> {
|
|
55
|
+
readonly route: string;
|
|
56
|
+
readonly emit: T extends {
|
|
57
|
+
events: infer E;
|
|
58
|
+
} ? Emitter<E> : Record<string, never>;
|
|
59
|
+
dispose(): void;
|
|
60
|
+
}
|
|
61
|
+
export interface MountOptions<Meta = unknown> {
|
|
62
|
+
/** Fine-grained origin check, applied after the port ingress ACL. */
|
|
63
|
+
readonly authorize?: (origin: Origin<Meta>) => boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface LinkOptions {
|
|
66
|
+
/** Consumer route pattern → server route pattern. Also the link's ACL. */
|
|
67
|
+
readonly routes: Readonly<Record<string, string>>;
|
|
68
|
+
/** Default timeout for requests traversing this link. */
|
|
69
|
+
readonly timeoutMs?: number;
|
|
70
|
+
}
|
|
71
|
+
export interface ConnectOptions {
|
|
72
|
+
readonly timeoutMs?: number;
|
|
73
|
+
readonly onError?: (error: BridgeError) => void;
|
|
74
|
+
}
|
|
75
|
+
export interface Port<Meta = unknown> {
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly origin: Origin<Meta>;
|
|
78
|
+
send(frame: Frame): void;
|
|
79
|
+
dispose(): void;
|
|
80
|
+
}
|
|
81
|
+
export interface Link {
|
|
82
|
+
dispose(): void;
|
|
83
|
+
}
|
|
84
|
+
export declare class HubImpl<Meta = unknown> {
|
|
85
|
+
private readonly mounts;
|
|
86
|
+
private readonly ports;
|
|
87
|
+
private readonly portRecords;
|
|
88
|
+
private readonly links;
|
|
89
|
+
private readonly localSubs;
|
|
90
|
+
private readonly localOrigin;
|
|
91
|
+
private localSubSeq;
|
|
92
|
+
private closed;
|
|
93
|
+
constructor(options?: {
|
|
94
|
+
localMeta?: Meta;
|
|
95
|
+
});
|
|
96
|
+
mount<T>(route: string, impl: Handlers<T, Meta>, options?: MountOptions<Meta>): Mount<T>;
|
|
97
|
+
attach(bridge: Bridge<Meta>): Port<Meta>;
|
|
98
|
+
bridge(client: Port<Meta>, server: Port<Meta>, options: LinkOptions): Link;
|
|
99
|
+
connect<T>(route: string, options?: ConnectOptions): Endpoint<T>;
|
|
100
|
+
connect<T>(port: Port<Meta>, route: string, options?: ConnectOptions): Endpoint<T>;
|
|
101
|
+
dispose(): void;
|
|
102
|
+
private dispatch;
|
|
103
|
+
private reportDispatchFailure;
|
|
104
|
+
private acceptSession;
|
|
105
|
+
private resetPortSession;
|
|
106
|
+
private handleRequest;
|
|
107
|
+
private handleSubscribe;
|
|
108
|
+
private handleResponse;
|
|
109
|
+
private handleEvent;
|
|
110
|
+
private handleUnsubscribe;
|
|
111
|
+
private handleCancel;
|
|
112
|
+
private matchingLinks;
|
|
113
|
+
private forward;
|
|
114
|
+
private expire;
|
|
115
|
+
private forget;
|
|
116
|
+
private removeLink;
|
|
117
|
+
private requestLocal;
|
|
118
|
+
private subscribeLocal;
|
|
119
|
+
private requestVia;
|
|
120
|
+
private subscribeVia;
|
|
121
|
+
private createEmitter;
|
|
122
|
+
private emit;
|
|
123
|
+
private dropSubscriptions;
|
|
124
|
+
private resolveMount;
|
|
125
|
+
private originFor;
|
|
126
|
+
private send;
|
|
127
|
+
private fail;
|
|
128
|
+
private failSub;
|
|
129
|
+
private requirePort;
|
|
130
|
+
private detach;
|
|
131
|
+
private assertOpen;
|
|
132
|
+
}
|
|
133
|
+
export declare function createHub<Meta = unknown>(options?: {
|
|
134
|
+
localMeta?: Meta;
|
|
135
|
+
}): HubImpl<Meta>;
|
|
136
|
+
export {};
|