Skip to content

Commit 9e052ee

Browse files
committed
Added twitch stream title the stream category icon in live portal
1 parent d78a6e7 commit 9e052ee

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

extensions/liveportal/views/scripts/datahandler.ejs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
const default_serverConfig = {
3232
// version number only needs updating if changing or deleting a variable.
3333
// new variables do not need the version updated.
34-
__version__: "0.6",
34+
__version__: "0.7",
3535
// extensions vars
3636
extensionname: "liveportal",
3737
channel: "LIVE_PORTAL",
@@ -75,9 +75,32 @@
7575
currentchatAsPlatform: "twitch",
7676
7777
// ##### settings widget variables
78+
7879
// TTS settings
7980
TTSVoiceFilter: "English", // filter out voices you are interested in
80-
//twith tts
81+
82+
// #################################################
83+
// Partially updated code, needs finishing
84+
// the tts data following this object should be updated to all come from this structure.
85+
platformData:
86+
{
87+
twitch:
88+
{
89+
streamCategory: "",
90+
streamCategoryImageCode: "",
91+
streamTitle: "",
92+
//twitch tts
93+
/*
94+
TTStwitchenabled: "off",
95+
TTSVolume: "1",
96+
TTSBlackList: "",
97+
TTSVoiceName: "Please select a windows voice",
98+
TTSVoiceIndex: -1,
99+
*/
100+
}
101+
102+
},
103+
//twitch tts
81104
winttstwitchenabled: "off",
82105
twitchTTSVolume: "1",
83106
twitchBlackList: "",
@@ -95,6 +118,9 @@
95118
kickBlackList: "",
96119
kickTTSVoiceName: "Please select a windows voice",
97120
kickTTSVoiceIndex: -1,
121+
122+
// Partially updated code end comment
123+
// #################################################
98124
// random facts twitter settings
99125
randomfactsenabled: "on",
100126
randomfactstimeout: 1800000,//30 min
@@ -1067,11 +1093,17 @@
10671093
}
10681094
else if (extension_packet.type === "trigger_TwitchGamedChanged")
10691095
{
1070-
let ele = document.getElementById("liveportaltitleTwitchCategoryImage")
10711096
let imagecode = extension_packet.data.parameters.imageURL.replace("{width}", 30).replace("{height}", 30)
1072-
ele.title = extension_packet.data.parameters.name;
1073-
ele.innerHTML = "<img style='border: 5px solid #6441a5; border-radius:50%' src='" + imagecode + "'>"
1097+
serverConfig.platformData.twitch.streamCategory = extension_packet.data.parameters.name;
1098+
serverConfig.platformData.twitch.streamCategoryImageCode = imagecode
1099+
updateTwitchCategoryAndTitle()
10741100
}
1101+
else if (extension_packet.type === "trigger_TwitchTitleChanged")
1102+
{
1103+
serverConfig.platformData.twitch.streamTitle = extension_packet.data.parameters.title
1104+
updateTwitchCategoryAndTitle();
1105+
}
1106+
10751107
}
10761108
// -------------------------------------------------------------------------------------------------
10771109
// DISCORD_CHAT
@@ -3989,7 +4021,7 @@
39894021
sr_api.ExtensionPacket(
39904022
"action_youtubeAPIPostLiveChatMessage",
39914023
serverConfig.extensionname,
3992-
// need to read accounts from twitchchat ext and give an option to chose who to send the message as
4024+
// need to read accounts from youtube ext and give an option to chose who to send the message as
39934025
{
39944026
platform: "youtube",
39954027
message: msg,
@@ -4006,7 +4038,7 @@
40064038
sr_api.ExtensionPacket(
40074039
"action_youtubePostLiveChatMessage",
40084040
serverConfig.extensionname,
4009-
// need to read accounts from twitchchat ext and give an option to chose who to send the message as
4041+
// need to read accounts from youtube ext and give an option to chose who to send the message as
40104042
{
40114043
platform: "youtube",
40124044
message: msg,
@@ -4729,4 +4761,16 @@
47294761
sr_api.ServerPacket("ExtensionReady", serverConfig.extensionname));
47304762
startupRequests()
47314763
}
4764+
// ============================================================================
4765+
// FUNCTION: updateTwitchCategoryAndTitle
4766+
// ============================================================================
4767+
/**
4768+
*
4769+
*/
4770+
function updateTwitchCategoryAndTitle ()
4771+
{
4772+
let ele = document.getElementById("liveportaltitleTwitchCategoryImage")
4773+
ele.title = serverConfig.platformData.twitch.streamCategory + " : " + serverConfig.platformData.twitch.streamTitle;
4774+
ele.innerHTML = "<img style='border: 5px solid #6441a5; border-radius:50%' src='" + serverConfig.platformData.twitch.streamCategoryImageCode + "'>"
4775+
}
47324776
</script>

extensions/twitch/server/server.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const localConfig =
6060
twitchCategoryErrorsText: "",
6161
twitchCategoryErrorsShowCounter: 0,
6262
currentTwitchGameCategoryId: -1, // as reported by twitch
63+
currentTwitchStreamTitle: "", // as reported by twitch
6364

6465
sendUserTwitchChatCredentialsTimeout: 5000,
6566
sendUserTwitchChatCredentialsHandle: null,
@@ -2196,7 +2197,7 @@ function onDataCenterMessage (server_packet)
21962197
// -----------------------------------------------------------------------------------
21972198
else if (extension_packet.type === "action_GetTwitchStats")
21982199
{
2199-
sendCurrentGameData(extension_packet.data.actionID)
2200+
sendTwitchStats(extension_packet.data.actionID)
22002201
}
22012202
// -----------------------------------------------------------------------------------
22022203
// action_GetTwitchStats
@@ -2629,6 +2630,7 @@ async function connectTwitch ()
26292630

26302631
// set our current game id and add it to the history
26312632
localConfig.currentTwitchGameCategoryId = channelData.gameId;
2633+
localConfig.currentTwitchStreamTitle = channelData.title;
26322634
// need to do this here as we don't have the game image in the current data.
26332635
addGameToHistoryFromGameName(channelData.gameName)
26342636
// Connect to the pub sub event listener
@@ -2645,7 +2647,7 @@ async function connectTwitch ()
26452647
//to start up (if we have just started the server)
26462648
setTimeout(() =>
26472649
{
2648-
sendCurrentGameData("twitch")
2650+
sendTwitchStats("twitch")
26492651
}, 5000);
26502652

26512653
})
@@ -4021,13 +4023,13 @@ function sendGameCategoriesTrigger (id = "twitch")
40214023
sendTrigger(trigger)
40224024
}
40234025
// ===========================================================================
4024-
// FUNCTION: sendCurrentGameData
4026+
// FUNCTION: sendTwitchStats
40254027
// ===========================================================================
40264028
/**
40274029
* sends trigger_TwitchGamedChanged
40284030
* @param {number} [triggerId="twitch"] ref id from action
40294031
*/
4030-
function sendCurrentGameData (triggerId = "twitch")
4032+
function sendTwitchStats (triggerId = "twitch")
40314033
{
40324034
let trigger = findTriggerByMessageType("trigger_TwitchGamedChanged");
40334035
const game = serverConfig.twitchCategoriesHistory.find(e => e.id === localConfig.currentTwitchGameCategoryId);
@@ -4036,6 +4038,14 @@ function sendCurrentGameData (triggerId = "twitch")
40364038
trigger.parameters = { triggerId: triggerId, id: game.id, name: game.name, imageURL: game.imageURL }
40374039
sendTrigger(trigger)
40384040
}
4041+
4042+
trigger = findTriggerByMessageType("trigger_TwitchTitleChanged");
4043+
if (game)
4044+
{
4045+
trigger.parameters = { triggerId: triggerId, title: localConfig.currentTwitchStreamTitle }
4046+
sendTrigger(trigger)
4047+
}
4048+
40394049
}
40404050
// ===========================================================================
40414051
// FUNCTION: raidChannel
@@ -4083,6 +4093,16 @@ function pubSubTriggerCallback (trigger)
40834093
//save the serverConfig so we remember the changes
40844094
SaveConfigToServer()
40854095
}
4096+
else if (trigger.messagetype == "trigger_TwitchTitleChanged")
4097+
{
4098+
// change our setup so it matches the data from twitch
4099+
localConfig.currentTwitchStreamTitle = trigger.parameters.title;
4100+
4101+
//update any of our modals
4102+
SendSettingsWidgetSmall()
4103+
//save the serverConfig so we remember the changes
4104+
SaveConfigToServer()
4105+
}
40864106
else
40874107
logger.log(localConfig.SYSTEM_LOGGING_TAG + serverConfig.extensionname + ".getClipById", "pubSubTriggerCallback() no handler for ", trigger.messagetype, " twitch callback message");
40884108
}

0 commit comments

Comments
 (0)