Zero-dependency Node.js client library for the LiveSplit Server.
Simply run in your terminal:
npm install livesplit-client
- Enable LiveSplit Server.
- Then look into this usage example:
const LiveSplitClient = require('livesplit-client');
(async () => {
try {
// Initialize client with LiveSplit Server's IP:PORT
const client = new LiveSplitClient('127.0.0.1:16834');
// Connect to the server, Promise will be resolved when the connection will be succesfully established
await client.connect();
// Start timer.
client.startOrSplit();
// Job done, now we can close this connection
client.disconnect();
} catch (err) {
console.error(err); // Something went wrong
}
})();
Click here and you will be navigated to the latest API docs.
Default command response timeout is 100 ms. You can set your own timeout:
const LiveSplitClient = require('livesplit-client');
const client = new LiveSplitClient('127.0.0.1:16834');
client.timeout = 250; // Timeout in ms
You could use client.send('command', expectResponse)
. Please note, that \r\n
will be automatically added to your command.
If your are expecting the answer, your should specify true
as second argument of this method. In other case Promise
will not be returned and you could potentially break answers order.
const LiveSplitClient = require('livesplit-client');
(async () => {
try {
// Initialize client with LiveSplit Server's IP:PORT
const client = new LiveSplitClient('127.0.0.1:16834');
// Connected event
client.on('connected', () => {
console.log('Connected!');
});
// Disconnected event
client.on('disconnected', () => {
console.log('Disconnected!');
});
// Error event
client.on('error', (err) => {
console.log(err);
});
// Raw data reciever
client.on('data', (data) => {
console.log('Debug data:', data);
});
// Some async sleep sugar for this example
const sleep = (time) => {
return new Promise((r) => {
setTimeout(() => r(), time);
});
};
// Connect to the server, Promise will be resolved when the connection will be succesfully established
await client.connect();
// Start timer
client.startOrSplit();
// Wait for 1 sec
await sleep(1000);
// Current time after 1 second
const time = await client.getCurrentTime();
console.log('Current time after 1 sec.:', time); // Blazing fast and accurate numbers
// Get split name
const splitName = await client.getCurrentSplitName();
console.log('Split name:', splitName);
// Get all available information
const info = await client.getAll();
console.log('Summary:', info);
// Pause and reset
await client.pause();
await client.reset();
// Job done, now we can close this connection
client.disconnect();
} catch (err) {
console.error(err); // Something went wrong
}
})();
Feel free to create issues and PR's. Thank you for your help!