StreamCore is an IPA based mod designed to allow developers to create interactive chat experiences with ease. At the time of writing StreamCore supports Twitch and YouTube.
Config files can be found in the UserData\StreamCore
folder. This folder will be referenced as the config folder
for the remainder of this readme.
Twitch configuration is very straightforward, click the link below to generate an OAuth token and copy it into the Twitch login file described below.
Option | Description |
---|---|
TwitchChannelName | The name of the Twitch channel whos chat you want to join (this is your Twitch username if you want to join your own channel) |
TwitchUsername | Your twitch username for the account you want to send messages as in chat (only matters if you're using the request bot) |
TwitchOAuthToken | The oauth token corresponding to the TwitchUsername entered above (Click here to generate an oauth token) |
YouTube configuration is not so straightforward. It also isn't good for longer streams since the YouTube API is absolutely terrible and uses your YouTube APIv3 data quota to read the chat.
What this means in layman's terms is that in a given day, you'll only be able to use StreamCore for about ~2 ish hours before you run out of quota. Sorry about this, I'll be implementing a way to use multiple sets of auth info in the future to "fix" this.
First, head over to the Google Developer API Console, and if you don't have one already create a project. It doesn't matter what you name this project, but I would name it something related to StreamCore.
After you've created a project, click on the Credentials tab on the left and click the "create credentials" button, then click "OAuth client ID"
Select application type "other" and enter a name, then click "Create".
From the Credentials tab, click on the new OAuth credential you just created. You should see a screen with the client id/client secret for the OAuth credential you just created, click the "Download JSON" button and save it to your computer.
Rename the JSON file you just downloaded to YouTubeClientId.json
and copy it into the StreamCore config folder.
Now that we've got our OAuth credential, we need to enable the YouTube Data APIv3. To do this, head over to the Google API Library.
Search for the "YouTube Data API v3" and click on it, then click "Enable".
Start up the game and a browser window should popup with the Google OAuth consent screen asking you to approve access to your account. After granting approval, StreamCore will automatically start reading chat from your live broadcast.
Implementing StreamCore into your plugin is very simple, and can be accomplished in just a few steps.
Implement ITwitchIntegration
, IYouTubeIntegration
, or IGlobalChatIntegration
into the class which you want to receive the chat callbacks
Note: StreamCore will automatically instantiate instances of any classes that implement any IGenericChatIntegration
-based interface in OnApplicationStart, so make sure you don't instantiate these classes anywhere in your own code!
Setup any chat message callbacks you wish to subscribe to. For Twitch, subscribe to the events in TwitchMessageHandlers
, and likewise for YouTube subscribe to the events in YouTubeMessageHandlers
. Any future integrations will follow this naming convention.
After you have setup the chat message callbacks and your class is ready, set the IsPluginReady
property to true
(this is part of the IGenericChatIntegration
interface, so you'll see what I mean once you do step 1).
Note: As long as IsPluginReady
is set to false, StreamCore will not try to establish a connection to any chat services. This means you can effectively block StreamCore from establishing any chat connections for as long as you need until your class is ready.
using StreamCore;
using StreamCore.Chat;
using StreamCore.YouTube;
using StreamCore.Twitch;
namespace YourModsNamespace
{
public class ChatMessageHandler : MonoBehaviour, ITwitchIntegration, IYouTubeIntegration
{
public bool IsPluginReady { get; set; } = false;
public void Awake()
{
// Setup chat message callbacks
TwitchMessageHandlers.PRIVMSG += (twitchMsg) => {
// do stuff with twitchMsg here
};
YouTubeMessageHandlers.OnMessageReceived += (youtubeMsg) => {
// do stuff with youtubeMsg here
};
// Signal to StreamCore that this class is ready to receive chat callbacks
IsPluginReady = true;
}
}
}
Initialize StreamCore in OnApplicationStart
It's important that you base your client around calling Initialize
in OnApplicationStart
, to ensure you don't miss any callbacks if any other plugins call Initialize
in OnApplicationStart
.
Make sure to include StreamCore.Chat
:
using StreamCore.Chat;
Then call Initialize
for the chat service you want to initialize. For now, since only Twitch is supported, we'll just initialize TwitchWebSocketClient
.
public void OnApplicationStart()
{
TwitchWebSocketClient.Initialize();
}
Subscribe to any callbacks you want to receive. You probably want to do this in OnApplicationStart
as well.
This can be time sensitive for callbacks such as TwitchWebSocketClient.OnConnected
, as if you don't subscribe in time you might miss the callback. StreamCore will delay the connection after calling Initialize
for 1 second, which should allow all plugins that utilize StreamCore to subscribe to these events in time.
TwitchWebSocketClient.OnConnected += () =>
{
Console.WriteLine("Connected to Twitch!");
}
TwitchMessageHandlers.PRIVMSG += (twitchMessage) =>
{
Console.WriteLine($"Received PRIVMSG from {twitchMessage.user.displayName} in channel {twitchMessage.channelName}. Message: {twitchMessage.message}");
};