This repository has been archived on 2026-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
allotment/packages/server/socket/SocketClient.js

31 lines
616 B
JavaScript

export class SocketClient {
constructor(socket) {
this.socket = socket;
this.id = socket.id;
this.request = socket.request;
}
getSession() {
return this.request.session;
}
isWateringAllowed() {
const s = this.getSession();
return !!(s && s.user && s.user.sub);
}
setupListeners() {
this.socket.on("disconnect", () => {
if (this.onDisconnect) this.onDisconnect(this);
});
}
emit(event, data) {
if (event === "message" && data && data.type) {
this.socket.emit(data.type, data.payload);
} else {
this.socket.emit(event, data);
}
}
}