I wonder whether any gem wraps all these details
Pusher
Asynchronicity
Asynchronicity is standard functionality for web applications - you'll have to open an asynchronous
request to your server, which will allow you to then receive as much data as you want.
Asynchronous connections are best defined within the scope of HTTP. HTTP is stateless, meaning it treats your requests as unique every time (does not persist the data / connectivity). This means you can generally only send single requests, which will yield a response; nothing more.
Asynchronous requests occur in parallel to the "stateless" requests, and essentially allow you to receive updated responses from the server through means other than the standard HTTP protocol, typically through Javascript
--
There are 2 main ways to initiate "asynchronous" requests:
- SSE's (Server Sent Events) - basically Ajax long polling
- Websockets (opens a perpetual connection)
--
SSE's
Server sent events are an HTML5 technology, which basically allows you to "ping" a server via Javascript, and manage any updates which comes through:
A server-sent event is when a web page automatically gets updates from
a server.
This was also possible before, but the web page would have to ask if
any updates were available. With server-sent events, the updates come
automatically.
Setting up SSE's is simple:
#app/assets/javascripts/application.js
var source = new EventSource("/your/endpoint");
source.onmessage = function(event) {
alert(event.data)
};
Although native in every browser except IE, SSEs have a major drawback, which is they act very similarly to long-polling, which is super inefficient.
--
Websockets
The second thing you should consider is web sockets. These are by far recommended, but not having set them up so far, I don't have much specific information on how to use them.
I have used Pusher
before though, which basically creates a third-party websocket for you to connect with. Websockets only connect once, and are consequently far more efficient than SSE's
I would recommend at least looking at Pusher - it sounds exactly like what you need