You've already forked factorio-server-manager
mirror of
https://github.com/OpenFactorioServerManager/factorio-server-manager.git
synced 2025-12-03 23:20:28 +02:00
25 lines
663 B
JavaScript
25 lines
663 B
JavaScript
import EventEmitter from "events";
|
|
|
|
const ws_scheme = window.location.protocol === "https:" ? "wss" : "ws";
|
|
const socket = new WebSocket(ws_scheme + "://" + window.location.host + "/ws");
|
|
|
|
const bus = new EventEmitter();
|
|
|
|
bus.on('log subscribe', () => {
|
|
socket.send(JSON.stringify({name: 'log subscribe'}));
|
|
});
|
|
|
|
bus.on('server status subscribe', () => {
|
|
socket.send(JSON.stringify({name: 'server status subscribe'}));
|
|
});
|
|
|
|
bus.on('command send', command => {
|
|
socket.send(JSON.stringify({name: 'command send', data: command}));
|
|
});
|
|
|
|
socket.onmessage = e => {
|
|
const {name, data} = JSON.parse(e.data)
|
|
bus.emit(name, data);
|
|
}
|
|
|
|
export default bus; |