@naxodev/opencode-music-player 0.2.6 → 0.3.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.
package/types.ts DELETED
@@ -1,144 +0,0 @@
1
- import type {
2
- PlayerState as CorePlayerState,
3
- Track as CoreTrack,
4
- } from "@naxodev/music-core"
5
- import {
6
- emptyPlayer as emptyCorePlayer,
7
- formatMs,
8
- isMac,
9
- } from "@naxodev/music-core"
10
-
11
- export type { Device, MusicError } from "@naxodev/music-core"
12
- export { formatMs, isMac }
13
-
14
- export type Artwork = {
15
- id: string
16
- legacy_id?: string
17
- png_base64: string
18
- accent: string
19
- cells: Array<Array<{ upper: string; lower: string }>>
20
- }
21
-
22
- /** Native IDs validate artwork samples; recording metadata keys artwork work. */
23
- export type ArtworkIdentity = {
24
- uid: string
25
- title: string
26
- artist: string
27
- album: string
28
- duration_ms: number
29
- }
30
-
31
- export type ArtworkCompletionEvent = {
32
- type: "artwork-completion"
33
- identity: ArtworkIdentity
34
- artwork: Artwork | null
35
- duration_ms: number
36
- }
37
-
38
- export type ArtworkPresentationListener = (
39
- event: ArtworkCompletionEvent,
40
- ) => void
41
-
42
- export type Track = CoreTrack & {
43
- artwork: Artwork | null
44
- artwork_loading?: boolean
45
- }
46
-
47
- export type PlayerState = Omit<CorePlayerState, "track"> & {
48
- track: Track | null
49
- }
50
-
51
- export type SessionMediaSnapshotEvent = {
52
- type: "snapshot"
53
- state: PlayerState
54
- }
55
-
56
- /** Host-local projection of session provider/connection lifecycle. */
57
- export type SessionMediaLifecycleEvent = {
58
- type: "lifecycle"
59
- message: string | null
60
- source: "connection" | "provider" | "acquisition"
61
- }
62
-
63
- export type SessionMediaEvent =
64
- SessionMediaSnapshotEvent | SessionMediaLifecycleEvent
65
- export type SessionMediaListener = (event: SessionMediaEvent) => void
66
- export type SessionMediaDisposer = () => void
67
-
68
- /** The OpenCode controller's session-only media contract. */
69
- export type SessionMedia = {
70
- player: () => Promise<PlayerState | null>
71
- refreshArtwork: () => Promise<void>
72
- play: () => Promise<unknown>
73
- pause: () => Promise<unknown>
74
- next: () => Promise<unknown>
75
- previous: () => Promise<unknown>
76
- seek: (positionMs: number) => Promise<unknown>
77
- subscribe: (listener: SessionMediaListener) => SessionMediaDisposer
78
- subscribePresentation: (
79
- listener: ArtworkPresentationListener,
80
- ) => SessionMediaDisposer
81
- dispose: () => Promise<void>
82
- }
83
-
84
- export function emptyPlayer(): PlayerState {
85
- return {
86
- ...emptyCorePlayer(),
87
- track: null,
88
- }
89
- }
90
-
91
- /** Merge an independent artwork result without accepting stale playback data. */
92
- export function mergeArtworkCompletion(
93
- player: PlayerState | null,
94
- event: ArtworkCompletionEvent,
95
- ): PlayerState | null {
96
- const track = player?.track
97
- if (
98
- !track ||
99
- track.name !== event.identity.title ||
100
- track.artists !== event.identity.artist ||
101
- track.album !== event.identity.album ||
102
- (track.duration_ms > 0 && track.duration_ms !== event.identity.duration_ms)
103
- ) {
104
- return player
105
- }
106
- return {
107
- ...player,
108
- track: {
109
- ...track,
110
- artwork: event.artwork,
111
- artwork_loading: false,
112
- },
113
- }
114
- }
115
-
116
- /** Keep host-local artwork presentation across playback-only snapshots. */
117
- export function mergePlayerSnapshot(
118
- player: PlayerState | null,
119
- snapshot: PlayerState,
120
- ): PlayerState {
121
- const current = player?.track
122
- const next = snapshot.track
123
- if (
124
- !current ||
125
- !next ||
126
- current.name !== next.name ||
127
- current.artists !== next.artists ||
128
- current.album !== next.album ||
129
- (current.duration_ms > 0 &&
130
- next.duration_ms > 0 &&
131
- current.duration_ms !== next.duration_ms) ||
132
- (current.artwork === null && current.artwork_loading !== false)
133
- ) {
134
- return snapshot
135
- }
136
- return {
137
- ...snapshot,
138
- track: {
139
- ...next,
140
- artwork: next.artwork ?? current.artwork,
141
- artwork_loading: false,
142
- },
143
- }
144
- }