# Unity/Game Communication

**URL:** <https://discuss.dev.twitch.com/t/unity-game-communication/31666>\
**Category:** Extensions\
**Created:** [May 14, 2021, 11:20am UTC](https://discuss.dev.twitch.com/t/unity-game-communication/31666 "2021-05-14T11:20:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DJ59990](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dj59990/32/12127_2.png) [@DJ59990](https://discuss.dev.twitch.com/u/DJ59990)\
**Post date:** [May 14, 2021, 11:20am UTC](https://discuss.dev.twitch.com/t/unity-game-communication/31666/1 "2021-05-14T11:20:10Z")

</div>

Hi There,

I am currently looking at making an extension for one of our games, the idea would be for the game to trigger a vote every so often on the extension so the viewers could choose an action to trigger within the game.

I have the front end for the extension currently designed and a simple backend triggering the votes to users and collecting the votes, but I’m a little stuck on how to trigger the initial vote from within the game to the ebs.

Looking into TwitchLib it has the option for OnChannelExtensionBroadcast which would handle the return back to the game, but I don’t seem to be able to find a way to correctly communicate with the extension/ebs from within the game itself.

I feel like I’m missing something simple haha, or I’m totally thinking of the puzzle in the wrong way.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [May 14, 2021, 11:32am UTC](https://discuss.dev.twitch.com/t/unity-game-communication/31666/2 "2021-05-14T11:32:20Z")

</div>

> [@DJ59990](#):
>
> Looking into TwitchLib it has the option for OnChannelExtensionBroadcast which would handle the return back to the game

I can’t clearly find what this does in this library.

If you refer to [https://swiftyspiffy.com/TwitchLib/PubSub/class\_twitch\_lib\_1\_1\_pub\_sub\_1\_1\_twitch\_pub\_sub.html#a591a97841b79eeb6b4f145d3b0fca3e0](https://swiftyspiffy.com/TwitchLib/PubSub/class_twitch_lib_1_1_pub_sub_1_1_twitch_pub_sub.html#a591a97841b79eeb6b4f145d3b0fca3e0)

**That is not directly supported by Twitch** and can break/change at any time and it’s not advised to be used. It is not a “supported topic” - [PubSub | Twitch Developers](https://dev.twitch.tv/docs/pubsub#topics) I also don’t think it works given the authentication requirements for that undocument/unsupported (for third parties) topic.

Twitch provides “extension pubsub”

Send from EBS: [Extensions Reference | Twitch Developers](https://dev.twitch.tv/docs/extensions/reference#send-extension-pubsub-message)  
Send from Extension HTML/JS: [Extensions Reference | Twitch Developers](https://dev.twitch.tv/docs/extensions/reference#send)  
Recieve in Extension HTML/JS: [Extensions Reference | Twitch Developers](https://dev.twitch.tv/docs/extensions/reference#listen)

Extension PubSub is “designed” as a “Fan Out” solution to Extension Clients not a “Fan In” solution to your EBS (or game as in this example). Additionally “Extension Viewers” generally won’t be able to broadcast a message via PubSub since viewers lack the authorisation to do so.

> This function can be called by the front end to send directly to PubSub. It uses the Twitch-provided JWT for broadcasters, to allow broadcasters to send a broadcast (channel) or whisper message. Broadcasters cannot send to global.

So likely can’t be used for the game to recieve results of a vote. Since you can’t get the votes as they are cast, as the instance of the extension for a plain user doesn’t have the authority to broadcast.

> [@DJ59990](#):
>
> but I don’t seem to be able to find a way to correctly communicate with the extension/ebs from within the game itself.

Thats up to you to determine, design and create, Tiwtch doesn’t provide anything in this regard.

Which is used by your EBS (or other extension frontends) to send a messages to instance of the extension running on Twitch.

So

Game → any medium → EBS → via Extension PubSub → HTML  
or  
Game → any medium → EBS → any medium → HTML

HTML → any medium → EBS → any medium → Game

“Any Medium” is repaced with something you design and create

Generally for between Game ↔ EBS and I’m rolling a Socket  
And for HTML → EBS I’m using plain JS Fetch making HTTP POST requests.  
And Extension PubSub for EBS to HTML

---

<div class="post-metadata">

**Author:** ![DJ59990](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dj59990/32/12127_2.png) [@DJ59990](https://discuss.dev.twitch.com/u/DJ59990)\
**Post date:** [May 14, 2021, 11:39am UTC](https://discuss.dev.twitch.com/t/unity-game-communication/31666/3 "2021-05-14T11:39:16Z")

</div>

Thanks for the quick and epic reply, that has cleared quite a few bits up for me. I’ll start looking into some socket goodness 😃
