DFreds
DFreds
Sockets not emitting
Alright, so basically I wrote this
function emitAsGm(
message: SocketMessage,
handler: () => void | Promise<void>,
): void {
if (game.user.isGM) {
handler(); // execute locally
} else {
if (!game.users.activeGM) {
throw Error();
}

game.socket.emit(SocketEffectHandler.IDENTIFIER, message);
}
}
function emitAsGm(
message: SocketMessage,
handler: () => void | Promise<void>,
): void {
if (game.user.isGM) {
handler(); // execute locally
} else {
if (!game.users.activeGM) {
throw Error();
}

game.socket.emit(SocketEffectHandler.IDENTIFIER, message);
}
}
async removeEffect({
effectId,
effectName,
uuid,
origin,
}: IRemoveEffect): Promise<void> {
emitAsGm(
{
request: "removeEffect",
effectId,
effectName,
uuid,
origin,
} satisfies SocketMessage,
async () => {
const effectHandler = new SocketEffectHandler();
await effectHandler.removeEffect({
effectId,
effectName,
uuid,
origin,
});
},
);
}
async removeEffect({
effectId,
effectName,
uuid,
origin,
}: IRemoveEffect): Promise<void> {
emitAsGm(
{
request: "removeEffect",
effectId,
effectName,
uuid,
origin,
} satisfies SocketMessage,
async () => {
const effectHandler = new SocketEffectHandler();
await effectHandler.removeEffect({
effectId,
effectName,
uuid,
origin,
});
},
);
}
For now anyway, probably could use some refactoring but it works. Thanks for the help!
9 replies
Sockets not emitting
Essentially, it needs to execute as the GM, but the issue was if the GM was the one triggering it. So I should so some check there first to see if I need to emit it at all I guess
9 replies
Sockets not emitting
Ohhhh. 😵‍💫 yeah, that was it. So basically... I also need to execute the function locally? I'm now seeing how this worked in socketlib
9 replies