Skip to content

@corewire/airplay/raop ​

ts
import { connect, discover, toTarget } from '@corewire/airplay/raop';

See RAOP.

Connecting ​

ExportDescription
connect(target: RaopTarget, options: RaopConnectOptions): Promise<RaopSession>Connects over RTSP and returns a ready session: the control channel, GET /info, /auth-setup for an AirPort, then ANNOUNCE and SETUP. Throws ConnectionClosedError when the signal aborts during the handshake
discover(options?: DiscoverOptions): Promise<DiscoveryResult[]>The RAOP receivers on the network; DiscoverOptions comes from @corewire/core/discovery
toTarget(result: DiscoveryResult): RaopTargetA target from a discovery result: address, port, id and TXT record
RAOP_SERVICE'_raop._tcp.local'

RaopSession ​

class RaopSession extends EventEmitter<RaopEventMap>

One RAOP connection to a receiver. It ends exactly once, with a reason. Then its signal aborts and a running stream stops. Create it with connect(). The constructor takes internal parts.

MemberDescription
target: RaopTargetWhat connect() got
context: ContextIts logger and identity
info: Record<string, unknown>The /info plist of the receiver; empty when it did not answer
isOpen: boolean
closeReason: CloseReason | undefinedWhy the session ended, or undefined while it is open
signal: AbortSignalAborts with a ConnectionClosedError when the session ends
volumeDb: numberThe volume last sent, in dBFS
stream(source: AudioSource, options?: RaopStreamOptions): Promise<RaopPlayback>Sends metadata, RECORD, FLUSH and the volume, then the audio over RTP. Resolves once audio flows. One stream at a time: a second one throws PlaybackError
setVolumeDb(volumeDb: number): Promise<void>dBFS, -144 (silent) to 0
close(): Promise<void>Stops a running stream and closes the connection
event closed: [reason: CloseReason, error?: Error]The session ended; also when the RTSP connection drops
event playing: [info: RaopPlaybackInfo]
event stoppedA stream stopped

RaopPlayback ​

MemberDescription
ended: Promise<void>Settles when the source ran out and TEARDOWN went out
stop(): voidStops the stream

Helpers ​

ExportDescription
pctToDbfs(volume: number): numberA percentage (0 to 100) to dBFS
getEncryptionTypes(properties: Map<string, string>): EncryptionTypeFrom the TXT record
getMetadataTypes(properties: Map<string, string>): MetadataTypeFrom the TXT record
getAudioProperties(properties: Map<string, string>): [number, number, number]Sample rate, channels and bytes per channel
enum EncryptionTypeUnknown, Unencrypted, MFiSAP
enum MetadataTypeNotSupported, Text, Artwork, Progress

Types ​

TypeDefinition
RaopTarget{address: string; port?: number; id?: string; txt?: Readonly<Record<string, string>>}; port 7000 when omitted
RaopConnectOptions{timing: TimingServer; context?: Context; metadata?: Partial<{title; artist; album}>; password?: string; signal?: AbortSignal}. The port of timing goes into SETUP. metadata shows while a stream has none of its own: title Streaming with CoreWire, artist CoreWire, album AirPlay when omitted. password answers a digest challenge on ANNOUNCE
RaopStreamOptions{metadata?: MediaMetadata; volumeDb?: number}
RaopPlayback{ended: Promise<void>; stop(): void}
RaopEventMap{closed: [reason: CloseReason, error?: Error]; playing: [info: RaopPlaybackInfo]; stopped: []}
RaopPlaybackInfo{metadata: MediaMetadata; position: number}
MediaMetadata{title: string; artist: string; album: string; duration: number; artwork?: Buffer}

CoreWire is released under the MIT license.