Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/FoxxMD/multi-scrobbler. Scrobble plays from multiple sources to multiple clients docs.multi-scrobbler.app
deezer docker jellyfin koito lastfm listenbrainz maloja mopidy mpris music music-assistant plex scrobble self-hosted spotify subsonic tautulli youtube-music
Something went wrong. Try again.
2.7 kB · 67 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import { childLogger, type Logger } from '@foxxmd/logging';import type { EventEmitter } from "events";import type {AppriseConfig, GotifyConfig, NtfyConfig, WebhookConfig, WebhookPayload} from "../common/infrastructure/config/health/webhooks.ts";import type { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.ts";import { AppriseWebhookNotifier } from "./AppriseWebhookNotifier.ts";import { GotifyWebhookNotifier } from "./GotifyWebhookNotifier.ts";import { NtfyWebhookNotifier } from "./NtfyWebhookNotifier.ts";import type { MSBackendEventMap } from '../common/infrastructure/MSBackendEventMap.ts';
export class Notifiers {
logger: Logger;
webhooks: AbstractWebhookNotifier[] = [];
emitter: EventEmitter;
clientEmitter: EventEmitter<MSBackendEventMap>; sourceEmitter: EventEmitter<MSBackendEventMap>;
constructor(emitter: EventEmitter, clientEmitter: EventEmitter<MSBackendEventMap>, sourceEmitter: EventEmitter<MSBackendEventMap>, parentLogger: Logger) { this.emitter = emitter; this.clientEmitter = clientEmitter; this.sourceEmitter = sourceEmitter;
this.logger = childLogger(parentLogger, 'Notifiers');
this.sourceEmitter.on('notify', async (payload) => { await this.notify(payload.data); }) this.clientEmitter.on('notify', async (payload) => { await this.notify(payload.data); }) }
buildWebhooks = async (webhookConfigs: WebhookConfig[]) => { for (const [i, config] of Object.entries(webhookConfigs)) { let webhook: AbstractWebhookNotifier; const defaultName = `Config ${i}` switch (config.type) { case 'gotify': webhook = new GotifyWebhookNotifier(defaultName, config as GotifyConfig, this.logger); break; case 'ntfy': webhook = new NtfyWebhookNotifier(defaultName, config as NtfyConfig, this.logger); break; case 'apprise': webhook = new AppriseWebhookNotifier(defaultName, config as AppriseConfig, this.logger); break; default: this.logger.error(`'${config.type}' is not a valid webhook type`); continue; } await webhook.initialize(); if(webhook.initialized) { await webhook.testAuth(); } this.webhooks.push(webhook); } }
notify = async (payload: WebhookPayload) => { for (const webhook of this.webhooks) { await webhook.notify(payload); } }}