fix all lint errors

This commit is contained in:
KGT1 2020-09-21 05:30:39 +02:00
parent 31420a22cc
commit f020613759
11 changed files with 327 additions and 358 deletions

View File

@ -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}]
}
}
}

View File

@ -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",

View File

@ -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);
});
fs.writeFile(filename, JSON.stringify(configfile, null, 1), (err) => {
if (err) return console.log(err);
});

View File

@ -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
};

View File

@ -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
}
setAudioDispatcher,
getAudioDispatcher
};

View File

@ -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);
discordClient.login(CONFIG.token);

View File

@ -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
}
getJellyfinClient,
getJellyfinEvents,
init
};

View File

@ -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
}
handleChannelMessage
};

View File

@ -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
}
startPlaying,
stop,
playPause,
resume,
pause
};

View File

@ -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
}
module.exports = {
checkJellyfinItemIDRegex
};

View File

@ -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
}
openSocket
};