I’m building a component extension that will be fed data from another application running on a streamer’s local machine. My initial idea is to have the application on the streamer’s local machine act as the “server” to send updates to the extension (that the streamer also has installed). If the streamer is not running the local application, then the extension will not receive any data. The idea is I won’t need a server hosted somewhere on the Internet.
Is this possible with a websocket (or something else)? Or would this create some sort of vulnerability for the streamer’s local machine, as I’d be opening it up to the Internet? Should I just use a web-hosted server/DB instead (Firebase maybe)? I was initially thinking it’d be simpler to do this without the server/DB, but if anyone has any input or experience in this it’s appreciated. Thanks!
It is possible to have an extension require the streamer to run an app on their machine for functionality, but there is some issues to be aware of that would make it problematic.
Firstly, only the extension for the streamer themselves would be able to connect to the app running on their machine, as for any viewer to do so would mean you would have to publish the streamers IP which is a huge security issue and should not be attempted.
Secondly, the app running on streamers machines wont be an EBS for the extension as it wont have your extension secrets needed to sign/verify JWTs. As such as the only way for you to get data to your viewers would be the app sending it to the streamer, who then broadcasts it over Pubsub. The issue here is that Pubsub has rate limits (1msg/s per channel, 5KB max message size), so that may not be sufficient to get all the data you need to your viewers.
As well as the rate limtis associated with pubsub, there’s also the practical issue in that it requires the streamer to have one of your extension views open, which is not always practical and if there’s any connection issues then the extension will fail.
A more appropriate solution would be to have the app you require the streamer to run connect to your EBS you have hosted somewhere properly, and then this can either broadcast messages on pubsub itself or allow viewers to communicate with (either via a websocket or a REST API).
Thanks for the thorough response! I will definitely go the route of the EBS hosted somewhere.
My initial plan was to have the extension get fed data without having to ask for it, but that seems a bit more complicated, as each viewer will need their own socket to the EBS. Is it possible to make the extension make a call to the EBS when the viewer begins viewing the stream? And then once it establishes the connection just get fed data? Achieving the same effect as pubsub but with faster results?
This might be a basic question but this will be my first extension.
Extensions are basically just a webpage that is loaded as an iframe, so yeah it’s certainly possible to make an extension call your EBS when it finishes loading.
Your extension will be listening to the
onAuthorized event fired by the Extension Helper which contains a token, and some user/channel details, so once you get that event you can make a connection to your EBS and using that data know what channel they are connecting from and who they are (if they’ve shared their identity you’ll know their Twitch ID, if they haven’t you’ll just get an opaque ID)
The only requirement is that all connections must be over HTTPS or WSS.
I decided to go with Socket.io, and I authenticate immediately after establishing a connection. I believe I can simply use ‘https’ in the url when making the connection to the EBS to establish a secure connection, but I haven’t tried yet. Thanks for the input!