From fdf8b60aaaaea96e84e305d66a3739205e967b5f Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Tue, 5 Sep 2023 12:06:44 +0200 Subject: [PATCH 1/3] Add getPositionInfo and improve getPosition --- src/index.ts | 1 + src/mediarendererClient.ts | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7e8166c..0c969c6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export { UpnpDeviceClient } from './deviceClient'; export { UpnpMediaRendererClient } from './mediarendererClient'; export { dlnaHelpers } from './utils/dlna'; +export { formatTime, parseTime } from './utils/time'; export * from './types'; diff --git a/src/mediarendererClient.ts b/src/mediarendererClient.ts index a2901ce..82dc421 100644 --- a/src/mediarendererClient.ts +++ b/src/mediarendererClient.ts @@ -109,8 +109,11 @@ export class UpnpMediaRendererClient extends UpnpDeviceClient { InstanceID: this.instanceId }); - const strTime = response.AbsTime !== 'NOT_IMPLEMENTED' ? response.AbsTime : response.RelTime; - return parseTime(strTime); + return parseTime(response.RelCount); + }; + + getPositionInfo = (): Promise => { + return this.callAVTransport('GetPositionInfo', { InstanceID: this.instanceId }); }; getDuration = async (): Promise => { From 2503cb88b4812f276d510698bbd3193a1c50ef75 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Tue, 5 Sep 2023 12:18:57 +0200 Subject: [PATCH 2/3] Add next and previous AVTransport commands --- src/mediarendererClient.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mediarendererClient.ts b/src/mediarendererClient.ts index 82dc421..47e900e 100644 --- a/src/mediarendererClient.ts +++ b/src/mediarendererClient.ts @@ -192,6 +192,16 @@ export class UpnpMediaRendererClient extends UpnpDeviceClient { await this.callAVTransport('Stop', params); }; + next = async () => { + const params = { InstanceID: this.instanceId }; + await this.callAVTransport('Next', params); + }; + + previous = async () => { + const params = { InstanceID: this.instanceId }; + await this.callAVTransport('Previous', params); + }; + seek = (seconds: number): Promise => { const params = { InstanceID: this.instanceId, From 7348ba78e21bd0a25ae50760d8f406be045b0d19 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Tue, 5 Sep 2023 12:19:06 +0200 Subject: [PATCH 3/3] Update readme with more usage information --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d119d50..5657ed1 100644 --- a/README.md +++ b/README.md @@ -55,15 +55,40 @@ import upnp from 'upnp-client'; const client = new upnp.UpnpMediaRendererClient('http://192.168.1.50:54380/MediaRenderer_HT-A9.xml'); -// TODO: To be written +const options = { + autoplay: true, + contentType: 'audio/flac', + dlnaFeatures: dlnaContentFeatures, // see below for dlnaHelpers + metadata: { + title: 'My song', + creator: 'My creator', + artist: 'My artist', + album: 'My album', + albumArtURI: 'http://127.0.0.1/albumArtURI.jpg', + type: 'audio' + } +}; -await client.play(); +await client.load('http://127.0.0.1/music.flac', options); + +await client.loadNext('http://127.0.0.1/next-music.flac', options); await client.pause(); +await client.play(); + await client.stop(); +await client.next(); + +await client.previous(); + await client.seek(60); + +// you can also call any AVTransport action supported by your device +const response = await client.callAVTransport('YourCustomAVTransportCall', { + InstanceID: client.instanceId +}); ``` ## Usage of dlnaHelpers @@ -77,6 +102,24 @@ const dlnaContentFeatures = `${upnp.dlnaHelpers.defaultFlags.DLNA_STREAMING_TIME_BASED_FLAGS}`; ``` +## Tips and tricks + +In the metadata you're passing to your speaker, make sure to avoid using accents and special characters. + +Here is a simple helper you could use: + +```ts +const escapeSpecialChars = (value: string) => { + return value + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') // remove all accents from characters + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/’/g, "'"); +}; +``` + ## Debugging Run with debug traces