mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 05:17:35 +00:00
f87053cb02
feat: add browser opening to test:notification feat: add c8 and mocha for testing feat: update Docker and ci style: update editorconfig
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import playerLib, {PlaySound} from 'play-sound';
|
|
import {config} from '../config';
|
|
import fs from 'fs';
|
|
import {logger} from '../logger';
|
|
|
|
let player: PlaySound;
|
|
|
|
if (config.notifications.playSound) {
|
|
player = config.notifications.soundPlayer
|
|
? playerLib({players: [config.notifications.soundPlayer]})
|
|
: playerLib();
|
|
|
|
if (player.player === null) {
|
|
logger.warn("✖ couldn't find sound player");
|
|
} else {
|
|
const playerName = player.player;
|
|
logger.info(`✔ sound player found: ${playerName}`);
|
|
}
|
|
}
|
|
|
|
export function playSound() {
|
|
if (config.notifications.playSound && player.player !== null) {
|
|
logger.debug('↗ playing sound');
|
|
|
|
fs.access(config.notifications.playSound, fs.constants.F_OK, error => {
|
|
if (error) {
|
|
logger.error(`✖ error opening sound file: ${error.message}`);
|
|
return;
|
|
}
|
|
|
|
player.play(config.notifications.playSound, (error: Error) => {
|
|
if (error) {
|
|
logger.error("✖ couldn't play sound", error);
|
|
}
|
|
|
|
logger.info('✔ played sound');
|
|
});
|
|
});
|
|
}
|
|
}
|