Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created January 8, 2013 03:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/4480862 to your computer and use it in GitHub Desktop.
Save Raynos/4480862 to your computer and use it in GitHub Desktop.
var PUBNUB = require("pubnub-browserify")
var config = require("./config")
var duplex = require("pubnub-stream/duplex")
module.exports = communication
function communication(doc, channel) {
var client = PUBNUB.init({
subscribe_key: config.subscribe_key
, publish_key: config.publish_key
})
var stream = duplex(client, channel)
stream.pipe(doc.createStream()).pipe(stream)
}
var crdt = require("crdt")
var communication = require("./communication")
var doc = new crdt.Doc()
communication(doc, "my room")
// And now it's synced to that room.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment