MiniTwitch.PubSub 1.0.3

dotnet add package MiniTwitch.PubSub --version 1.0.3
NuGet\Install-Package MiniTwitch.PubSub -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MiniTwitch.PubSub" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MiniTwitch.PubSub --version 1.0.3
#r "nuget: MiniTwitch.PubSub, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MiniTwitch.PubSub as a Cake Addin
#addin nuget:?package=MiniTwitch.PubSub&version=1.0.3

// Install MiniTwitch.PubSub as a Cake Tool
#tool nuget:?package=MiniTwitch.PubSub&version=1.0.3

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 or UserId, 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 230 1/10/2024
1.0.2 178 11/14/2023
1.0.1 105 10/12/2023
1.0.0 124 9/23/2023

# MiniTwitch.PubSub Changelog

## 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