Add foundations for the data request sockets
This commit is contained in:
parent
8632054e63
commit
ce6ac8a93b
8 changed files with 48 additions and 0 deletions
34
module/sockets/_index.mjs
Normal file
34
module/sockets/_index.mjs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { cancelRequest } from "./cancelRequest.mjs";
|
||||
import { createNotif } from "./createNotif.mjs";
|
||||
import { dataRequest } from "./dataRequest.mjs";
|
||||
import { localizer } from "../utils/Localizer.mjs";
|
||||
import { Logger } from "../utils/Logger.mjs";
|
||||
import { submitRequest } from "./submitRequest.mjs";
|
||||
|
||||
const events = {
|
||||
// Data Request sockets
|
||||
cancelRequest,
|
||||
createNotif,
|
||||
dataRequest,
|
||||
submitRequest,
|
||||
};
|
||||
|
||||
export function registerSockets() {
|
||||
Logger.info(`Setting up socket listener`);
|
||||
|
||||
game.socket.on(`system.taf`, (data, userID) => {
|
||||
const { event, payload } = data ?? {};
|
||||
if (event == null || payload === undefined) {
|
||||
ui.notifications.error(localizer(`taf.notifs.error.invalid-socket`));
|
||||
return;
|
||||
};
|
||||
|
||||
if (events[event] == null) {
|
||||
ui.notifications.error(localizer(`taf.notifs.error.unknown-socket-event`, { event }));
|
||||
return;
|
||||
};
|
||||
|
||||
const user = game.users.get(userID);
|
||||
events[event](payload, user);
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue