Skip to content

Commit 8696f78

Browse files
committed
added Notifications
1 parent 95497c3 commit 8696f78

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

Emby.Webhooks/Configuration/PluginConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class Hook
2525
public bool withMovies { get; set; }
2626
public bool withEpisodes { get; set; }
2727
public bool withSongs { get; set; }
28+
public bool withNotifications { get; set; }
2829
}
2930
}
3031
}

Emby.Webhooks/Configuration/config.html

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ <h3>Events</h3>
3636
<input is="emby-checkbox" type="checkbox" class="chkOnResume" />
3737
<span>Resume</span>
3838
</label>
39+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
40+
<input is="emby-checkbox" type="checkbox" class="chkNotifications" />
41+
<span>Notifications</span>
42+
</label>
3943
</div>
4044
<div>
4145
<h3>Media Types</h3>
@@ -52,6 +56,13 @@ <h3>Media Types</h3>
5256
<span>Songs</span>
5357
</label>
5458
</div>
59+
<div><h3>Notifications</h3>
60+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
61+
<input is="emby-checkbox" type="checkbox" class="chkNotifications" />
62+
<span>Notifications</span>
63+
</label>
64+
</div>
65+
5566
</div>
5667
<button title="Delete" class="btnDeleteDevice paper-icon-button-light removeHook" type="button" is="paper-icon-button-light"><i class="md-icon">delete</i></button>
5768

@@ -62,7 +73,7 @@ <h3>Media Types</h3>
6273
<div class="content-primary">
6374

6475
<form class="smtpConfigurationForm">
65-
<div id="itemTemplate" class="paperList" style="display:none;">
76+
<!-- <div id="itemTemplate" class="paperList" style="display:none;">
6677
<div class="listItem">
6778
<div class="listItemBody two-line">
6879
<div>
@@ -86,6 +97,10 @@ <h3>Events</h3>
8697
<input is="emby-checkbox" type="checkbox" class="chkOnResume" />
8798
<span>Resume</span>
8899
</label>
100+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
101+
<input is="emby-checkbox" type="checkbox" class="chkNotifications" />
102+
<span>Notifications</span>
103+
</label>
89104
</div>
90105
<div>
91106
<h3>Media Types</h3>
@@ -102,11 +117,13 @@ <h3>Media Types</h3>
102117
<span>Songs</span>
103118
</label>
104119
</div>
120+
121+
105122
</div>
106123
<button title="Delete" class="btnDeleteDevice paper-icon-button-light removeHook" type="button" is="paper-icon-button-light"><i class="md-icon">delete</i></button>
107124
108125
</div>
109-
</div>
126+
</div> -->
110127

111128

112129
<!--
@@ -166,12 +183,12 @@ <h1 style="display:inline-block;vertical-align:middle;">Webhooks</h1>
166183
$('#testNotification', page).on('click', function (event) {
167184

168185
Dashboard.showLoadingMsg();
169-
var a = $('#itemTemplate').html();
186+
var a = $('#itemTemplate').clone();
170187

171-
var b =$('#Hooks', page).append(
188+
$('#Hooks', page).append(
172189
a
173190
);
174-
$(b).show();
191+
$(a).show();
175192

176193
Dashboard.hideLoadingMsg();
177194

@@ -199,7 +216,8 @@ <h1 style="display:inline-block;vertical-align:middle;">Webhooks</h1>
199216
withMovies: $(this).find('.chkMovies').first().checked(),
200217
withEpisodes: $(this).find('.chkEpisodes').first().checked(),
201218
withSongs: $(this).find('.chkSongs').first().checked(),
202-
219+
withNotifications: $(this).find('.chkNotifications').first().checked()
220+
203221
}
204222
);
205223
});
@@ -241,6 +259,8 @@ <h1 style="display:inline-block;vertical-align:middle;">Webhooks</h1>
241259
$(a).find('.chkMovies').first().checked(config.Hooks[i].withMovies || false);
242260
$(a).find('.chkEpisodes').first().checked(config.Hooks[i].withEpisodes || false);
243261
$(a).find('.chkSongs').first().checked(config.Hooks[i].withSongs || false);
262+
$(a).find('.chkNotifications').first().checked(config.Hooks[i].withNotifications || false);
263+
244264

245265

246266
}

Emby.Webhooks/Webhooks.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
using MediaBrowser.Model.Serialization;
1414
using MediaBrowser.Common.Net;
1515
using System.Net.Http;
16+
using MediaBrowser.Controller.Notifications;
17+
using MediaBrowser.Controller.Entities;
18+
using System.Threading;
1619

1720
namespace Emby.Webhooks
1821
{
1922

20-
class Webhooks : IServerEntryPoint
23+
public class Webhooks : IServerEntryPoint, INotificationService
2124
{
2225
private readonly ISessionManager _sessionManager;
2326
private readonly IUserDataManager _userDataManager;
@@ -44,6 +47,11 @@ public PauseControl getPauseControl(string deviceId)
4447

4548
public static Webhooks Instance { get; private set; }
4649

50+
public string Name
51+
{
52+
get{ return "Webhooks";}
53+
}
54+
4755
public Webhooks(ISessionManager sessionManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IUserDataManager userDataManager)
4856
{
4957
_logger = logManager.GetLogger(Plugin.Instance.Name);
@@ -205,5 +213,29 @@ public string buildJson (PlaybackProgressEventArgs e, string trigger)
205213
return (sr.ReadToEnd());
206214
*/
207215
}
216+
217+
public Task SendNotification(UserNotification request, CancellationToken cancellationToken)
218+
{
219+
return SendNotifcationHook(request);
220+
}
221+
222+
public async Task<bool> SendNotifcationHook(UserNotification request)
223+
{
224+
var hooks = Plugin.Instance.Configuration.Hooks.Where(i => i.withNotifications);
225+
var json = _jsonSerializer.SerializeToString(request);
226+
_logger.Debug(json);
227+
228+
foreach (var h in hooks)
229+
{
230+
await SendHooks(h, json);
231+
}
232+
return true;
233+
}
234+
235+
public bool IsEnabledForUser(User user)
236+
{
237+
238+
return user.Policy.IsAdministrator;
239+
}
208240
}
209241
}

0 commit comments

Comments
 (0)