Skip to content
George Farcasiu edited this page Jan 29, 2016 · 1 revision

Socket.io is used for server to client notifications. When the transaction object changes on the server, a notification will be sent over socket.io to all listening clients. This allows for clients to receive real time updates without the use of polling.

Upon connection to the socket.io server clients will need to tell the server which transactions the client wants updates on. This is accomplished by emitting a register_transaction event with the transaction's uuid attached to the data section. After the event is received by the server, the server will notify that client with any changes to that transaction. However the client must register a handler for the transaction if it wants to execute code when it receives this transaction change event. Handlers should register to listen to events with the name equal to the transaction uuid it wants to listen for.

Example code:

socketio = io(socketiohost);
socketio.on("connect", function() {

    // Register a listener for the transaction
    socketio.on(transactionUuid, function(update) {
        //A transaction change event has been received for the specific transaction
    });

    // Tell the server to send this client updates for the transaction with uuid `transactionUuid`
    socketio.emit("register_transaction", {"transaction_uuid": transactionUuid});

    // Repeat for every transaction you want updates for
});

Clone this wiki locally