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
49 changes: 46 additions & 3 deletions TwitchLib.Unity/Client.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
using System;
using TwitchLib.Client;
using TwitchLib.Client.Events;
using TwitchLib.Client.Exceptions;
using TwitchLib.Client.Interfaces;
using TwitchLib.Client.Models;
using UnityEngine;

namespace TwitchLib.Unity
{
public class Client : TwitchClient, ITwitchClient
{
private readonly GameObject _threadDispatcher;
public new bool OverrideBeingHostedCheck { get; set; }

public new ConnectionCredentials ConnectionCredentials
{
get => base.ConnectionCredentials;
set
{
if (IsConnected)
ThreadDispatcher.Instance().Enqueue(() => throw new IllegalAssignmentException("While the client is connected, you are unable to change the connection credentials. Please disconnect first and then change them."));
base.ConnectionCredentials = value;
TwitchUsername = value.TwitchUsername;
}
}

#region Events
/// <summary>
Expand Down Expand Up @@ -210,10 +225,21 @@ public Client() : base(null)
_threadDispatcher = new GameObject("TwitchClientUnityDispatcher");
_threadDispatcher.AddComponent<ThreadDispatcher>();
UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

base.OnLog += ((object sender, OnLogArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnLog?.Invoke(sender, e)); });

base.OverrideBeingHostedCheck = true;

base.OnLog += (object sender, OnLogArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnLog?.Invoke(sender, e)); };
base.OnConnected += ((object sender, OnConnectedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnConnected?.Invoke(sender, e)); });
base.OnJoinedChannel += ((object sender, OnJoinedChannelArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnJoinedChannel?.Invoke(sender, e)); });

base.OnJoinedChannel += ((object sender, OnJoinedChannelArgs e) => {

ThreadDispatcher.Instance().Enqueue(() => OnJoinedChannel?.Invoke(sender, e));

if (OnBeingHosted == null) return;
if (e.Channel.ToLower() != TwitchUsername && !OverrideBeingHostedCheck)
ThreadDispatcher.Instance().Enqueue(() => throw new BadListenException("BeingHosted", "You cannot listen to OnBeingHosted unless you are connected to the broadcaster's channel as the broadcaster. You may override this by setting the TwitchClient property OverrideBeingHostedCheck to true."));
});

base.OnIncorrectLogin += ((object sender, OnIncorrectLoginArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnIncorrectLogin?.Invoke(sender, e)); });
base.OnChannelStateChanged += ((object sender, OnChannelStateChangedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnChannelStateChanged?.Invoke(sender, e)); });
base.OnUserStateChanged += ((object sender, OnUserStateChangedArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnUserStateChanged?.Invoke(sender, e)); });
Expand Down Expand Up @@ -253,6 +279,23 @@ public Client() : base(null)
base.OnSelfRaidError += ((object sender, EventArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnSelfRaidError?.Invoke(sender, e)); });
base.OnNoPermissionError += ((object sender, EventArgs e) => { ThreadDispatcher.Instance().Enqueue(() => OnNoPermissionError?.Invoke(sender, e)); });
}

/// <summary>
/// Sends a request to get channel moderators. You MUST listen to OnModeratorsReceived event./>.
/// </summary>
/// <param name="channel">JoinedChannel object to designate which channel to send request to.</param>
public new void GetChannelModerators(JoinedChannel channel)
{
if (!IsInitialized) HandleNotInitialized();
if (OnModeratorsReceived == null)
throw new EventNotHandled("OnModeratorsReceived");
SendMessage(channel, "/mods");
}

private new void HandleNotInitialized()
{
ThreadDispatcher.Instance().Enqueue(() => throw new ClientNotInitializedException("The twitch client has not been initialized and cannot be used. Please call Initialize();"));
}
}
}

6 changes: 3 additions & 3 deletions TwitchLib.Unity/TwitchLib.Unity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<PackageId>TwitchLib.Unity</PackageId>
<Version>0.9.0</Version>
<Version>0.9.1</Version>
<Description>Unity wrapper system for TwitchLib</Description>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>LuckyNoS7evin</Authors>
Expand All @@ -17,8 +17,8 @@
<RepositoryType>Git</RepositoryType>
<PackageTags>twitch library unity3d unity dotnet c# csharp net standard 2.0</PackageTags>
<NeutralLanguage>en-US</NeutralLanguage>
<AssemblyVersion>0.9.0.0</AssemblyVersion>
<FileVersion>0.9.0.0</FileVersion>
<AssemblyVersion>0.9.1.0</AssemblyVersion>
<FileVersion>0.9.1.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down