mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-23 18:21:55 +01:00
add websocket handler
This commit is contained in:
parent
715eee0a5f
commit
e6d8db86f6
38
src/websockethandler.js
Normal file
38
src/websockethandler.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
openSocket
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user