JupiterBroadcasting / jupiterbroadcasting.com

JupiterBroadcasting.com, hugo-based and community-driven!
https://jupiterbroadcasting.com
101 stars 49 forks source link

On-air alert functionality (w JBot! sorta...) #41

Closed gerbrent closed 1 year ago

gerbrent commented 2 years ago

@reesericci:

I'd like to work on a webhook endpoint to tell the website about a live show from jbot (basically can I use netlify functions/cf workers)

I was hoping to be able to deploy a serverless/edge function on something like cf workers/netlify functions/deno deploy to create an endpoint for JBot to ping and then store a running "live show" JSON object in a redis/workers KV

that way the website would ping the JSON endpoint every time it's loaded to check if a show is live

and JBot would ping (with a token) a JSON object containing which show was going live to a different endpoint

instead of updating git every time

reesericci commented 2 years ago

I got a basic deno serverless/edge function working that stores a JSON object that looks like this in redis:

{ 
  "title": "Jupiter Broadcasting,
  "chatroom": "irc.geekshed.net"
}

then makes it accessible from a GET request (e.g. when the page loads) and allows POST/DELETE requests with a JWT signed with an RSA key pair to update that object

I'm unsure if it's a good idea to set up a system to notify clients, people viewing the website or possibly a background service worker, about any changes realtime instead of the website checking whenever it's loaded. Then clients could be notified right away that JB went live, but it's a complex system to set up and would require a server to handle the subscriptions. (because the clients would be behind NAT and a callback URL wouldn't work) I don't think regular HTTP polling is a good idea because of bandwidth costing money.

reesericci commented 2 years ago

Serverless function gist: https://gist.github.com/reesericci/2875f2049993c0fea7b67abf1eb1984a

reesericci commented 2 years ago

@StefanS-O is there any pipeline for deploying a serverless function? (i.e. vercel, netlify, cloudflare workers, deno, etc)

elreydetoda commented 2 years ago

@StefanS-O is there any pipeline for deploying a serverless function? (i.e. vercel, netlify, cloudflare workers, deno, etc)

I know I'm not Stefan, but from my observation of the infrastructure there isn't. If you just do an nslookup on the website domain:

$ nslookup jupiterbroadcasting.net 8.8.8.8
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   jupiterbroadcasting.net
Address: 142.132.186.250

And a whois on the returned IP address, you'll see that it's an IP address controlled by hetzner.com (which is a hosting company similar to Linode).

If they use more of cloudflare (reasons mentioned here), you should be able to use cloudflare workers.

elreydetoda commented 2 years ago

Also, I know I haven't really commented on this issue before, and am definitely not very familiar with redis, but if you're looking for a KV store is there a reason for not using a hosted service like this: https://www.cloudflare.com/products/workers-kv/

I've never used it before, but just thinking of ways to lighten the amount of services that JB'll have to run initially to get the website up and running. I'd imagine if they want to host a redis instance later on (since self-hosting is something JB does) that'd be doable, but just to initially launch without an extra 2-3 services (search + s3 endpoint where some other services talked about).

reesericci commented 2 years ago

CF KV is an excellent solution, I just didn't want to use it if JB wasn't going to utilize CF workers for deploying this.

reesericci commented 2 years ago

I also built it on top of the Deno runtime which is not supported by CF, only themselves (Deno Deploy) and Netlify from what I remember.

elreydetoda commented 2 years ago

Ya, IIRC CF works run their own version of a node runtime, right? (Only heard about it on podcasts)

reesericci commented 2 years ago

Deno isn't node so it wouldn't work

reesericci commented 2 years ago

for realtime updates Cloudflare's Pub/Sub: https://developers.cloudflare.com/pub-sub/ could possibly work instead of self-hosting a pub/sub solution.

reesericci commented 2 years ago

As it turns out, redis has a builtin Pub/Sub function: https://redis.io/docs/manual/pubsub/

elreydetoda commented 2 years ago

Deno isn't node so it wouldn't work

Ya, I was mainly asking if you knew the runtime that they use, not trying to say deno is node 🙃

elreydetoda commented 2 years ago

for realtime updates Cloudflare's Pub/Sub: https://developers.cloudflare.com/pub-sub/ could possibly work instead of self-hosting a pub/sub solution. As it turns out, redis has a builtin Pub/Sub function: https://redis.io/docs/manual/pubsub/

Cool! So redis could be used for local dev and Cloudflare could be used for prod?

I wouldn't start working on modifing it (unless you want to) until you get a JB person's (or others via proxy (@StefanS-O or someone similar) ) opinion which solution they'd like more. (Self-hosting redis, cloudflare KV or Pub/Sub, etc...)

It's honestly up to them for whatever is easiest to implement/maintain + what's needed.

I was honestly just asking, because I was curious 😅

StefanS-O commented 2 years ago

I will start looking into this after launch, this is not a milestone 1 issue and also needs decissions from @ChrisLAS where this should be hosted.

gerbrent commented 1 year ago

feature completed by https://github.com/JupiterBroadcasting/jupiterbroadcasting.com/pull/378