@@ -81,6 +81,10 @@ public class EventSubWebsocketClient
81
81
/// </summary>
82
82
public event AsyncEventHandler < ChannelChatMessageDeleteArgs > ChannelChatMessageDelete ;
83
83
/// <summary>
84
+ /// Event that triggers on "channel.chat.notification" notifications
85
+ /// </summary>
86
+ public event AsyncEventHandler < ChannelChatNotificationArgs > ChannelChatNotification ;
87
+ /// <summary>
84
88
/// Event that triggers on "channel.cheer" notifications
85
89
/// </summary>
86
90
public event AsyncEventHandler < ChannelCheerArgs > ChannelCheer ;
@@ -339,7 +343,7 @@ public class EventSubWebsocketClient
339
343
/// <param name="serviceProvider">DI Container to resolve other dependencies dynamically</param>
340
344
/// <param name="websocketClient">Underlying Websocket client to connect to connect to EventSub Websocket service</param>
341
345
/// <exception cref="ArgumentNullException">Throws ArgumentNullException if a dependency is null</exception>
342
- public EventSubWebsocketClient ( ILogger < EventSubWebsocketClient > logger , IEnumerable < INotificationHandler > handlers , IServiceProvider serviceProvider , WebsocketClient websocketClient )
346
+ public EventSubWebsocketClient ( ILogger < EventSubWebsocketClient > logger , IEnumerable < INotificationHandler > handlers , IServiceProvider serviceProvider , WebsocketClient websocketClient )
343
347
{
344
348
_logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
345
349
_serviceProvider = serviceProvider ?? throw new ArgumentNullException ( nameof ( serviceProvider ) ) ;
@@ -358,7 +362,7 @@ public EventSubWebsocketClient(ILogger<EventSubWebsocketClient> logger, IEnumera
358
362
/// Instantiates an EventSubWebsocketClient used to subscribe to EventSub notifications via Websockets.
359
363
/// </summary>
360
364
/// <param name="loggerFactory">LoggerFactory used to construct Loggers for the EventSubWebsocketClient and underlying classes</param>
361
- public EventSubWebsocketClient ( ILoggerFactory loggerFactory = null )
365
+ public EventSubWebsocketClient ( ILoggerFactory loggerFactory = null )
362
366
{
363
367
_loggerFactory = loggerFactory ;
364
368
@@ -390,7 +394,7 @@ public EventSubWebsocketClient(ILoggerFactory loggerFactory = null)
390
394
/// </summary>
391
395
/// <param name="url">Optional url param to be able to connect to reconnect urls provided by Twitch or test servers</param>
392
396
/// <returns>true: Connection successful false: Connection failed</returns>
393
- public async Task < bool > ConnectAsync ( Uri url = null )
397
+ public async Task < bool > ConnectAsync ( Uri url = null )
394
398
{
395
399
url = url ?? new Uri ( WEBSOCKET_URL ) ;
396
400
_lastReceived = DateTimeOffset . MinValue ;
@@ -413,7 +417,7 @@ public async Task<bool> ConnectAsync(Uri url = null)
413
417
/// Disconnect from Twitch EventSub Websockets
414
418
/// </summary>
415
419
/// <returns>true: Disconnect successful false: Disconnect failed</returns>
416
- public async Task < bool > DisconnectAsync ( )
420
+ public async Task < bool > DisconnectAsync ( )
417
421
{
418
422
_cts ? . Cancel ( ) ;
419
423
return await _websocketClient . DisconnectAsync ( ) ;
@@ -423,7 +427,7 @@ public async Task<bool> DisconnectAsync()
423
427
/// Reconnect to Twitch EventSub Websockets with a Twitch given Url
424
428
/// </summary>
425
429
/// <returns>true: Reconnect successful false: Reconnect failed</returns>
426
- public Task < bool > ReconnectAsync ( )
430
+ public Task < bool > ReconnectAsync ( )
427
431
{
428
432
return ReconnectAsync ( new Uri ( WEBSOCKET_URL ) ) ;
429
433
}
@@ -433,7 +437,7 @@ public Task<bool> ReconnectAsync()
433
437
/// </summary>
434
438
/// <param name="url">New Websocket Url to connect to, to preserve current session and topics</param>
435
439
/// <returns>true: Reconnect successful false: Reconnect failed</returns>
436
- private async Task < bool > ReconnectAsync ( Uri url )
440
+ private async Task < bool > ReconnectAsync ( Uri url )
437
441
{
438
442
url = url ?? new Uri ( WEBSOCKET_URL ) ;
439
443
@@ -505,7 +509,7 @@ private async Task<bool> ReconnectAsync(Uri url)
505
509
/// Setup handlers for all supported subscription types
506
510
/// </summary>
507
511
/// <param name="handlers">Enumerable of handlers that are responsible for acting on a specified subscription type</param>
508
- private void PrepareHandlers ( IEnumerable < INotificationHandler > handlers )
512
+ private void PrepareHandlers ( IEnumerable < INotificationHandler > handlers )
509
513
{
510
514
_handlers = _handlers ?? new Dictionary < string , Action < EventSubWebsocketClient , string , JsonSerializerOptions > > ( ) ;
511
515
@@ -525,7 +529,7 @@ private void PrepareHandlers(IEnumerable<INotificationHandler> handlers)
525
529
/// <para>E.g. a Twitch specified 10 seconds minimum frequency would result in 12 seconds used by the client to honor network latencies and so on.</para>
526
530
/// </summary>
527
531
/// <returns>a Task that represents the background operation</returns>
528
- private async Task ConnectionCheckAsync ( )
532
+ private async Task ConnectionCheckAsync ( )
529
533
{
530
534
while ( _cts != null && _websocketClient . IsConnected && ! _cts . IsCancellationRequested )
531
535
{
@@ -547,7 +551,7 @@ private async Task ConnectionCheckAsync()
547
551
/// </summary>
548
552
/// <param name="sender">Sender of the event. In this case <see cref="WebsocketClient"/></param>
549
553
/// <param name="e">EventArgs send with the event. <see cref="DataReceivedArgs"/></param>
550
- private async Task OnDataReceived ( object sender , DataReceivedArgs e )
554
+ private async Task OnDataReceived ( object sender , DataReceivedArgs e )
551
555
{
552
556
_lastReceived = DateTimeOffset . Now ;
553
557
@@ -592,7 +596,7 @@ private async Task OnDataReceived(object sender, DataReceivedArgs e)
592
596
/// </summary>
593
597
/// <param name="sender">Sender of the event. In this case <see cref="WebsocketClient"/></param>
594
598
/// <param name="e">EventArgs send with the event. <see cref="ErrorOccuredArgs"/></param>
595
- private async Task OnErrorOccurred ( object sender , ErrorOccuredArgs e )
599
+ private async Task OnErrorOccurred ( object sender , ErrorOccuredArgs e )
596
600
{
597
601
await ErrorOccurred . InvokeAsync ( this , e ) ;
598
602
}
@@ -601,7 +605,7 @@ private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e)
601
605
/// Handles 'session_reconnect' notifications
602
606
/// </summary>
603
607
/// <param name="message">notification message received from Twitch EventSub</param>
604
- private void HandleReconnect ( string message )
608
+ private void HandleReconnect ( string message )
605
609
{
606
610
_logger ? . LogReconnectRequested ( SessionId ) ;
607
611
var data = JsonSerializer . Deserialize < EventSubWebsocketSessionInfoMessage > ( message , _jsonSerializerOptions ) ;
@@ -616,7 +620,7 @@ private void HandleReconnect(string message)
616
620
/// Handles 'session_welcome' notifications
617
621
/// </summary>
618
622
/// <param name="message">notification message received from Twitch EventSub</param>
619
- private async ValueTask HandleWelcome ( string message )
623
+ private async ValueTask HandleWelcome ( string message )
620
624
{
621
625
var data = JsonSerializer . Deserialize < EventSubWebsocketSessionInfoMessage > ( message , _jsonSerializerOptions ) ;
622
626
@@ -640,7 +644,7 @@ private async ValueTask HandleWelcome(string message)
640
644
/// Handles 'session_disconnect' notifications
641
645
/// </summary>
642
646
/// <param name="message">notification message received from Twitch EventSub</param>
643
- private async Task HandleDisconnect ( string message )
647
+ private async Task HandleDisconnect ( string message )
644
648
{
645
649
var data = JsonSerializer . Deserialize < EventSubWebsocketSessionInfoMessage > ( message ) ;
646
650
@@ -654,7 +658,7 @@ private async Task HandleDisconnect(string message)
654
658
/// Handles 'session_keepalive' notifications
655
659
/// </summary>
656
660
/// <param name="message">notification message received from Twitch EventSub</param>
657
- private void HandleKeepAlive ( string message )
661
+ private void HandleKeepAlive ( string message )
658
662
{
659
663
_logger ? . LogMessage ( message ) ;
660
664
}
@@ -664,7 +668,7 @@ private void HandleKeepAlive(string message)
664
668
/// </summary>
665
669
/// <param name="message">notification message received from Twitch EventSub</param>
666
670
/// <param name="subscriptionType">subscription type received from Twitch EventSub</param>
667
- private void HandleNotification ( string message , string subscriptionType )
671
+ private void HandleNotification ( string message , string subscriptionType )
668
672
{
669
673
if ( _handlers != null && _handlers . TryGetValue ( subscriptionType , out var handler ) )
670
674
handler ( this , message , _jsonSerializerOptions ) ;
@@ -676,7 +680,7 @@ private void HandleNotification(string message, string subscriptionType)
676
680
/// Handles 'revocation' notifications
677
681
/// </summary>
678
682
/// <param name="message">notification message received from Twitch EventSub</param>
679
- private void HandleRevocation ( string message )
683
+ private void HandleRevocation ( string message )
680
684
{
681
685
if ( _handlers != null && _handlers . TryGetValue ( "revocation" , out var handler ) )
682
686
handler ( this , message , _jsonSerializerOptions ) ;
@@ -689,7 +693,7 @@ private void HandleRevocation(string message)
689
693
/// </summary>
690
694
/// <param name="eventName">name of the event to raise</param>
691
695
/// <param name="args">args to pass with the event</param>
692
- internal async void RaiseEvent ( string eventName , object args = null )
696
+ internal async void RaiseEvent ( string eventName , object args = null )
693
697
{
694
698
var fInfo = GetType ( ) . GetField ( eventName , BindingFlags . Instance | BindingFlags . NonPublic ) ;
695
699
0 commit comments