add single weather or spotify update event

This commit is contained in:
StarAppeal
2024-12-09 04:28:25 +01:00
parent 04d0785c69
commit 6d8a865ad5
4 changed files with 42 additions and 21 deletions
@@ -10,14 +10,22 @@ export class GetSpotifyUpdatesEvent extends CustomWebsocketEvent {
handler = async () => {
console.log("Starting Spotify updates");
// first execute the function once
this.spotifyUpdates()
.then(() => {
// then set the interval
this.ws.asyncUpdates = setInterval(() => {
this.spotifyUpdates();
}, 1000);
});
this.ws.emit(WebsocketEventType.GET_SINGLE_SPOTIFY_UPDATE, {});
this.ws.asyncUpdates = setInterval(() => {
this.ws.emit(WebsocketEventType.GET_SINGLE_SPOTIFY_UPDATE, {});
}, 1000);
}
}
export class GetSingleSpotifyUpdateEvent extends CustomWebsocketEvent {
event = WebsocketEventType.GET_SINGLE_SPOTIFY_UPDATE;
handler = async () => {
console.log("Getting single Spotify update event");
await this.spotifyUpdates();
}
private async spotifyUpdates() {
@@ -8,12 +8,21 @@ export class GetWeatherUpdatesEvent extends CustomWebsocketEvent {
handler = async () => {
console.log("Starting weather updates");
this.weatherUpdates().then(() => {
this.ws.asyncUpdates = setInterval(() => {
this.weatherUpdates();
}, 1000 * 60);
}
);
this.ws.emit(WebsocketEventType.GET_SINGLE_WEATHER_UPDATE);
this.ws.asyncUpdates = setInterval(() => {
this.ws.emit(WebsocketEventType.GET_SINGLE_WEATHER_UPDATE);
}, 1000 * 60);
}
}
export class GetSingleWeatherUpdateEvent extends CustomWebsocketEvent {
event = WebsocketEventType.GET_SINGLE_WEATHER_UPDATE;
handler = async () => {
console.log("Getting single weather update event");
await this.weatherUpdates();
}
private async weatherUpdates() {
@@ -1,7 +1,9 @@
export enum WebsocketEventType {
GET_SETTINGS = "GET_SETTINGS",
GET_STATE = "GET_STATE",
GET_SINGLE_SPOTIFY_UPDATE = "GET_SINGLE_SPOTIFY_UPDATE",
GET_SPOTIFY_UPDATES = "GET_SPOTIFY_UPDATES",
GET_SINGLE_WEATHER_UPDATE = "GET_SINGLE_WEATHER_UPDATE",
GET_WEATHER_UPDATES = "GET_WEATHER_UPDATES",
STOP_SPOTIFY_UPDATES = "STOP_SPOTIFY_UPDATES",
STOP_WEATHER_UPDATES = "STOP_WEATHER_UPDATES",
@@ -1,9 +1,9 @@
import {ExtendedWebSocket} from "../../../interfaces/extendedWebsocket";
import {GetSettingsEvent} from "./getSettingsEvent";
import {ErrorEvent} from "./errorEvent";
import {GetSpotifyUpdatesEvent} from "./getSpotifyUpdatesEvent";
import {GetSingleSpotifyUpdateEvent, GetSpotifyUpdatesEvent} from "./getSpotifyUpdatesEvent";
import {GetStateEvent} from "./getStateEvent";
import {GetWeatherUpdatesEvent} from "./getWeatherUpdatesEvent";
import {GetSingleWeatherUpdateEvent, GetWeatherUpdatesEvent} from "./getWeatherUpdatesEvent";
import {StopSpotifyUpdatesEvent} from "./stopSpotifyUpdatesEvent";
import {StopWeatherUpdatesEvent} from "./stopWeatherUpdatesEvent";
import {UpdateUserEvent} from "./updateUserEvent";
@@ -11,13 +11,15 @@ import {CustomWebsocketEvent} from "./customWebsocketEvent";
export function getEventListeners(ws: ExtendedWebSocket): CustomWebsocketEvent[] {
return [
new GetSettingsEvent(ws),
new ErrorEvent(ws),
new GetSpotifyUpdatesEvent(ws),
new GetStateEvent(ws),
new GetWeatherUpdatesEvent(ws),
new GetSettingsEvent(ws),
new GetSingleSpotifyUpdateEvent(ws),
new GetSpotifyUpdatesEvent(ws),
new StopSpotifyUpdatesEvent(ws),
new GetSingleWeatherUpdateEvent(ws),
new GetWeatherUpdatesEvent(ws),
new StopWeatherUpdatesEvent(ws),
new UpdateUserEvent(ws)
new UpdateUserEvent(ws),
new ErrorEvent(ws)
];
}