MiniTwitch.PubSub
1.0.4
dotnet add package MiniTwitch.PubSub --version 1.0.4
NuGet\Install-Package MiniTwitch.PubSub -Version 1.0.4
<PackageReference Include="MiniTwitch.PubSub" Version="1.0.4" />
paket add MiniTwitch.PubSub --version 1.0.4
#r "nuget: MiniTwitch.PubSub, 1.0.4"
// Install MiniTwitch.PubSub as a Cake Addin #addin nuget:?package=MiniTwitch.PubSub&version=1.0.4 // Install MiniTwitch.PubSub as a Cake Tool #tool nuget:?package=MiniTwitch.PubSub&version=1.0.4
MiniTwitch.PubSub
MiniTwitch.PubSub is the component responsible for interaction with the Twitch PubSub service. The usage of this package revolves around the PubSubClient
class and the Topics
static class.
Features
- Package code is fully documented with XML comments
- Exposes documented & undocumented PubSub topics
- Uses
System.Text.Json
under the hood; Fast, efficient and without unnecessary dependencies - Exposes events with
Func<T1, .., ValueTask>
delegates, making asynchronous handling very easy - Automatically reconnects upon disconnection & automatically re-listens to topics
- Simplistic; Events have clear descriptions on what they do and how to get them invoked
- Multi-token support; You're not limited to 1 auth token per
PubSubClient
- Comes with a built-in logger, which can be disabled or replaced easily
- Events return the topic parameters as
ChannelId
orUserId
, making them easily distinguishable
Getting Started
here is an example usage of the PubSubClient
class:
using MiniTwitch.PubSub;
using MiniTwitch.PubSub.Interfaces;
using MiniTwitch.PubSub.Models;
using MiniTwitch.PubSub.Payloads;
namespace MiniTwitchExample;
public class Program
{
static async Task Main()
{
PubSubClient client = new("my token");
await client.ConnectAsync();
var playbackResponse = await client.ListenTo(Topics.VideoPlayback(36175310));
if (playbackResponse.IsSuccess)
Console.WriteLine($"Listened to {playbackResponse.TopicKey} successfully!");
var responses = await client.ListenTo(Topics.Following(783267696) | Topics.ChatroomsUser(754250938, "a different token"));
foreach (var response in responses)
{
if (!response.IsSuccess)
Console.WriteLine($"Failed to listen to {response.TopicKey}! Error: {response.Error}");
}
client.OnStreamUp += OnStreamUp;
client.OnFollow += OnFollow;
client.OnTimedOut += OnTimedOut;
_ = Console.ReadLine();
}
private static ValueTask OnStreamUp(ChannelId channelId, IStreamUp stream)
{
Console.WriteLine($"Channel ID {channelId} just went live! (Stream delay: {stream.PlayDelay})");
return ValueTask.CompletedTask;
}
private static ValueTask OnFollow(ChannelId channelId, Follower follower)
{
Console.WriteLine($"{follower.Name} just followed you!");
return ValueTask.CompletedTask;
}
private static ValueTask OnTimedOut(UserId userId, ITimeOutData timeout)
{
Console.WriteLine(
$"Your other account (ID: {userId}) has been timed out for {timeout.ExpiresInMs}ms in channel ID {timeout.ChannelId}");
return ValueTask.CompletedTask;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- MiniTwitch.Common (>= 1.1.10)
-
net7.0
- MiniTwitch.Common (>= 1.1.10)
-
net8.0
- MiniTwitch.Common (>= 1.1.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
# MiniTwitch.PubSub Changelog
## 1.0.4
### Minor changes
- `PubSubClient` now has the property `IsConnected` for checking whether the underlying WebSocket is connected
**
## 1.0.3
### Minor changes
- Updated authentication comment for `following.{id}` topic
### Dev
- Changed internal messagetopic & topicinfo values to match `ReadOnlySpan<byte>.MSum()` rather than `.Sum()`. Usages of the latter were also switched
- Removed unused hypetrain topic from messagetopic