The javascript SDK for the Collabrify.it backend
Making your webapp Collabrified with Collabrify is a breeze. Just drop this script tag in you html file:
<script scr='path/to/hosted/Collabrify.js'></script>
Now you can instantiate a Collbrify Client:
var client = new CollabrifyClient({
application_id: Long.fromString('1234567890'),
user_id: 'example@gmail.com'
});
Now start a collabrified session:
var client = new CollabrifyClient({
application_id: Long.fromString('1234567890'),
user_id: 'example@gmail.com'
});
client.createSession({
name: 'you_session_name',
password: 'password',
tags: ['you_sesson_tag1','you_sesson_tag2']
});
On another webpage, lets search for the session and join in:
client = new CollabrifyClient({
application_id: Long.fromString('1234567890'),
user_id: 'example@gmail.com'
});
client.listSessions(['you_sesson_tags'])
.then(function (sessions) {
client.joinSession({session: sessions[0], password: 'password'});
})
.then(function (session) {});
.catch(function (e) {"catch any errors here"})
And, BOOM! you App is now collabrified. Send messages between clients like so:
client.broadcast({some: 'data', any: 'data'})
And recieve the data on the other clients
client.on('event', function (event) {
// USE THE DATA HERE
});
var client = new CollabrifyClient({
application_id: Long.fromString('1234567890'),
user_id: 'example@gmail.com'
});
client.createSession({
name: 'name of the session',
password: 'password',
tags: ['you_sesson_tag1','you_sesson_tag2']
});
Returns a promise that get resolved when a sessions is created on server.
client.listSession(['an', 'array', 'of', 'tags']);
Returns a promise that get resolved when a list of session objects is available.
The second (optional, defaults to false) boolean argument determines whether a filter or exact match query is performed (false = filter, true = exact match). With filter, a session will be included if their tag list contains all of the tags contained in the array. With exact match, a session will be included if and only if their tag list matches the specified tag list.
Example: Session 1's tag: ['apple', 'orange', 'banana'] listSession(['apple']) will include Session 1. listSession(['apple'], true) will not include Session 1.
client.joinSession({session: session, password: 'password'});
Returns a promise that gets resolved when the session is joined.
client.broadcast({any: 'javascript', object: 1});
Returns a promise that gets resolved when broadcast is done. If a ArrayBuffer object is passed, it is passed along as raw data.
client.leaveSession();
Returns a promise that gets resolved when session has been left.
client.endSession();
Returns a promise that gets resolved when session has been left. Can only be called by owner.
client.preventFurtherJoins();
Returns a promise that gets resolved when a confirmation from the server is recieved. Can only be called by owner.
client.pauseEvents();
Pauses incoming events.
client.resumeEvents();
Resumes incoming events.
'''javascript console.log CollabrifyClient.version '''
Returns the client version
Returns JSON parsed data
Returns raw bytes
This object contains information about the active session. undefined otherwise.
This object contains information about the current user if a session is active. undefined otherwise.
The current submission_registration_id.
All errors except for notification errors are handled through promises. When a broadcast call fails, the catch handler passes an Array of events (that failed) that have a resend() method that can be used to try to send the event again.
Should work on
Use of a Promise pollyfill is recommended. Take a look at https://github.com/then/promise