Primus - An abstraction layer for real time frameworks

I thought this was interesting-- an abstraction layer for real time frameworks; it even supports binary encoding.

I remember a few months ago I was having a hard time finding a real time framework to power my collaborative drawing app (WIP - almost done), now it seems their are quite a number of them. I’m working on a reference collection so others can find them without searching for 2 weeks like I did (WIP).

I haven’t gone so far as to see how well Yjs integrates with primus, but I thought it was worth sharing :grin:

Primus, the creator god of transformers but now also known as universal wrapper for real-time frameworks. There are a lot of real-time frameworks available for Node.js and they all have different opinions on how real-time should be done. Primus provides a common low level interface to communicate in real-time using various real-time frameworks.

Advantages

  1. Effortless switching between real-time frameworks by changing one single line of code. No more API rewrites needed when your project requirements change, the framework gets abandoned or simply breaks down.
  2. Built-in reconnect, it just works. The reconnect is controlled by a randomised exponential back-off algorithm to reduce server stress.
  3. Offline detection, Primus is smart enough to detect when users drop their internet connection (switching WIFI points/cell towers for example) and reconnects when they are back online.
  4. Automatically encodes and decodes messages using custom parsers. Can be easily switched for binary encoding for example.
  5. A clean, stream-compatible interface for the client and server. You can just stream#pipe data around. In addition to that, the client works on Node.js as well, write once, run it everywhere.
  6. Fixes various of bugs in the supported frameworks and additional stability patches to improve real-time communication.
  7. Comes with an amazing plugin interface to keep the core library as fast and lean as possible while still allowing the server and the client to be extended.
  8. Last but not least, Primus is built with love, passion and dedication to the real-time web.

If I understand correctly, prismus allows using different communication technologies to the server. You can choose amongst Enigne.io (which is used by socket.io and allows downgrading to HTTP long pulling), BrowserChannel, and Websockets.

For collaborative applications, it is best to use Websockets instead of HTTP long pulling or BrowserChannel. In my opinion, there is little advantage in supporting browsers that don’t support Websockets. All browsers that have been updated after 2012 now support websockets.

For other applications (e.g. notification messages that are mainly triggered by the server), it does make sense to use long pulling or BrowserChannel connections.

So for Yjs, I believe there is little benefit in using prismus. Though it’s definitely a really cool project which makes a lot of things easier.

Sure, I suppose I thought it was a neat project and interesting example of an abstraction layer for real time frameworks yet, as you mentioned, don’t actually have need of this particular library at the moment myself :slight_smile: