lms-player-monitor
v1.0.0
Published
Monitor players connected to Lyrion Music Server
Readme
lms-player-monitor
Monitor players connected to Lyrion Music Server (LMS). Tested with LMS v9.x.
Installation
npm i lms-player-monitorIn package.json of your project, you must add the following section:
"overrides": {
"cometd-nodejs-client": {
"http-proxy-agent": "^7.0.2",
"https-proxy-agent": "^7.0.6"
}
}This is because lms-player-monitor is a CommonJS module, whereas http-proxy-agent and https-proxy-agent (v8 and above) are ESM-only.
Usage
- Create a
LmsPlayerMonitorinstance:
import { LmsPlayerMonitor, Server } from 'lms-player-monitor';
const server: Server = {
host: '192.168.1.30',
// port: ... (defaults to 9000)
// username: ... (for protected LMS)
// password: ...
}
const monitor = new LmsPlayerMonitor({
server
});- Attach event listeners
// Server connected
monitor.on('serverConnect', () => { ... });
// Server disconnected
monitor.on('serverDisconnect', () => { ... });
// Player connected to server
monitor.on('playerConnect', (players) => { ... });
// Player disconnected from server
monitor.on('playerDisconnect', (players) => { ... });
// Player status updated
monitor.on('playerStatus', (status) => { ... });
// Player sync state changed
monitor.on('playerSync', (groups) => { ... });- Start the monitor
await monitor.start();- Stop the monitor
await monitor.stop()'Additonal methods
Description
Retrieves the list of players currently associated with the server. Note this can include players that are disconnected but retained by the server in case they reconnect. To check whether a player is connected, observe its isConnected property.
Returns
Promise<Player[]>: A promise that resolves to an array of Player objects.
Example
const players = (await monitor.getPlayers()).filter(
(player) => player.isConnected
);
console.log('Connected players:', players);Description
Retrieves the status of the player identified by playerId.
Parameters
- playerId: The player ID (
string).
Returns
Promise<PlayerStatus>: A promise that resolves to a PlayerStatus object.
Example
const status = await monitor.getPlayerStatus('d8:3a:dd:58:58:72');Running the example
Clone this repo, then:
$ npm i
$ npm run build
$ npm run example -- -h <server address> Changelog
1.0.0
- Initial release
License
MIT. See LICENSE.
