From f020613759b6b2517675dc8b9e111f5cb580adc7 Mon Sep 17 00:00:00 2001 From: KGT1 Date: Mon, 21 Sep 2020 05:30:39 +0200 Subject: [PATCH] fix all lint errors --- .eslintrc.json | 7 +- package.json | 3 +- parseENV.js | 29 ++-- src/discordclientmanager.js | 16 +-- src/dispachermanager.js | 14 +- src/index.js | 29 ++-- src/jellyfinclientmanager.js | 26 ++-- src/messagehandler.js | 268 ++++++++++++++++------------------- src/playbackmanager.js | 214 +++++++++++++--------------- src/util.js | 12 +- src/websockethandler.js | 67 +++++---- 11 files changed, 327 insertions(+), 358 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 36f559c..539a4a1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,5 +11,10 @@ "ecmaVersion": 12 }, "rules": { + "semi": ["error", "always"], + "quotes": ["error", "double"], + "indent": ["error", "tab"], + "no-unused-vars": ["error"], + "no-tabs":["error",{"allowIndentationTabs":true}] } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 4918b4f..8af2e91 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node src/index.js", - "postinstall": "npx patch-package" + "postinstall": "npx patch-package", + "lint": "npx eslint src/ & npx eslint parseENV.js" }, "repository": { "type": "git", diff --git a/parseENV.js b/parseENV.js index 0c1655d..c1d0b60 100644 --- a/parseENV.js +++ b/parseENV.js @@ -1,21 +1,14 @@ -const fs = require('fs'); -const filename='./config.json'; +const fs = require("fs"); +const filename = "./config.json"; const configfile = require(filename); -if(!configfile["discord-prefix"]) - configfile["discord-prefix"]=process.env.DISCORD_PREFIX; -if(!configfile["token"]) - configfile["token"]=process.env.DISCORD_TOKEN; -if(!configfile["server-adress"]) - configfile["server-adress"]=process.env.JELLYFIN_SERVER_ADDRESS; -if(!configfile["jellyfin-username"]) - configfile["jellyfin-username"]=process.env.JELLYFIN_USERNAME; -if(!configfile["jellyfin-password"]) - configfile["jellyfin-password"]=process.env.JELLYFIN_PASSWORD; -if(!configfile["jellyfin-app-name"]) - configfile["jellyfin-app-name"]=process.env.JELLYFIN_APP_NAME; +if (!configfile["discord-prefix"]) { configfile["discord-prefix"] = process.env.DISCORD_PREFIX; } +if (!configfile.token) { configfile.token = process.env.DISCORD_TOKEN; } +if (!configfile["server-adress"]) { configfile["server-adress"] = process.env.JELLYFIN_SERVER_ADDRESS; } +if (!configfile["jellyfin-username"]) { configfile["jellyfin-username"] = process.env.JELLYFIN_USERNAME; } +if (!configfile["jellyfin-password"]) { configfile["jellyfin-password"] = process.env.JELLYFIN_PASSWORD; } +if (!configfile["jellyfin-app-name"]) { configfile["jellyfin-app-name"] = process.env.JELLYFIN_APP_NAME; } - -fs.writeFile(filename, JSON.stringify(configfile,null,1), (err) => { - if (err) return console.log(err); -}); \ No newline at end of file +fs.writeFile(filename, JSON.stringify(configfile, null, 1), (err) => { + if (err) return console.log(err); +}); diff --git a/src/discordclientmanager.js b/src/discordclientmanager.js index 0af363e..0ff55b9 100644 --- a/src/discordclientmanager.js +++ b/src/discordclientmanager.js @@ -1,15 +1,15 @@ -const Discord = require('discord.js'); +const Discord = require("discord.js"); var discordClient; -function init(){ - discordClient= new Discord.Client(); +function init () { + discordClient = new Discord.Client(); } -function getDiscordClient(){ - return discordClient; +function getDiscordClient () { + return discordClient; } module.exports = { - getDiscordClient, - init -} + getDiscordClient, + init +}; diff --git a/src/dispachermanager.js b/src/dispachermanager.js index c8093fe..5aba524 100644 --- a/src/dispachermanager.js +++ b/src/dispachermanager.js @@ -1,13 +1,13 @@ var audioDispatcher; -function setAudioDispatcher(par){ - audioDispatcher=par; +function setAudioDispatcher (par) { + audioDispatcher = par; } -function getAudioDispatcher(){ - return audioDispatcher; +function getAudioDispatcher () { + return audioDispatcher; } module.exports = { - setAudioDispatcher, - getAudioDispatcher -} \ No newline at end of file + setAudioDispatcher, + getAudioDispatcher +}; diff --git a/src/index.js b/src/index.js index 40527ec..955221c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,29 +1,26 @@ +const CONFIG = require("../config.json"); -const CONFIG = require('../config.json'); +const jellyfinClientManager = require("./jellyfinclientmanager"); -const jellyfinClientManager=require('./jellyfinclientmanager'); - -const discordclientmanager= require('./discordclientmanager'); +const discordclientmanager = require("./discordclientmanager"); discordclientmanager.init(); -const discordClient=discordclientmanager.getDiscordClient(); +const discordClient = discordclientmanager.getDiscordClient(); -const {audioDispatcher} = require('./dispachermanager'); -const {handleChannelMessage}=require('./messagehandler'); +const { handleChannelMessage } = require("./messagehandler"); jellyfinClientManager.init(); -//TODO Error Checking as the apiclients is inefficent -jellyfinClientManager.getJellyfinClient().authenticateUserByName(CONFIG["jellyfin-username"],CONFIG["jellyfin-password"]).then((response)=>{ - jellyfinClientManager.getJellyfinClient().setAuthenticationInfo(response.AccessToken, response.SessionInfo.UserId); +// TODO Error Checking as the apiclients is inefficent +jellyfinClientManager.getJellyfinClient().authenticateUserByName(CONFIG["jellyfin-username"], CONFIG["jellyfin-password"]).then((response) => { + jellyfinClientManager.getJellyfinClient().setAuthenticationInfo(response.AccessToken, response.SessionInfo.UserId); }); - -discordClient.on('ready', () => { - console.log('connected to Discord'); +discordClient.on("ready", () => { + console.log("connected to Discord"); }); -discordClient.on('message', message => { - handleChannelMessage(message); +discordClient.on("message", message => { + handleChannelMessage(message); }); -discordClient.login(CONFIG.token); \ No newline at end of file +discordClient.login(CONFIG.token); diff --git a/src/jellyfinclientmanager.js b/src/jellyfinclientmanager.js index 1a40518..9541f97 100644 --- a/src/jellyfinclientmanager.js +++ b/src/jellyfinclientmanager.js @@ -1,24 +1,24 @@ -const { ApiClient , Events } = require('jellyfin-apiclient'); -const CONFIG = require('../config.json'); -const os = require('os'); +const { ApiClient, Events } = require("jellyfin-apiclient"); +const CONFIG = require("../config.json"); +const os = require("os"); var jellyfinClient; -function init(){ - jellyfinClient = new ApiClient(CONFIG["server-adress"], CONFIG["jellyfin-app-name"], "0.0.1", os.hostname(), os.hostname()); +function init () { + jellyfinClient = new ApiClient(CONFIG["server-adress"], CONFIG["jellyfin-app-name"], "0.0.1", os.hostname(), os.hostname()); } -function getJellyfinClient(){ - return jellyfinClient; +function getJellyfinClient () { + return jellyfinClient; } -function getJellyfinEvents(){ - return Events; +function getJellyfinEvents () { + return Events; } module.exports = { - getJellyfinClient, - getJellyfinEvents, - init -} \ No newline at end of file + getJellyfinClient, + getJellyfinEvents, + init +}; diff --git a/src/messagehandler.js b/src/messagehandler.js index 7bfff5e..00fd310 100644 --- a/src/messagehandler.js +++ b/src/messagehandler.js @@ -1,171 +1,155 @@ -const CONFIG = require('../config.json'); -const Discord = require('discord.js'); +const CONFIG = require("../config.json"); +const Discord = require("discord.js"); const { - checkJellyfinItemIDRegex -} = require('./util'); + checkJellyfinItemIDRegex +} = require("./util"); const { - getAudioDispatcher -} = require('./dispachermanager'); + getAudioDispatcher +} = require("./dispachermanager"); -const discordclientmanager = require('./discordclientmanager'); -const jellyfinClientManager = require('./jellyfinclientmanager'); -const playbackmanager = require('./playbackmanager'); -const websocketHanler = require('./websockethandler'); +const discordclientmanager = require("./discordclientmanager"); +const jellyfinClientManager = require("./jellyfinclientmanager"); +const playbackmanager = require("./playbackmanager"); +const websocketHanler = require("./websockethandler"); const discordClient = discordclientmanager.getDiscordClient(); - var isSummendByPlay = false; +// random Color of the Jellyfin Logo Gradient +function getRandomDiscordColor () { + function randomNumber (b, a) { + return Math.floor((Math.random() * Math.pow(Math.pow((b - a), 2), 1 / 2)) + (b > a ? a : b)); + } -//random Color of the Jellyfin Logo Gradient -function getRandomDiscordColor() { - function randomNumber(b, a) { - return Math.floor((Math.random() * Math.pow(Math.pow((b - a), 2), 1 / 2)) + (b > a ? a : b)) - } + const GRANDIENT_START = "#AA5CC3"; + const GRANDIENT_END = "#00A4DC"; - const GRANDIENT_START = '#AA5CC3'; - const GRANDIENT_END = '#00A4DC'; + let rS = GRANDIENT_START.slice(1, 3); + let gS = GRANDIENT_START.slice(3, 5); + let bS = GRANDIENT_START.slice(5, 7); + rS = parseInt(rS, 16); + gS = parseInt(gS, 16); + bS = parseInt(bS, 16); - let rS = GRANDIENT_START.slice(1, 3); - let gS = GRANDIENT_START.slice(3, 5); - let bS = GRANDIENT_START.slice(5, 7); - rS = parseInt(rS, 16); - gS = parseInt(gS, 16); - bS = parseInt(bS, 16); + let rE = GRANDIENT_END.slice(1, 3); + let gE = GRANDIENT_END.slice(3, 5); + let bE = GRANDIENT_END.slice(5, 7); + rE = parseInt(rE, 16); + gE = parseInt(gE, 16); + bE = parseInt(bE, 16); - let rE = GRANDIENT_END.slice(1, 3); - let gE = GRANDIENT_END.slice(3, 5); - let bE = GRANDIENT_END.slice(5, 7); - rE = parseInt(rE, 16); - gE = parseInt(gE, 16); - bE = parseInt(bE, 16); - - return ('#' + ('00' + (randomNumber(rS, rE)).toString(16)).substr(-2) + ('00' + (randomNumber(gS, gE)).toString(16)).substr(-2) + ('00' + (randomNumber(bS, bE)).toString(16)).substr(-2)); + return ("#" + ("00" + (randomNumber(rS, rE)).toString(16)).substr(-2) + ("00" + (randomNumber(gS, gE)).toString(16)).substr(-2) + ("00" + (randomNumber(bS, bE)).toString(16)).substr(-2)); } -async function searchForItemID(searchString) { +async function searchForItemID (searchString) { + const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({ + searchTerm: searchString, + includeItemTypes: "Audio" + }); - let response = await jellyfinClientManager.getJellyfinClient().getSearchHints({ - searchTerm: searchString, - includeItemTypes: "Audio" - }) - - if (response.TotalRecordCount < 1) { - throw "Found no Song" - } else { - return response.SearchHints[0].ItemId - } + if (response.TotalRecordCount < 1) { + throw Error("Found no Song"); + } else { + return response.SearchHints[0].ItemId; + } } -function summon(voiceChannel){ - voiceChannel.join() +function summon (voiceChannel) { + voiceChannel.join(); } -function summonMessage(message){ - if (!message.member.voice.channel) { - message.reply('please join a voice channel to summon me!'); - }else if(message.channel.type === 'dm'){ - message.reply('no dms') - } - else{ - summon(message.member.voice.channel) - } +function summonMessage (message) { + if (!message.member.voice.channel) { + message.reply("please join a voice channel to summon me!"); + } else if (message.channel.type === "dm") { + message.reply("no dms"); + } else { + summon(message.member.voice.channel); + } } -function handleChannelMessage(message) { - getRandomDiscordColor() +async function playThis (message) { + const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "play") + (CONFIG["discord-prefix"] + "play").length + 1; + const argument = message.content.slice(indexOfItemID); + let itemID; + // check if play command was used with itemID + const regexresults = checkJellyfinItemIDRegex(argument); + if (regexresults) { + itemID = regexresults[0]; + } else { + try { + itemID = await searchForItemID(argument); + } catch (e) { + message.reply(e.message); + playbackmanager.stop(discordClient.user.client.voice.connections.first()); + return; + } + } - if (message.content.startsWith(CONFIG["discord-prefix"] + 'summon')) { - isSummendByPlay = false; + discordClient.user.client.voice.connections.forEach((element) => { + playbackmanager.startPlaying(element, itemID, isSummendByPlay); + }); +} - websocketHanler.openSocket(); +function handleChannelMessage (message) { + getRandomDiscordColor(); - summonMessage(message); + if (message.content.startsWith(CONFIG["discord-prefix"] + "summon")) { + isSummendByPlay = false; + websocketHanler.openSocket(); + summonMessage(message); + } else if (message.content.startsWith(CONFIG["discord-prefix"] + "disconnect")) { + playbackmanager.stop(); + jellyfinClientManager.getJellyfinClient().closeWebSocket(); + discordClient.user.client.voice.connections.forEach((element) => { + element.disconnect(); + }); + } else if ((message.content.startsWith(CONFIG["discord-prefix"] + "pause")) || (message.content.startsWith(CONFIG["discord-prefix"] + "resume"))) { + if (getAudioDispatcher() !== undefined) { + playbackmanager.playPause(); + } else { + message.reply("there is nothing playing!"); + } + } else if (message.content.startsWith(CONFIG["discord-prefix"] + "play")) { + if (discordClient.user.client.voice.connections.size < 1) { + summonMessage(message); + isSummendByPlay = true; + } - } else if (message.content.startsWith(CONFIG["discord-prefix"] + 'disconnect')) { - playbackmanager.stop() - jellyfinClientManager.getJellyfinClient().closeWebSocket(); - discordClient.user.client.voice.connections.forEach((element) => { - element.disconnect(); - }); - - - } else if ((message.content.startsWith(CONFIG["discord-prefix"] + 'pause')) || (message.content.startsWith(CONFIG["discord-prefix"] + 'resume'))) { - if (getAudioDispatcher() !== undefined) { - playbackmanager.playPause(); - } else { - message.reply("there is nothing playing!") - } - - - } else if (message.content.startsWith(CONFIG["discord-prefix"] + 'play')) { - - - if (discordClient.user.client.voice.connections.size < 1) { - summonMessage(message) - isSummendByPlay=true - } - - async function playThis(){ - - let indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + 'play') + (CONFIG["discord-prefix"] + 'play').length + 1; - let argument = message.content.slice(indexOfItemID); - let itemID; - //check if play command was used with itemID - let regexresults = checkJellyfinItemIDRegex(argument); - if (regexresults) { - itemID = regexresults[0]; - } else { - try { - itemID = await searchForItemID(argument); - } catch (e) { - message.reply(e); - playbackmanager.stop(discordClient.user.client.voice.connections.first()); - return; - } - } - - discordClient.user.client.voice.connections.forEach((element) => { - playbackmanager.startPlaying(element,itemID,isSummendByPlay); - }) - } - - playThis(); - - } else if (message.content.startsWith(CONFIG["discord-prefix"] + 'stop')) { - if(isSummendByPlay){ - if(discordClient.user.client.voice.connections.size > 0){ - playbackmanager.stop(discordClient.user.client.voice.connections.first()); - } - }else{ - playbackmanager.stop(); - } - - } else if (message.content.startsWith(CONFIG["discord-prefix"] + 'help')) { - const reply = new Discord.MessageEmbed() - .setColor(getRandomDiscordColor()) - .addFields({ - name: `${CONFIG['discord-prefix']}summon`, - value: 'Join the channel the author of the message' - }, { - name: `${CONFIG['discord-prefix']}disconnect`, - value: 'Disconnect from all current Voice Channels' - }, { - name: `${CONFIG['discord-prefix']}play`, - value: 'Play the following item' - }, { - name: `${CONFIG['discord-prefix']}pause/resume`, - value: 'Pause/Resume audio' - }, { - name: `${CONFIG['discord-prefix']}help`, - value: 'Display this help message' - }) - message.channel.send(reply); - } + playThis(message); + } else if (message.content.startsWith(CONFIG["discord-prefix"] + "stop")) { + if (isSummendByPlay) { + if (discordClient.user.client.voice.connections.size > 0) { + playbackmanager.stop(discordClient.user.client.voice.connections.first()); + } + } else { + playbackmanager.stop(); + } + } else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) { + const reply = new Discord.MessageEmbed() + .setColor(getRandomDiscordColor()) + .addFields({ + name: `${CONFIG["discord-prefix"]}summon`, + value: "Join the channel the author of the message" + }, { + name: `${CONFIG["discord-prefix"]}disconnect`, + value: "Disconnect from all current Voice Channels" + }, { + name: `${CONFIG["discord-prefix"]}play`, + value: "Play the following item" + }, { + name: `${CONFIG["discord-prefix"]}pause/resume`, + value: "Pause/Resume audio" + }, { + name: `${CONFIG["discord-prefix"]}help`, + value: "Display this help message" + }); + message.channel.send(reply); + } } module.exports = { - handleChannelMessage -} \ No newline at end of file + handleChannelMessage +}; diff --git a/src/playbackmanager.js b/src/playbackmanager.js index 58e17b4..3aa6f05 100644 --- a/src/playbackmanager.js +++ b/src/playbackmanager.js @@ -1,156 +1,146 @@ -const { default: fetch } = require('node-fetch'); const { - getAudioDispatcher, - setAudioDispatcher -} = require('./dispachermanager'); + getAudioDispatcher, + setAudioDispatcher +} = require("./dispachermanager"); var currentPlayingItemId; var progressInterval; var isPaused; -const jellyfinClientManager = require('./jellyfinclientmanager'); -function streamURLbuilder(itemID, bitrate) { - //so the server transcodes. Seems appropriate as it has the source file. - let supportedCodecs = "opus" - let supportedContainers = "ogg,opus" - return `${jellyfinClientManager.getJellyfinClient().serverAddress()}/Audio/${itemID}/universal?UserId=${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}&DeviceId=${jellyfinClientManager.getJellyfinClient().deviceId()}&MaxStreamingBitrate=${bitrate}&Container=${supportedContainers}&AudioCodec=${supportedCodecs}&api_key=${jellyfinClientManager.getJellyfinClient().accessToken()}&TranscodingContainer=ts&TranscodingProtocol=hls`; +const jellyfinClientManager = require("./jellyfinclientmanager"); +function streamURLbuilder (itemID, bitrate) { + // so the server transcodes. Seems appropriate as it has the source file. + const supportedCodecs = "opus"; + const supportedContainers = "ogg,opus"; + return `${jellyfinClientManager.getJellyfinClient().serverAddress()}/Audio/${itemID}/universal?UserId=${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}&DeviceId=${jellyfinClientManager.getJellyfinClient().deviceId()}&MaxStreamingBitrate=${bitrate}&Container=${supportedContainers}&AudioCodec=${supportedCodecs}&api_key=${jellyfinClientManager.getJellyfinClient().accessToken()}&TranscodingContainer=ts&TranscodingProtocol=hls`; } -function startPlaying(voiceconnection, itemID, disconnectOnFinish) { - isPaused=false; - async function playasync() { - let url = streamURLbuilder(itemID, voiceconnection.channel.bitrate) - jellyfinClientManager.getJellyfinClient().reportPlaybackStart({ userID: `${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}`, itemID: `${itemID}` }) - currentPlayingItemId = itemID; - setAudioDispatcher(voiceconnection.play(url)); - let time = await jellyfinClientManager.getJellyfinClient().getItem(jellyfinClientManager.getJellyfinClient().getCurrentUserId(),currentPlayingItemId) - async function asfg(){ - jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()) - } - //progressInterval=setInterval(asfg,2000); +function startPlaying (voiceconnection, itemID, disconnectOnFinish) { + isPaused = false; + async function playasync () { + const url = streamURLbuilder(itemID, voiceconnection.channel.bitrate); + jellyfinClientManager.getJellyfinClient().reportPlaybackStart({ userID: `${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}`, itemID: `${itemID}` }); + currentPlayingItemId = itemID; + setAudioDispatcher(voiceconnection.play(url)); - getAudioDispatcher().on("finish", () => { - if (disconnectOnFinish) { - stop(voiceconnection); - }else{ - stop(); - } - }) - } - playasync().catch((rsn) => { console.log(rsn) }); + getAudioDispatcher().on("finish", () => { + if (disconnectOnFinish) { + stop(voiceconnection); + } else { + stop(); + } + }); + } + playasync().catch((rsn) => { console.log(rsn); }); } /** * @param {Object=} disconnectVoiceConnection - Optional The voice Connection do disconnect from */ -function stop(disconnectVoiceConnection) { - isPaused=true; - if (disconnectVoiceConnection) { - disconnectVoiceConnection.disconnect() - } - jellyfinClientManager.getJellyfinClient().reportPlaybackStopped({userId: jellyfinClientManager.getJellyfinClient().getCurrentUserId(),itemId:currentPlayingItemId}) - if(getAudioDispatcher()) - getAudioDispatcher().destroy(); - setAudioDispatcher(undefined); - clearInterval(progressInterval); +function stop (disconnectVoiceConnection) { + isPaused = true; + if (disconnectVoiceConnection) { + disconnectVoiceConnection.disconnect(); + } + jellyfinClientManager.getJellyfinClient().reportPlaybackStopped({ userId: jellyfinClientManager.getJellyfinClient().getCurrentUserId(), itemId: currentPlayingItemId }); + if (getAudioDispatcher()) { getAudioDispatcher().destroy(); } + setAudioDispatcher(undefined); + clearInterval(progressInterval); } -function pause() { - isPaused=true; - console.log('here paused is changed', isPaused); - jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()) - getAudioDispatcher().pause(true); +function pause () { + isPaused = true; + console.log("here paused is changed", isPaused); + jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()); + getAudioDispatcher().pause(true); } -function resume() { - isPaused=false; - jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()) - getAudioDispatcher().resume(); +function resume () { + isPaused = false; + jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()); + getAudioDispatcher().resume(); } -function playPause() { - if (getAudioDispatcher().paused) - resume(); - else - pause(); +function playPause () { + if (getAudioDispatcher().paused) { resume(); } else { pause(); } } -function getPostitionTicks(){ - //this is very sketchy but i dont know how else to do it - return (getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime)*10000; +function getPostitionTicks () { + // this is very sketchy but i dont know how else to do it + return (getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime) * 10000; } -function getPlayMethod(){ - //TODO figure out how to figure this out - return 'Transcode'; +function getPlayMethod () { + // TODO figure out how to figure this out + return "Transcode"; } -function getRepeatMode(){ - return 'RepeatNone'; +function getRepeatMode () { + return "RepeatNone"; } -function getPlaylistItemId(){ - //as I curently dont support Playlists - return 'playlistItem0' +function getPlaylistItemId () { + // as I curently dont support Playlists + return "playlistItem0"; } -function getPlaySessionId(){ - //i think its just a number which you dont need to retrieve but need to report - return 'ae2436edc6b91b11d72aeaa67f84e0ea'; +function getPlaySessionId () { + // i think its just a number which you dont need to retrieve but need to report + return "ae2436edc6b91b11d72aeaa67f84e0ea"; } -function getNowPLayingQueue(){ - return [{ - Id: currentPlayingItemId, - //as I curently dont support Playlists - PlaylistItemId: getPlaylistItemId() - }] +function getNowPLayingQueue () { + return [{ + Id: currentPlayingItemId, + // as I curently dont support Playlists + PlaylistItemId: getPlaylistItemId() + }]; } -function getCanSeek(){ - return false; +function getCanSeek () { + return false; } -function getIsMuted(){ - return false; +function getIsMuted () { + return false; } -function getVolumeLevel(){ - return 100; +function getVolumeLevel () { + return 100; } -function getItemId(){ - return currentPlayingItemId +function getItemId () { + return currentPlayingItemId; } -function getIsPaused(){ - //AudioDispacker Paused is to slow +function getIsPaused () { + // AudioDispacker Paused is to slow - if(isPaused == undefined){ - isPaused=false; - } - - return isPaused; + if (isPaused === undefined) { + isPaused = false; + } + + return isPaused; } -function getProgressPayload(){ - let payload= { - CanSeek: getCanSeek(), - IsMuted: getIsMuted(), - IsPaused: getIsPaused(), - ItemId: getItemId(), - MediaSourceId: getItemId(), - NowPlayingQueue: getNowPLayingQueue(), - PlayMethod: getPlayMethod(), - PlaySessionId: getPlaySessionId(), - PlaylistItemId: getPlaylistItemId(), - PositionTicks: getPostitionTicks(), - RepeatMode: getRepeatMode(), - VolumeLevel: getVolumeLevel() - } - return payload +function getProgressPayload () { + const payload = { + CanSeek: getCanSeek(), + IsMuted: getIsMuted(), + IsPaused: getIsPaused(), + ItemId: getItemId(), + MediaSourceId: getItemId(), + NowPlayingQueue: getNowPLayingQueue(), + PlayMethod: getPlayMethod(), + PlaySessionId: getPlaySessionId(), + PlaylistItemId: getPlaylistItemId(), + PositionTicks: getPostitionTicks(), + RepeatMode: getRepeatMode(), + VolumeLevel: getVolumeLevel() + }; + return payload; } module.exports = { - startPlaying, - stop, - playPause, - resume, - pause -} \ No newline at end of file + startPlaying, + stop, + playPause, + resume, + pause +}; diff --git a/src/util.js b/src/util.js index de6abd9..5a5eeb6 100644 --- a/src/util.js +++ b/src/util.js @@ -1,8 +1,8 @@ -function checkJellyfinItemIDRegex(strgintomatch){ - let regexresult=strgintomatch.match(/([0-9]|[a-f]){32}/); - return regexresult; +function checkJellyfinItemIDRegex (strgintomatch) { + const regexresult = strgintomatch.match(/([0-9]|[a-f]){32}/); + return regexresult; } -module.exports={ - checkJellyfinItemIDRegex -} \ No newline at end of file +module.exports = { + checkJellyfinItemIDRegex +}; diff --git a/src/websockethandler.js b/src/websockethandler.js index 24ea03d..fab35ab 100644 --- a/src/websockethandler.js +++ b/src/websockethandler.js @@ -1,38 +1,37 @@ -const jellyfinClientManager = require('./jellyfinclientmanager'); -const discordclientmanager = require('./discordclientmanager'); -const playbackmanager = require('./playbackmanager'); +const jellyfinClientManager = require("./jellyfinclientmanager"); +const discordclientmanager = require("./discordclientmanager"); +const playbackmanager = require("./playbackmanager"); - -function openSocket() { - jellyfinClientManager.getJellyfinClient().openWebSocket(); - jellyfinClientManager.getJellyfinClient().reportCapabilities( - { - 'PlayableMediaTypes': "Audio", - 'SupportsMediaControl': "True", - 'SupportedCommands': "Play,Playstate" - } - ); - jellyfinClientManager.getJellyfinEvents().on(jellyfinClientManager.getJellyfinClient(), "message", (type, data) => { - //console.log(data); - if (data.MessageType == 'Play') { - if (data.Data.PlayCommand == 'PlayNow') { - discordclientmanager.getDiscordClient().user.client.voice.connections.forEach((element) => { - playbackmanager.startPlaying(element, data.Data.ItemIds[data.Data.StartIndex||0], false); - element.on("error", (error) => { - console.error(error); - }); - }); - } - }else if(data.MessageType == 'Playstate'){ - if(data.Data.Command == 'PlayPause'){ - playbackmanager.playPause(); - }else if(data.Data.Command == 'Stop'){ - playbackmanager.stop(); - } - } - }); +function openSocket () { + jellyfinClientManager.getJellyfinClient().openWebSocket(); + jellyfinClientManager.getJellyfinClient().reportCapabilities( + { + PlayableMediaTypes: "Audio", + SupportsMediaControl: "True", + SupportedCommands: "Play,Playstate" + } + ); + jellyfinClientManager.getJellyfinEvents().on(jellyfinClientManager.getJellyfinClient(), "message", (type, data) => { + // console.log(data); + if (data.MessageType === "Play") { + if (data.Data.PlayCommand === "PlayNow") { + discordclientmanager.getDiscordClient().user.client.voice.connections.forEach((element) => { + playbackmanager.startPlaying(element, data.Data.ItemIds[data.Data.StartIndex || 0], false); + element.on("error", (error) => { + console.error(error); + }); + }); + } + } else if (data.MessageType === "Playstate") { + if (data.Data.Command === "PlayPause") { + playbackmanager.playPause(); + } else if (data.Data.Command === "Stop") { + playbackmanager.stop(); + } + } + }); } module.exports = { - openSocket -} \ No newline at end of file + openSocket +};