Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ You can also find a console app example for .NET 8 and for .NET Framework 4.8 in
[1]: https://img.shields.io/nuget/v/TwitchLib.EventSub.Websockets.svg?label=TwitchLib.EventSub.Websockets
[2]: https://www.nuget.org/packages/TwitchLib.EventSub.Websockets

## Breaking Changes in Version 0.7
- removed INotificationHandler interface
- Removed deprecated versions of .NET.
- All EventSub events were moved to `TwitchLib.EventSub.Core` Nuget Package, for better management across future EventSub transport Client libraries.
That means their namespace changed from `TwitchLib.EventSub.Websockets.Core.EventArgs.*` to `TwitchLib.EventSub.Core.EventArgs.*`.
- Like Events, all EventSub Models were moved to the `TwitchLib.EventSub.Core` package, (namespace changed from `TwitchLib.EventSub.Websockets.Core.Models` to `TwitchLib.EventSub.Core.Models`)
but to ensure that the models can be used across projects some changes had to be made:
- Properties from `EventSubNotification<T>` were moved to `TwitchLibEventSubEventArgs<T>`.
- Property `Notification` was removed from `TwitchLibEventSubEventArgs<T>`.
- Class `EventSubMetadata` was renamed to `WebsocketEventSubMetadata`.
- `WebsocketDisconnected` and `WebsocketReconnected` now contain more specific EventArgs.

## Setup

Step 1: Create a new project (Console, WPF, ASP.NET)
Expand Down Expand Up @@ -110,7 +122,7 @@ namespace TwitchLib.EventSub.Websockets.Test
}
}

private async Task OnWebsocketDisconnected(object sender, EventArgs e)
private async Task OnWebsocketDisconnected(object sender, WebsocketDisconnectedArgs e)
{
_logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!");

Expand All @@ -122,7 +134,7 @@ namespace TwitchLib.EventSub.Websockets.Test
}
}

private async Task OnWebsocketReconnected(object sender, EventArgs e)
private async Task OnWebsocketReconnected(object sender, WebsocketReconnectedArgs e)
{
_logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using TwitchLib.Api;
using TwitchLib.EventSub.Websockets.Core.EventArgs;
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;
using TwitchLib.EventSub.Core.EventArgs.Channel;

namespace TwitchLib.EventSub.Websockets.Example.NetStandard
{
Expand Down Expand Up @@ -50,7 +50,7 @@ private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e)

private async Task OnChannelFollow(object sender, ChannelFollowArgs e)
{
var eventData = e.Notification.Payload.Event;
var eventData = e.Payload.Event;
_logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.Extensions.Logging;
using TwitchLib.Api;
using TwitchLib.EventSub.Websockets.Core.EventArgs;
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;
using TwitchLib.EventSub.Core.EventArgs.Channel;

namespace TwitchLib.EventSub.Websockets.Example.NetStandard
{
Expand Down Expand Up @@ -46,7 +46,7 @@ private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e)

private async Task OnChannelFollow(object sender, ChannelFollowArgs e)
{
var eventData = e.Notification.Payload.Event;
var eventData = e.Payload.Event;
_logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}");
}

Expand Down
25 changes: 20 additions & 5 deletions TwitchLib.EventSub.Websockets.Example/WebsocketHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
using System.Threading.Tasks;
using TwitchLib.Api;
using TwitchLib.Api.Core.Enums;
using TwitchLib.EventSub.Core.EventArgs.Channel;
using TwitchLib.EventSub.Websockets.Core.EventArgs;
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;
using TwitchLib.EventSub.Websockets.Core.Models;

namespace TwitchLib.EventSub.Websockets.Example
{
Expand All @@ -28,8 +29,9 @@ public WebsocketHostedService(ILogger<WebsocketHostedService> logger, EventSubWe
_eventSubWebsocketClient.WebsocketReconnected += OnWebsocketReconnected;
_eventSubWebsocketClient.ErrorOccurred += OnErrorOccurred;

_eventSubWebsocketClient.UnknownEventSubNotification += OnUnknownEventSubNotification;
_eventSubWebsocketClient.ChannelFollow += OnChannelFollow;

// Get ClientId and ClientSecret by register an Application here: https://dev.twitch.tv/console/apps
// https://dev.twitch.tv/docs/authentication/register-app/
_twitchApi.Settings.ClientId = "YOUR_APP_CLIENT_ID";
Expand All @@ -49,7 +51,7 @@ private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e)

private async Task OnChannelFollow(object sender, ChannelFollowArgs e)
{
var eventData = e.Notification.Payload.Event;
var eventData = e.Payload.Event;
_logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}");
}

Expand Down Expand Up @@ -81,7 +83,7 @@ await _twitchApi.Helix.EventSub.CreateEventSubSubscriptionAsync("channel.follow"
}
}

private async Task OnWebsocketDisconnected(object sender, EventArgs e)
private async Task OnWebsocketDisconnected(object sender, WebsocketDisconnectedArgs e)
{
_logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!");

Expand All @@ -93,9 +95,22 @@ private async Task OnWebsocketDisconnected(object sender, EventArgs e)
}
}

private async Task OnWebsocketReconnected(object sender, EventArgs e)
private async Task OnWebsocketReconnected(object sender, WebsocketReconnectedArgs e)
{
_logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected");
}

// Handling notifications that are not (yet) implemented
private async Task OnUnknownEventSubNotification(object sender, UnknownEventSubNotificationArgs e)
{
var metadata = (WebsocketEventSubMetadata)e.Metadata;
_logger.LogInformation("Received event that has not yet been implemented: type:{type}, version:{version}", metadata.SubscriptionType, metadata.SubscriptionVersion);

switch((metadata.SubscriptionType, metadata.SubscriptionVersion))
{
case ("channel.chat.message", "1"): /*code to handle the event*/ break;
default: break;
}
}
}
}
3 changes: 2 additions & 1 deletion TwitchLib.EventSub.Websockets/Client/WebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ private async Task ProcessDataAsync()
case WebSocketMessageType.Binary:
break;
case WebSocketMessageType.Close:
_logger?.LogWebsocketClosed((WebSocketCloseStatus)_webSocket.CloseStatus!, _webSocket.CloseStatusDescription!);
var logLevel = _webSocket.CloseStatus is WebSocketCloseStatus.NormalClosure ? LogLevel.Information : LogLevel.Critical;
_logger?.LogWebsocketClosed(logLevel, (WebSocketCloseStatus)_webSocket.CloseStatus!, _webSocket.CloseStatusDescription!);
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading