Total.js + primus.io = realtime communication

Primus.io (www.primus.io) is one of the most known and professional library to real time communication. 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

  • 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.
  • Built-in reconnect, it just works. The reconnect is controlled by a randomised exponential back-off algorithm to reduce server stress.
  • 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.
  • Automatically encodes and decodes messages using custom parsers. Can be easily switched for binary encoding for example.
  • 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.
  • Fixes various of bugs in the supported frameworks and additional stability patches to improve real-time communication.
  • 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.

In below article will be presented consolidation primus.io module with Total.js platform.

Assumptions and Benefits our project:

  • Main objective: integration Total.js with primus.io library for realtime communication

Below presented skeleton/project You can find on my GitHub repository: https://github.com/maxprog/total.js-primus.io.git

Structure of Total.js directories is following:

The most important:

In case of integration Total.js  with primus.io You have to do following steps:

1. Add to config line configuration allow-websocket: false to disable web socket lib

2. Implement integration primus.io library with total.js  in main total.js file server (e.g. debug.js, release.js or in any defined by You file). Logic of creation in case of primary.io is a bit different to socket.io – please take a look on ‘room’ functionality

3. Place in index.html javascript primus.io reference responsible for communication client side with node.js server

<script src=”/primus/primus.io.js”></script>

4. Implement javascript functionality responsible for communication by primus.io on client side (index.html or layout.html)

4. Bind functions of primus.io javascript with html tags to handle events for incoming and sending message

The last operation it is installation process all necessary modules and run total.js server:

      1. Install the total.js  in project directory
        npm install 
        
      2. Start the server from the root directory of project
        node debug.js
        
      3. You should see information that total.js was started

Visit http://localhost:8000, open two or more browsers and start work on messenger

April 5th, 2017

  • This is the suitable blog for anyone who needs to search out out about this topic. You understand a lot its virtually onerous to argue with you (not that I actually would need匟aHa). You undoubtedly put a brand new spin on a subject thats been written about for years. Nice stuff, just great!.

  • I am just writing to let you know what a fantastic encounter my friend’s child encountered reading the blog. She discovered so many pieces, which include how it is like to have an incredible helping style to let other folks easily comprehend some problematic things. You undoubtedly exceeded people’s desires. I appreciate you for offering such practical, safe, edifying not to mention easy thoughts on your topic to Julie..

  • I precisely had to appreciate you once again. I am not sure the things I would’ve accomplished without these methods documented by you over such area of interest. It actually was a real depressing issue in my opinion, nevertheless being able to see a professional tactic you managed that forced me to cry for joy. Now i’m grateful for your assistance and even hope you really know what an amazing job you are accomplishing instructing many people by way of your web blog. I am certain you haven’t come across all of us..

  • I discovered your weblog internet site on google and check a few of one’s early posts. Continue to preserve up the very beneficial operate. I just extra up your RSS feed to my MSN News Reader. Seeking forward to reading additional from you later on!.