Skip to content

Commit

Permalink
Adding pubsub to client's OTDocument so we can see what messages comi…
Browse files Browse the repository at this point in the history
…ng in look like from outside
  • Loading branch information
fitzgen committed May 2, 2011
1 parent 76812b6 commit 36e46a3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,15 @@ define([
setTimeout(loop, 10);
}

function noop () {}

return {
OTDocument: function (opts) {
var outgoing = [],
incoming = [],
socket = opts.socket || error("socket is required"),
ui = opts.ui || error("ui is required"),
pubsub = opts.pubsub || { publish: noop, subscribe: noop },
docId = opts.id,
initialized = false;

Expand All @@ -168,16 +171,21 @@ define([
case "connect":
if ( ! initialized ) {
init(outgoing, incoming, socket, ui, event.data);
pubsub.publish("/ot/connect", [event.data]);
initialized = true;
} else {
error("Already initialized");
pubsub.publish("/ot/error", ["Already initialized"]);
throw new Error("Already initialized");
}
break;

case "update":
incoming.push(event.data);
pubsub.publish("/ot/update", [event.data]);
break;

default:
pubsub.publish("/ot/error", ["Unknown event type", event.type]);
throw new Error("Unknown event type: " + event.type);

}
Expand Down

0 comments on commit 36e46a3

Please sign in to comment.