Skip to content

Commit

Permalink
fix: Generated types (first version)
Browse files Browse the repository at this point in the history
Related to #512
  • Loading branch information
svrooij committed Sep 29, 2021
1 parent 3c40f3d commit 0272cbb
Show file tree
Hide file tree
Showing 37 changed files with 4,102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _exports: typeof import("./lib/sonos");
export = _exports;
9 changes: 9 additions & 0 deletions types/lib/asyncDeviceDiscovery.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export = AsyncDeviceDiscovery;
declare class AsyncDeviceDiscovery {
discover(options?: {
timeout: number;
}): Promise<any>;
discoverMultiple(options?: {
timeout: number;
}): Promise<any>;
}
32 changes: 32 additions & 0 deletions types/lib/deviceDiscovery.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference types="node" />
export = deviceDiscovery;
/**
* Create a DeviceDiscovery Instance (emits 'DeviceAvailable' with a found Sonos Component)
* @param {Object} options Optional Options to control search behavior.
* Set 'timeout' to how long to search for devices
* (in milliseconds).
* Set 'port' to use a specific inbound UDP port,
* rather than a randomly assigned one
* @param {Function} listener Optional 'DeviceAvailable' listener (sonos)
* @return {DeviceDiscovery}
*/
declare function deviceDiscovery(options: any, listener: Function): DeviceDiscovery;
/**
* Create a new instance of DeviceDiscovery
* @class DeviceDiscovery
* @emits 'DeviceAvailable' on a Sonos Component Discovery
*/
declare class DeviceDiscovery extends EventEmitter {
constructor(options: any);
foundSonosDevices: {};
socket: dgram.Socket;
searchTimer: NodeJS.Timeout;
onTimeout(): void;
sendDiscover(): void;
pollTimer: NodeJS.Timeout;
sendDiscoveryOnAddress(address: any): void;
destroy(): void;
}
import EventEmitter_1 = require("events");
import EventEmitter = EventEmitter_1.EventEmitter;
import dgram = require("dgram");
38 changes: 38 additions & 0 deletions types/lib/events/adv-listener.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// <reference types="node" />
export = defaultListener;
declare const defaultListener: SonosListener;
/**
* An event listener for sonos events. (Just a small http server)
* @class SonosListener
*/
declare class SonosListener extends EventEmitter {
/**
* Creates a new SonosListener (called automatically)
*/
constructor();
port: number;
_listening: boolean;
_deviceSubscriptions: any[];
_requestHandler: (req: any, resp: any) => void;
_eventServer: http.Server;
/**
* Start the listener, has to be called before subscribing
*/
startListener(): void;
/**
* Stop the listener and unsubscribes for all events.
* Very important to call or you'll get wrong notifications
*/
stopListener(): Promise<any>;
isListening(): boolean;
/**
* Subscribe to all events for this device.
* @param {Sonos} device Pass in the Sonos device, it will be the eventemitter
*/
subscribeTo(device: any): Promise<any>;
_handleMessage(req: any, resp: any, body: any): void;
_handleGlobalNotification(endpoint: any, body: any): Promise<void>;
}
import EventEmitter_1 = require("events");
import EventEmitter = EventEmitter_1.EventEmitter;
import http = require("http");
43 changes: 43 additions & 0 deletions types/lib/events/eventParser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export function ParseAndEmitEvents(endpoint: any, body: any, device: any): Promise<{
name: string;
eventBody: any;
}>;
export function _parseAvTransportEvent(body: any, device: any): Promise<{
name: string;
eventBody: any;
}>;
export function _parseRenderingControlEvent(body: any, device: any): Promise<{
name: string;
eventBody: any;
}>;
export function _genericEvent(endpoint: any, body: any, device: any): {
name: string;
endpoint: any;
eventBody: any;
};
export function _parseContentDirectoryEvent(body: any, device: any): {
name: string;
eventBody: any;
};
export function _parseAlarmEvent(body: any, device: any): {
name: string;
eventBody: any;
};
export function _parseZoneGroupTopologyEvent(body: any, device: any): Promise<{
name: string;
eventBody: {
Zones: any;
};
}>;
export function _parseGroupRenderingControlEvent(body: any, device: any): {
name: string;
eventBody: any;
device: {
host: any;
port: any;
};
};
export function _parseQueueEvent(body: any, device: any): Promise<{
name: string;
eventBody: any;
}>;
88 changes: 88 additions & 0 deletions types/lib/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Wrap in UPnP Envelope
* @param {String} body The SOAP body.
* @return {String}
*/
export function CreateSoapEnvelop(body: string): string;
/**
* Encodes characters not allowed within html/xml tags, for use with nester xml.
* @param {String} input
* @return {String}
*/
export function EncodeXml(input: string): string;
/**
* Converts parentID to upnp cass
* @param {String} parentID The id of the parent
* @return {String} object.item.audioItem.musicTrack
*/
export function GetUpnpClass(parentID: string): string;
/**
* Generate custom metadata, to be used with the play and/or setAVTransportURI
* @param {String} streamUri The playback uri
* @param {String} itemId
* @param {String} duration The duration of the song, as 'hh:mm:ss'
* @param {String} title The title of the song
* @param {String} artist The artist of the sons
* @param {String} album the album of the song
* @param {String} coverUrl the coverUrl of the song
* @param {String} parentId the parentId of the song
*/
export function GenerateCustomMetadata(streamUrl: any, itemId: string, duration: string, title: string, artist: string, album: string, coverUrl: string, parentId: string): string;
/**
* Creates object with uri and metadata from playback uri
* @param {String} uri The playback uri
* @param {String} artUri Uri for art image
* @return {Object} { uri: uri, metadata: metadata }
*/
export function GenerateLocalMetadata(uri: string, artUri?: string): any;
/**
* Creates object with uri and metadata from playback uri
* @param {String} uri The playback uri (currently supports spotify, tunein)
* @param {String} title Sometimes the title is required.
* @param {String} region Spotify region is required for all spotify tracks, see `sonos.SpotifyRegion`
* @return {Object} options {uri: Spotify uri, metadata: metadata}
*/
export function GenerateMetadata(uri: string, title?: string, region?: string): any;
/**
* Parse DIDL into track structure
* @param {String} didl
* @param {String} host host ip
* @param {Number} port port numer
* @param {String} trackUri Track Uri
* @return {object}
*/
export function ParseDIDL(didl: string, host: string, port: number, trackUri: string): any;
export function dropIDNamespace(value: any): any;
export function ParseDIDLItem(item: any, host: any, port: any, trackUri: any): {
id: any;
parentID: any;
title: any;
artist: any;
album: any;
albumArtist: any;
albumArtURI: any;
};
/**
* Convert a time string to seconds
* @param {String} time like `00:03:34`
* @returns {Number} number of seconds like 214
*/
export function TimeToSeconds(time: string): number;
export function _ParseXml(input: any, callback: any): any;
/**
* Convert the playbackstate to a bit more readable
* @param {String} state Sonos playback state
*/
export function TranslateState(state: string): any;
/**
* Parse Xml to an object async
* @param {String} input The XML to be parsed
* @return {Promise}
*/
export function ParseXml(input: string): Promise<any>;
/**
* Sanitizes Device Description XML async
* @param {String} input The XML to be sanitized
* @return {Promise}
*/
export function SanitizeDeviceDescriptionXml(input: string): Promise<any>;
153 changes: 153 additions & 0 deletions types/lib/services/AVTransport.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
export = AVTransport;
/**
* Create a new instance of AVTransport
* @class AVTransport
* @param {String} host The host param of one of your sonos speakers
* @param {Number} port The port of your sonos speaker, defaults to 1400
*/
declare class AVTransport extends Service {
constructor(host: any, port: any);
/**
* Set the Transport URI
* @param {object} options Object with required options
* @param {number} options.InstanceID The instance you want to control is always `0`
* @param {string} options.CurrentURI The new URI you wish to set.
* @param {string} options.CurrentURIMetaData The metadata of the uri you wish to set.
* @returns {Promise<Object>} Parsed response data.
*/
SetAVTransportURI(options: {
InstanceID: number;
CurrentURI: string;
CurrentURIMetaData: string;
}): Promise<any>;
/**
* Add an URI to the queue
* @param {object} options The the required properties
* @param {number} options.InstanceID The instance you want to control is always `0`
* @param {string} options.EnqueuedURI The URI of the track you want to add
* @param {string} options.EnqueuedURIMetaData The Metadata of the track you wish to add, see `Helpers.GenerateMetadata`
* @param {number} options.DesiredFirstTrackNumberEnqueued The position in the queue
* @param {number} options.EnqueueAsNext To Queue this item as the next item set to `1`
* @returns {Promise<Object>} Parsed response data.
*/
AddURIToQueue(options: {
InstanceID: number;
EnqueuedURI: string;
EnqueuedURIMetaData: string;
DesiredFirstTrackNumberEnqueued: number;
EnqueueAsNext: number;
}): Promise<any>;
AddURIToSavedQueue(options: any): Promise<any>;
AddMultipleURIsToQueue(options: any): Promise<any>;
/**
* Reorder tracks in queue
* @param {object} options All the required options
* @param {number} options.InstanceID The instance you want to edit is always `0`
* @param {number} options.UpdateID The update id, not a clue what this means. Just specify `0`
* @param {number} options.StartingIndex The index of the first song you want to move.
* @param {number} options.NumberOfTracks How many tracks do you want to move?
* @param {number} options.InsertBefore Where should these tracks be inserted?
* @returns {Promise<Object>} Parsed response data.
*/
ReorderTracksInQueue(options: {
InstanceID: number;
UpdateID: number;
StartingIndex: number;
NumberOfTracks: number;
InsertBefore: number;
}): Promise<any>;
ReorderTracksInSavedQueue(options: any): Promise<any>;
/**
* Remove a single track from the queue
* @param {object} options Object with required options
* @param {number} options.InstanceID The instance you want to control is always `0`
* @param {string} options.ObjectID The object to remove
* @param {string} options.UpdateID The update id, not a clue what this means. Just specify `0`
* @returns {Promise<Object>} Parsed response data.
*/
RemoveTrackFromQueue(options: {
InstanceID: number;
ObjectID: string;
UpdateID: string;
}): Promise<any>;
/**
* Remove a range of tracks from the queue
* @param {object} options Object with required options
* @param {number} options.InstanceID The instance you want to control is always `0`
* @param {number} options.UpdateID The update id, not a clue what this means. Just specify `0`
* @param {number} options.StartingIndex Index of the first song to remove
* @param {number} options.NumberOfTracks How many tracks to remove
* @returns {Promise<Object>} Parsed response data.
*/
RemoveTrackRangeFromQueue(options: {
InstanceID: number;
UpdateID: number;
StartingIndex: number;
NumberOfTracks: number;
}): Promise<any>;
RemoveAllTracksFromQueue(): Promise<any>;
SaveQueue(options: any): Promise<any>;
CreateSavedQueue(title: any): Promise<any>;
BackupQueue(options: any): Promise<any>;
GetMediaInfo(): Promise<any>;
GetTransportInfo(): Promise<any>;
GetPositionInfo(): Promise<any>;
GetDeviceCapabilities(): Promise<any>;
GetTransportSettings(): Promise<any>;
GetCrossfadeMode(): Promise<any>;
Stop(): Promise<any>;
Play(): Promise<any>;
Pause(): Promise<any>;
/**
* Skip to other track or time
* @param {object} options Object with required options
* @param {number} options.InstanceID The instance you want to control is always `0`
* @param {'TRACK_NR' | 'REL_TIME' | 'TIME_DELTA'} options.Unit One of these `TRACK_NR`, `REL_TIME`, `TIME_DELTA`
* @param {string | number} options.Target Skip to what track number, relative time as hh:mm:ss, or track number
*/
Seek(options: {
InstanceID: number;
Unit: 'TRACK_NR' | 'REL_TIME' | 'TIME_DELTA';
Target: string | number;
}): Promise<any>;
Next(): Promise<any>;
NextProgrammedRadioTracks(): Promise<any>;
Previous(): Promise<any>;
NextSection(options: any): Promise<any>;
PreviousSection(options: any): Promise<any>;
/**
* Set the new playmode
* @param {string} playmode One of the following `NORMAL` `REPEAT_ALL` `SHUFFLE` `SHUFFLE_NOREPEAT`
* @returns {Promise<Object>} Parsed response data.
*/
SetPlayMode(playmode: string): Promise<any>;
SetCrossfadeMode(options: any): Promise<any>;
NotifyDeletedURI(options: any): Promise<any>;
GetCurrentTransportActions(): Promise<any>;
BecomeCoordinatorOfStandaloneGroup(): Promise<any>;
DelegateGroupCoordinationTo(options: any): Promise<any>;
BecomeGroupCoordinator(options: any): Promise<any>;
BecomeGroupCoordinatorAndSource(options: any): Promise<any>;
/**
* Configure a sleeptimer.
* @param {string} duration the duration as 'ISO8601Time', needs sample!
* @returns {Promise<Object>} Parsed response data.
*/
ConfigureSleepTimer(duration: string): Promise<any>;
GetRemainingSleepTimerDuration(): Promise<any>;
RunAlarm(options: any): Promise<any>;
StartAutoplay(options: any): Promise<any>;
GetRunningAlarmProperties(options: any): Promise<any>;
/**
* Snooze the current running alarm for a number of minutes.
* @param {string} duration The duration, as 'ISO8601Time', needs sample!
* @returns {Promise<Object>} Parsed response data.
*/
SnoozeAlarm(duration: string): Promise<any>;
/**
* Get information about the current track, parsed version of `GetPositionInfo()`
* @returns {Promise<Object>} The current playing track
*/
CurrentTrack(): Promise<any>;
}
import Service = require("./Service");

0 comments on commit 0272cbb

Please sign in to comment.