-
Notifications
You must be signed in to change notification settings - Fork 10
Classes
This project offers a number of TypeScript classes that you can use to interact with Killer Queen's socket messages.
The KQStream
class is an EventEmitter
that processes socket messages from a Killer Queen cabinet. You can set up a callback method for each type of supported event. These callback methods receive objects that contain event data in a deserialized format.
Creates a new KQStream
object with the specified options:
-
options.log
: astream.Writable
object where all messages from the cabinet, appended with a timestamp, will be written
All options
properties are optional.
Connect to the specified host and processes messages. host
should usually follow the format: ws://[HOST_IP]:12749
.
Reads and processes messages from the data
string, simulating messages from a real Killer Queen cabinet.
data
must be the contents of a CSV file with the following format:
- First value: timestamp in milliseconds
- Second value: message from the cabinet (not wrapped in quotes)
The first message in the data
string is processed immediately, and processing of subsequent messages is delayed according to each message's timestamp. For this reason, the messages in the CSV file must be ordered chronologically, from least recent to most recent.
Example contents of data
parameter:
1518063409334,![k[playerKill],v[355.7845,653.2191,1,8]]!
1518063409335,![k[playerKill],v[374.6361,728.9593,2,1]]!
1518063409336,![k[playerKill],v[688.7562,494.5107,2,5]]!
1518063409337,![k[playernames],v[,,,,,,,,,]]!
Set the callback for playerKill
events. callback
should accept a single parameter of type PlayerKill
.
Set the callback for playernames
events. callback
should accept a single parameter of type PlayerNames
.
Simple killfeed:
import { KQStream, PlayerKill, Character } from '../src/KQStream';
const characterNames = {
[Character.GoldQueen]: 'Gold Queen',
[Character.BlueQueen]: 'Blue Queen',
[Character.GoldStripes]: 'Gold Stripes',
[Character.BlueStripes]: 'Blue Stripes',
[Character.GoldAbs]: 'Gold Abs',
[Character.BlueAbs]: 'Blue Abs',
[Character.GoldSkulls]: 'Gold Skull',
[Character.BlueSkulls]: 'Blue Skull',
[Character.GoldChecks]: 'Gold Checks',
[Character.BlueChecks]: 'Blue Checks'
};
const stream = new KQStream();
stream.on('playerKill', (event: PlayerKill) => {
const victor = characterNames[event.by];
const vainquished = characterNames[event.killed];
console.log(`${victor} killed ${vainquished} at ${event.pos.x},${event.pos.y}`);
});
stream.connect(`ws://localhost:12749`);
Logging all cabinet messages to a file:
import * as fs from 'fs';
import { KQStream } from '../src/KQStream';
const stream = new KQStream({
log: fs.createWriteStream('log.txt')
});
stream.connect(`ws://localhost:12749`);
See the example
folder for more usage examples.