node package manager



build status

browser support

Presence information for rooms of people persisted in crdt


var Document = require("crdt")
var presence = require("presence")
// todo document this 
var room = RoomStruct(...)
var doc = Document()
var rooms = presence(doc, room)
fold(rooms, function (room) {
    fold(room.people, function (person) {
        // "add" or "remove" 
        console.log("person.eventType", person.eventType)
        console.log("person", person,

There are two types of rows that will be added to crdt for the sake of maintaing presence information, the first is the room

    id: "presence~room~" + ( || uuid())
    , host: || {}
    , type: "presence~room"
    , ts:

and the second is for the people

    id: "presence~person~" +
    , roomId:
    , online: Boolean
    , ts: Date
    /* other properties that are on person objects */
    , type: "presence~person"

The contract for room input is that it's an object with a host property and a people reducible representing a stream of people data.

The contract for people is that they look like

    id: "some id"
    , ts: Date
    , online: Boolean

It's your job to have a stream of people data, the online flag is used to indicate whether someone is online. the id is used for identity and ts is used by cleanse to cleanse any people who havn't updated their ts recently (i.e. heartbeating)


npm install presence


  • Raynos

MIT Licenced