Browse files

Use socket.io.js from a relative mountpoint.

  • Loading branch information...
1 parent 6784969 commit bb9d9397f27a6b0f82b69efccc542a9f6f655d2a @reid reid committed Mar 13, 2012
Showing with 38 additions and 20 deletions.
  1. +4 −0 lib/hub/index.js
  2. +2 −1 lib/hub/view/index.html
  3. +32 −19 lib/hub/view/public/capture.js
View
4 lib/hub/index.js
@@ -449,6 +449,9 @@ Hub.prototype._createRouter = function () {
router.get(/\//, function () {
var server = this;
function onFile(err, html) {
+ html = html.toString("utf8");
+ html = html.replace("{{script}}",
+ "<script>Yeti.capture(\"" + (self.mountpoint || '') + "\");</script>");
html = plates.bind(html, {
"yeti-version": metadata.version,
"test": "Starting up..."
@@ -503,6 +506,7 @@ Hub.prototype.attachServer = function () {
// For client-side use later on.
this.mountpoint = route;
+ // this.io.set("resource", route + "/socket.io");
};
View
3 lib/hub/view/index.html
@@ -21,8 +21,9 @@
<p>Version <span id="yeti-version"></span>.</p>
</div>
<p id="test"></p>
- <script src="/socket.io/socket.io.js"></script>
+ <script src="socket.io/socket.io.js"></script>
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
<script src="public/capture.js"></script>
+ {{script}}
</body>
</html>
View
51 lib/hub/view/public/capture.js
@@ -1,24 +1,37 @@
-YUI().use("cookie", function (Y) {
- var agentId = Y.Cookie.get("yeti-agent");
+var Yeti = {
+ capture: function (resource) {
+ if (!resource) {
+ resource = "";
+ }
+ resource += "/socket.io";
+ resource = resource.substr(1); // strip leading slash
- var socket = io.connect(io.util.uniqueUri({}) + "/capture");
+ YUI().use("cookie", function (Y) {
+ var agentId = Y.Cookie.get("yeti-agent");
- socket.json.emit("register", {
- agentId: agentId,
- ua: Y.UA
- });
+ var socket = io.connect(io.util.uniqueUri({}) + "/capture", {
+ resource: resource
+ });
- socket.on("ready", function (newId) {
- agentId = newId;
- Y.Cookie.set("yeti-agent", newId, {
- path: "/",
- expires: new Date("March 10, 2029")
+ socket.json.emit("register", {
+ agentId: agentId,
+ ua: Y.UA
+ });
+
+ socket.on("ready", function (newId) {
+ agentId = newId;
+ Y.Cookie.set("yeti-agent", newId, {
+ path: "/",
+ expires: new Date("March 10, 2029")
+ });
+ document.getElementById("test").innerHTML = "All set!";
+ });
+
+ socket.on("test", function (test) {
+ document.location.href = test;
+ //console.log("got test", test);
+ });
});
- document.getElementById("test").innerHTML = "All set!";
- });
+ }
+};
- socket.on("test", function (test) {
- document.location.href = test;
- //console.log("got test", test);
- });
-});

0 comments on commit bb9d939

Please sign in to comment.