Skip to content

Commit 7b3d6e0

Browse files
committed
Added alert graphic for Channel Points
1 parent 88deeb5 commit 7b3d6e0

File tree

7 files changed

+173
-7
lines changed

7 files changed

+173
-7
lines changed

Fritz.Chatbot/AttentionHub.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public interface IAttentionHubClient
1212

1313
// Cheer 200 parithon 12/18/2018
1414
// Cheer 500 pharewings 12/18/2018
15-
Task AlertFritz();
16-
Task ClientConnected(string connectionId);
17-
Task SummonScott();
15+
Task AlertFritz();
16+
Task ClientConnected(string connectionId);
17+
Task SummonScott();
1818

19-
Task PlaySoundEffect(string fileName);
19+
Task PlaySoundEffect(string fileName);
20+
21+
Task NotifyChannelPoints(ChannelPointRedemption redemption);
2022

2123
}
2224

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Fritz.StreamLib.Core
6+
{
7+
public class ChannelPointRedemption
8+
{
9+
10+
public string RedeemingUserName { get; set; }
11+
12+
public string RedeemingUserId { get; set; }
13+
14+
public string RewardName { get; set; }
15+
16+
public int RewardValue { get; set; }
17+
18+
public string RewardPrompt { get; set; }
19+
20+
public string BackgroundColor { get; set; }
21+
22+
public Uri Image_1x { get; set; }
23+
24+
public Uri Image_2x { get; set; }
25+
26+
public Uri Image_4x { get; set; }
27+
28+
}
29+
}

Fritz.StreamTools/Controllers/AttentionController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public IActionResult Index()
1313
return View();
1414
}
1515

16+
public IActionResult Points() {
17+
return View();
18+
}
19+
1620
public IActionResult TestClient()
1721
{
1822
return View();

Fritz.StreamTools/Services/TwitchPubSubService.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Fritz.StreamTools.Hubs;
1+
using Fritz.StreamLib.Core;
2+
using Fritz.StreamTools.Hubs;
23
using Fritz.Twitch;
34
using Fritz.Twitch.PubSub;
45
using Microsoft.AspNetCore.SignalR;
@@ -39,7 +40,20 @@ private void _Proxy_OnChannelPointsRedeemed(object sender, ChannelRedemption e)
3940
using (var scope = _ServiceProvider.CreateScope())
4041
{
4142
var context = scope.ServiceProvider.GetRequiredService<IHubContext<AttentionHub, IAttentionHubClient>>();
42-
context.Clients.All.PlaySoundEffect("pointsredeemed.mp3");
43+
//context.Clients.All.PlaySoundEffect("pointsredeemed.mp3");
44+
var redemption = new ChannelPointRedemption
45+
{
46+
RedeemingUserName = e.redemption.user.display_name,
47+
RedeemingUserId = e.redemption.user.id,
48+
RewardName = e.redemption.reward.title,
49+
RewardValue = e.redemption.reward.cost,
50+
RewardPrompt = e.redemption.user_input,
51+
BackgroundColor = e.redemption.reward.background_color,
52+
Image_1x = new Uri(e.redemption.reward.image?.url_1x ?? e.redemption.reward.default_image.url_1x),
53+
Image_2x = new Uri(e.redemption.reward.image?.url_2x ?? e.redemption.reward.default_image.url_2x),
54+
Image_4x = new Uri(e.redemption.reward.image?.url_4x ?? e.redemption.reward.default_image.url_4x)
55+
};
56+
context.Clients.All.NotifyChannelPoints(redemption);
4357
}
4458
}
4559

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
@{
2+
Layout = null;
3+
}
4+
5+
<!DOCTYPE html>
6+
7+
<html>
8+
<head>
9+
<title>Channel Points Alert</title>
10+
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
11+
<style>
12+
13+
#Alert * {
14+
font-family: 'Roboto', Arial;
15+
font-weight: bold;
16+
font-size: 42px;
17+
color: #FFF;
18+
text-shadow: 1px 1px 1px #000;
19+
}
20+
21+
@@keyframes fadeIn {
22+
0% {
23+
opacity: 0;
24+
}
25+
26+
100% {
27+
opacity: 1;
28+
}
29+
}
30+
31+
@@keyframes fadeOut {
32+
0% {
33+
opacity: 1;
34+
}
35+
36+
100% {
37+
opacity: 0;
38+
}
39+
}
40+
41+
.fadeIn {
42+
animation-name: fadeIn;
43+
animation-duration: 1s;
44+
animation-fill-mode: both;
45+
}
46+
47+
.fadeOut {
48+
animation-name: fadeOut;
49+
animation-duration: 1s;
50+
animation-fill-mode: both;
51+
}
52+
</style>
53+
54+
</head>
55+
<body>
56+
57+
<div id="Alert">
58+
59+
<table>
60+
<tr>
61+
<td>
62+
<div id="alertImgBg"><img id="alertImg" /></div>
63+
</td>
64+
<td>
65+
<p><span id="user"></span> has just redeemed</p>
66+
<p><span id="reward"></span> for <span id="rewardValue"></span> Fritz Bitz</p>
67+
<p id="rewardPrompt"></p>
68+
</td>
69+
</tr>
70+
</table>
71+
72+
</div>
73+
74+
75+
<script src="~/lib/signalr/signalr-client.js"></script>
76+
<script src="~/js/attentionhub.js"></script>
77+
78+
<script>
79+
var audio = new Audio('@Url.Content(@"~/contents/pointsredeemed.mp3")');
80+
81+
var alertEl = document.getElementById("Alert");
82+
83+
var hub = new AttentionHub();
84+
hub.onRedemption = (redemption) => {
85+
86+
document.getElementById("user").textContent = redemption.RedeemingUserName;
87+
document.getElementById("reward").textContent = redemption.RewardName;
88+
document.getElementById("rewardValue").textContent = redemption.RewardValue;
89+
document.getElementById("rewardPrompt").textContent = redemption.RewardPrompt;
90+
document.getElementById("alertImg").src = redemption.Image_4x;
91+
document.getElementById("alertImgBg").style.backgroundColor = redemption.BackgroundColor;
92+
93+
alertEl.classList.remove("fadeOut");
94+
alertEl.classList.add("fadeIn");
95+
audio.play();
96+
97+
window.setTimeout(function () {
98+
alertEl.classList.remove("fadeIn");
99+
alertEl.classList.add("fadeOut");
100+
}, 5000);
101+
}
102+
103+
(function () {
104+
alertEl.classList.add("fadeOut");
105+
hub.start();
106+
})();
107+
108+
</script>
109+
</body>
110+
</html>

Fritz.StreamTools/wwwroot/js/attentionhub.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ class AttentionHub {
4444
this._hub.on("PlaySoundEffect", (fileName) => {
4545
if (this.debug) console.debug(`Playing file: ${fileName}`);
4646
if (this.onPlaySoundEffect) this.onPlaySoundEffect(fileName);
47-
});
47+
});
48+
49+
this._hub.on("NotifyChannelPoints", redemption => {
50+
if (this.debug) console.debug(`Redeemed: ${redemption}`);
51+
if (this.onRedemption) this.onRedemption(redemption);
52+
});
4853

4954

5055
return this._hub.start();

Fritz.Twitch/PubSub/Proxy.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private bool HandlePongMessage(string message) {
189189
_PingAcknowledged = true;
190190
_PongTimer.Stop();
191191
_PongTimer.Dispose();
192+
_Logger.LogDebug("TwitchPubSub PONG received successfully");
192193
return true;
193194
}
194195

@@ -225,6 +226,7 @@ private bool HandleChannelPointsMessage(string message) {
225226
_Logger.LogError(e, "Error while deserializing the message");
226227
_Logger.LogInformation("Message contents: " + innerMessage);
227228
}
229+
_Logger.LogWarning($"Channel Points redeemed: {innerMessage}");
228230
OnChannelPointsRedeemed?.Invoke(null, messageObj?.data);
229231
return true;
230232

0 commit comments

Comments
 (0)