-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
** Breaking Release because of Async Events switch **
- Loading branch information
Showing
31 changed files
with
624 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
TwitchLib.EventSub.Websockets.Example.NetStandard/WebsocketHostedServiceWithoutDI.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using TwitchLib.EventSub.Websockets.Core.EventArgs; | ||
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; | ||
|
||
namespace TwitchLib.EventSub.Websockets.Example.NetStandard | ||
{ | ||
public class WebsocketHostedServiceWithoutDI : IHostedService | ||
{ | ||
private readonly ILogger<WebsocketHostedService> _logger; | ||
private readonly EventSubWebsocketClient _eventSubWebsocketClient; | ||
|
||
public WebsocketHostedServiceWithoutDI(ILogger<WebsocketHostedService> logger, ILoggerFactory loggerFactory) | ||
{ | ||
_logger = logger; | ||
_eventSubWebsocketClient = new EventSubWebsocketClient(loggerFactory); | ||
|
||
_eventSubWebsocketClient.WebsocketConnected += OnWebsocketConnected; | ||
_eventSubWebsocketClient.WebsocketDisconnected += OnWebsocketDisconnected; | ||
_eventSubWebsocketClient.WebsocketReconnected += OnWebsocketReconnected; | ||
_eventSubWebsocketClient.ErrorOccurred += OnErrorOccurred; | ||
|
||
_eventSubWebsocketClient.ChannelFollow += OnChannelFollow; | ||
} | ||
|
||
public async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
await _eventSubWebsocketClient.ConnectAsync(); | ||
} | ||
|
||
public async Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
await _eventSubWebsocketClient.DisconnectAsync(); | ||
} | ||
|
||
private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e) | ||
{ | ||
_logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} - Error occurred!"); | ||
} | ||
|
||
private async Task OnChannelFollow(object sender, ChannelFollowArgs e) | ||
{ | ||
var eventData = e.Notification.Payload.Event; | ||
_logger.LogInformation($"{eventData.UserName} followed {eventData.BroadcasterUserName} at {eventData.FollowedAt}"); | ||
} | ||
|
||
private async Task OnWebsocketConnected(object sender, WebsocketConnectedArgs e) | ||
{ | ||
_logger.LogInformation($"Websocket {_eventSubWebsocketClient.SessionId} connected!"); | ||
|
||
if (!e.IsRequestedReconnect) | ||
{ | ||
// subscribe to topics | ||
} | ||
} | ||
|
||
private async Task OnWebsocketDisconnected(object sender, EventArgs e) | ||
{ | ||
_logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!"); | ||
|
||
// Don't do this in production. You should implement a better reconnect strategy | ||
while (!await _eventSubWebsocketClient.ReconnectAsync()) | ||
{ | ||
_logger.LogError("Websocket reconnect failed!"); | ||
await Task.Delay(1000); | ||
} | ||
} | ||
|
||
private async Task OnWebsocketReconnected(object sender, EventArgs e) | ||
{ | ||
_logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected"); | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
TwitchLib.EventSub.Websockets.Example/TwitchLib.EventSub.Websockets.Example.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelAdBreakBeginArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; | ||
using TwitchLib.EventSub.Websockets.Core.Models; | ||
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel | ||
{ | ||
public class ChannelAdBreakBeginArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelAdBreakBegin>> | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatMessageArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; | ||
using TwitchLib.EventSub.Websockets.Core.Models; | ||
|
||
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel | ||
{ | ||
public class ChannelChatMessageArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelChatMessage>> | ||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelGuestStarGuestUpdateArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; | ||
using TwitchLib.EventSub.Websockets.Core.Models; | ||
|
||
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel | ||
{ | ||
public class ChannelGuestStarGuestUpdateArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelGuestStarGuestUpdate>> | ||
{ } | ||
} |
Oops, something went wrong.