31 lines
616 B
JavaScript
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);
|
|
}
|
|
}
|
|
}
|