add single weather or spotify update event
This commit is contained in:
@@ -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)
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user