UNPKG

upnp-client-ts

Version:

A modern UPNP client made in Typescript.

161 lines (159 loc) 5.73 kB
import http from "http"; import { EventEmitter } from "events"; export interface Icon { mimetype: string; width: string; height: string; depth: string; url: string; } export interface Service { serviceType: string; serviceId: string; SCPDURL: string; controlURL: string; eventSubURL: string; } export interface DeviceDescription { icons: Icon[]; services: Record<string, Service>; deviceType: string; friendlyName: string; manufacturer: string; manufacturerURL: string; modelName: string; modelNumber: string; modelDescription: string; UDN: string; } export interface Action { inputs: ActionArgument[]; outputs: ActionArgument[]; } export interface ActionArgument { name: string; direction: string; relatedStateVariable: string; } interface StateVariable { dataType: string; sendEvents: string; allowedValues: string[]; defaultValue?: string; } export interface ServiceDescription { actions: Record<string, Action>; stateVariables: Record<string, StateVariable>; } export interface Subscription { sid: string; url: string; timer: NodeJS.Timeout; listeners: Listener[]; } export type UpnpEvent = Record<string, string | number>; export type UpnpClientResponse = Record<string, string>; export type Listener = (event: UpnpEvent) => void; export type MediaEvents = 'status' | 'loading' | 'playing' | 'paused' | 'stopped' | 'speedChanged'; export interface Metadata { title?: string; type?: 'audio' | 'video' | 'image'; url?: string; creator?: string; artist?: string; album?: string; albumArtURI?: string; genre?: string; subtitlesUrl?: string; protocolInfo?: string; } export interface Protocol { protocol: string; network: string; contentFormat: string; additionalInfo: string; } export interface MediaRendererOptions { autoplay?: boolean; metadata?: Metadata; dlnaFeatures?: string; contentType?: string; } export class UpnpDeviceClient extends EventEmitter { url: string; deviceDescription: DeviceDescription; serviceDescriptions: Record<string, ServiceDescription>; server: http.Server; listening: boolean; subscriptions: Record<string, Subscription>; constructor(url: string); getDeviceDescription: () => Promise<DeviceDescription>; getServiceDescription: (serviceId: string) => Promise<ServiceDescription>; callAction: (serviceId: string, actionName: string, params: Record<string, string | number>) => Promise<UpnpClientResponse>; subscribe: (serviceId: string, listener: Listener) => Promise<void>; renew: (serviceId: string, sid: string, service: Service) => Promise<void>; unsubscribe: (serviceId: string, listener: Listener) => Promise<boolean>; ensureEventingServer: () => Promise<void>; releaseEventingServer: () => void; } export const formatTime: (seconds: number) => string; export const parseTime: (time: string) => number; export class UpnpMediaRendererClient extends UpnpDeviceClient { instanceId: number; constructor(url: string); callAVTransport: (actionName: string, params: Record<string, string | number>) => Promise<UpnpClientResponse>; getSupportedProtocols: () => Promise<Protocol[]>; getPosition: () => Promise<number>; getPositionInfo: () => Promise<UpnpClientResponse>; getDuration: () => Promise<number>; getMediaInfo: () => Promise<UpnpClientResponse>; load: (url: string, options: MediaRendererOptions) => Promise<UpnpClientResponse>; loadNext: (url: string, options: MediaRendererOptions) => Promise<UpnpClientResponse>; play: () => Promise<UpnpClientResponse>; pause: () => Promise<void>; stop: () => Promise<void>; next: () => Promise<void>; previous: () => Promise<void>; seek: (seconds: number) => Promise<UpnpClientResponse>; getVolume: () => Promise<number>; setVolume: (volume: number) => Promise<void>; getTransportInfo: () => Promise<UpnpClientResponse>; } type SeekMode = 'none' | 'time' | 'range' | 'both'; export const dlnaHelpers: { defaultFlags: { DLNA_STREAMING_BYTE_BASED_FLAGS: string; DLNA_STREAMING_TIME_BASED_FLAGS: string; DLNA_ORIGIN_FLAGS: string; }; flagByteCodes: { /** Content source is the clock source during transport */ DLNA_ORG_FLAG_SENDER_PACED: number; /** Limited Operation: time-seek supported */ DLNA_ORG_FLAG_TIME_BASED_SEEK: number; /** Limited Operation: byte-seek supported */ DLNA_ORG_FLAG_BYTE_BASED_SEEK: number; /** Resource supports 'Container Playback' */ DLNA_ORG_FLAG_PLAY_CONTAINER: number; /** Content does not have a fixed beginning */ DLNA_ORG_FLAG_S0_INCREASE: number; /** Content does not have a fixed end */ DLNA_ORG_FLAG_SN_INCREASE: number; /** RTSP resource supports pausing of media transfer */ DLNA_ORG_FLAG_RTSP_PAUSE: number; /** Streaming transfer mode supported */ DLNA_ORG_FLAG_STREAMING_TRANSFER_MODE: number; /** Interactive transfer mode supported */ DLNA_ORG_FLAG_INTERACTIVE_TRANSFERT_MODE: number; /** Background transfer mode supported */ DLNA_ORG_FLAG_BACKGROUND_TRANSFERT_MODE: number; /** No content transfer when paused */ DLNA_ORG_FLAG_CONNECTION_STALL: number; /** DLNAv1.5 version flag */ DLNA_ORG_FLAG_DLNA_V15: number; }; getDlnaSeekModeFeature: (seekMode: SeekMode) => string; getDlnaTranscodeFeature: (transcodeEnabled: boolean) => string; toDlnaFlagString: (flags: number) => string; }; //# sourceMappingURL=types.d.ts.map