Skip to content

Commit

Permalink
Merge pull request #4 from Mikescops/feature/add-new-commands-mediare…
Browse files Browse the repository at this point in the history
…nderer

Add new commands mediarenderer
  • Loading branch information
Mikescops authored Sep 5, 2023
2 parents c36a278 + 7348ba7 commit 1b4273f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, '&lt;')
.replace(/>/g, '&gt;')
.replace(//g, "'");
};
```

## Debugging

Run with debug traces
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
17 changes: 15 additions & 2 deletions src/mediarendererClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpnpClientResponse> => {
return this.callAVTransport('GetPositionInfo', { InstanceID: this.instanceId });
};

getDuration = async (): Promise<number> => {
Expand Down Expand Up @@ -189,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<UpnpClientResponse> => {
const params = {
InstanceID: this.instanceId,
Expand Down

0 comments on commit 1b4273f

Please sign in to comment.