mafintosh / signalhub

Simple signalling server that can be used to coordinate handshaking with webrtc or other fun stuff.
MIT License
667 stars 97 forks source link

Easy deployment to now.sh #26

Closed billiegoose closed 6 years ago

billiegoose commented 7 years ago

I've started using now by @rauchg lately, and I wanted to be able to deploy a signalhub server with now. To this end, I added an npm start script, and the instructions to the README. Note that the instructions say to run "now mafintosh/signalhub" which won't actually work until this change is merged... what I actually used was "now wmhilton-contrib/signalhub". Check it out live!

~https://signalhub-hzbibrznqa.now.sh/~

https://signalhub-jccqtwhdwc.now.sh

billiegoose commented 7 years ago

Actually, hold that pull request until I actually have a working app... the signalhub server seems fine, but for some reason webrtc-swarm isn't finding peers.

billiegoose commented 7 years ago

Fun fact, now.sh doesn't play nice with Server Sent Events because of NGINX request buffering. I have added an X-Accel-Buffering: no header to signalhub's code so it actually works on now.sh now. I rescind my hold on this pull-request; you may merge at will!

Credit goes to @remy for documenting this solution on his blog.

@rauchg I don't know if you can configure NGINX so that requests with Content-Type: text/event-stream are not buffered, but that sounds like a fun feature the Zeit team could add. I found one other example of a site on now.sh trying (and failing) to use event streams: https://simpl.info/eventsource/ by @samdutton which is connecting to sse.now.sh

derhuerst commented 7 years ago

Would love to see this merged! 💚 Anything I can help to speed this up?

billiegoose commented 7 years ago

Oh god this feels like years ago. Um... does any of it work?

...

Um... yes! Yes, it appears SSE works now! Open a couple of these and look in the console to demo:

view on requirebin

var signalhub = require('signalhub')
var hub = signalhub('my-app', [
  'https://signalhub-jccqtwhdwc.now.sh/'
])

hub.subscribe('my-channel')
  .on('data', function (message) {
    console.log('new message received', message)
  })

setInterval(function () {
hub.broadcast('my-channel', {hello: 'world'})
}, 1000)

It is worth noting that now.sh WILL hibernate inactive instances. (That's how they can afford unlimited immutable deployments.) They tend to unfreeze pretty quickly though - usually (though not always) before the request times out.

billiegoose commented 7 years ago

@derhuerst as to directly answer your question about speeding it up... I don't think there is anything to do except draw @mafintosh's attention and make him aware that this is ready to merge now.

derhuerst commented 6 years ago

FYI I deployed one at signalhub.jannisr.de.

mafintosh commented 6 years ago

Good job everyone. @wmhilton you want to help maintain this?

mafintosh commented 6 years ago

4.9.0

derhuerst commented 6 years ago

@wmhilton it would be great if you could add the urls of the now deployments that you created to the readme. 💛

billiegoose commented 6 years ago

@mafintosh Gladly.

@derhuerst Er, why would we want those URLs in the README? If you're thinking they could be for others to use, let me alias them as something reasonable like https://signalhub[0-9].now.sh/

Edit: Actually no. Aliases are mutable, and if I aliased them then they would be under my control. (mwahaha.) The original URLs are immutable, which is better for trusting. I can add them to the README.