@krp-races/krp-node-wrapper
Version:
A node.js wrapper for a dedicated or challenge server in kart racing pro.
22 lines (19 loc) • 734 B
JavaScript
import { createSocket } from 'dgram';
import { EventEmitter } from 'events';
class SocketWrapper extends EventEmitter {
constructor(options) {
super();
this.options = options;
this.socket = createSocket(options.type);
// Forward events
this.socket.on("close", () => this.emit("close"));
this.socket.on("connect", () => this.emit("connect"));
this.socket.on("error", (err) => this.emit("error", err));
this.socket.on("listening", () => this.emit("listening"));
this.socket.on("message", (...args) => this.emit("message", ...args));
}
send(msg) {
this.socket.send(msg, this.options.port, this.options.host);
}
}
export { SocketWrapper };