javascriptnode.jswebsocketfayewebix

Faye Websocket in NodeJS


I'm new to nodeJS and faye / websockets .

Made a datatable with webix and i want to make a live update to it.

Right now trying to make it with Faye , but not quite sure what should i do after faye sends me a request that looks like that :

[{"channel":"/meta/handshake","version":"1.0","supportedConnectionTypes":["websocket","eventsource","long-polling","cross-origin-long-polling","callback-polling"],"id":"1"}]

and gets a respones :

[{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"8bkeysctea7ucerz9h3tyjz0n52s5os","advice":{"reconnect":"retry","interval":0,"timeout":45000}}]

On the server ( NodeJS ) i have the following code :

var http = require("http"),
    faye = require("faye");


    var server = http.createServer(function (request, response) {
           //Here i have some code for the CRUD operations for the webix Datatable    
    }),
       bayeux = new faye.NodeAdapter({ mount: '/faye', timeout: 45 });

    bayeux.attach(server);
    server.listen(1212, function () {
       console.log("\r\n" + new Date() + "\n -->> HTTP Server listens to Port 1212 <<--\r\n ");
    });

on the client side ( JS ) :

webix.proxy.faye.client = new Faye.Client("//localhost:1212/faye");    
webix.proxy.faye.clientId = webix.uid(); // unique client id
webix.proxy.faye.client.connect();

HTML :

<script type="text/javascript" src="//localhost:1212/faye/client.js"></script>

( Took preatty much everything from webix examples + faye examples )

Maybe someone can explain me what to do next , or give a link where i can read more about Websockets and how to work with them.

Thank you for your time.


Solution

  • After you have configured faye on the client and on the server side, you can use it as a datasource for any component

    {
    view: "datatable", 
    url: "faye->/data", 
    save: "faye->/data"
    }
    

    Beware that faye is used only for syncing data between clients, it will not load or save data to the real database