Permalink
Browse files

Adding pubsub to client's OTDocument so we can see what messages comi…

…ng in look like from outside
  • Loading branch information...
1 parent 76812b6 commit 36e46a39e055b73773dbe9176c613dfdf04eb0a4 @fitzgen committed May 2, 2011
Showing with 9 additions and 1 deletion.
  1. +9 −1 client.js
View
@@ -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;
@@ -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);
}

0 comments on commit 36e46a3

Please sign in to comment.