JavaScript bindings for talking to an Incus server in the browser or on the server-side.
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);
}
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);
});
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));
});
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});