Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Latest commit

 

History

History
77 lines (54 loc) · 1.94 KB

readme.md

File metadata and controls

77 lines (54 loc) · 1.94 KB

Incus.js Build Status NPM

JavaScript bindings for talking to an Incus server in the browser or on the server-side.

Example 1: Reacting to incoming events

var incus = new Incus.Client('http://localhost:4000', 'UID', '/page/path');

incus.on('connect', function() {
    console.log('connected');
}

incus.on('Event1', function (data) {
   console.log(data);
}

Example 2: Updating the page

Incus keeps track of which page a user is currently on, for the page message events. A page is just an arbitrary string. Use this to, for example, provide real-time updates only to users viewing particular content at a particular URL:

$(function() {
    incus.setPage(window.location.path);
});

Example 3: User messaging

Incus supports user-generated messages. You could use this to, for example, implement a simple chat system:

<div id="chat">
    <div id="messages"></div>
    
    <form id="input">
        <input type="text" class="input" placeholder="Say something." />
    </form>
</div>
$("#input form").on("submit", function(e) {
    e.preventDefault();
    
    incus.MessageAll("chatmessage", {
        "message": $("#chat .input").text()
    });
});

incus.on("chatmessage", function(msg) {
    $("#chat #messages").append($('<div>').text(msg.message));
});

Example 4: Browserify

Incus.js is distributed as a NPM module. If you already use node, using Incus is easy! Just add incusjs to your package.json and off you go:

{
    "dependencies": {
        "incusjs": "1.*"
    }
}
var IncusClient = require('incus');

var incus = new IncusClient('http://localhost:4000', 'UID', '/page/path');

incus.MessageUser('event1', 'uid1', {foo: 3});