Skip to content

Commit

Permalink
Fix yui#44, remove dependency on yui.yahooapis.com.
Browse files Browse the repository at this point in the history
This allows Yeti to be used in environments where an
internet connection is not available.
  • Loading branch information
reid committed May 14, 2012
1 parent d18ee8d commit 24b5021
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/hub/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Agent(manager, registration) {
throw new Error("UA required.");
}

this.name = parseUA(this.ua.userAgent);
this.name = parseUA(this.ua);

this.seen = new Date();
this.waiting = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Hub.prototype._onRunConnection = function (socket) {
batch = self.batchManager.getBatchByAgent(id);

if (!id) {
// TODO handle error.
// TODO XXX Do not crash Yeti on bad input.
throw new Error("Expected ID!");
}

Expand Down
1 change: 0 additions & 1 deletion lib/hub/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ <h1><span class="yeti">Yeti</span></h1>
</div>
<p id="test"></p>
<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>
Expand Down
51 changes: 31 additions & 20 deletions lib/hub/view/public/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
(function () {
"use strict";

function getCookie(name) {
var parts = document.cookie.split(";"),
cookie,
i = 0,
l = parts.length;
name += "=";
for (; i < l; i++) {
cookie = parts[i].replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
if (cookie.indexOf(name) === 0) {
return cookie.substring(name.length, cookie.length);
}
}
return null;
}

window.Yeti = {
capture: function (resource) {
if (resource === "/") {
Expand All @@ -11,29 +26,25 @@
resource += "/socket.io";
resource = resource.substr(1); // strip leading slash

YUI().use("cookie", function (Y) {
var agentId = Y.Cookie.get("yeti-agent"),
socket = io.connect(io.util.uniqueUri({}) + "/capture", {
resource: resource
});

socket.json.emit("register", {
agentId: agentId,
ua: Y.UA
var agentId = getCookie("yeti-agent"),
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")
});
document.getElementById("test").innerHTML = "All set!";
});
socket.json.emit("register", {
agentId: agentId,
ua: window.navigator.userAgent
});

socket.on("navigate", function (test) {
document.location.href = test;
});
socket.on("ready", function (newId) {
agentId = newId;
document.cookie = "yeti-agent=" + newId +
";path=/;expires=Sat, 10 Mar 2029 08:00:00 GMT";
document.getElementById("test").innerHTML = "All set!";
});

socket.on("navigate", function (test) {
document.location.href = test;
});
}
};
Expand Down
21 changes: 16 additions & 5 deletions lib/hub/view/public/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,26 @@
socket = $yetify.socket,
Runner = null;

function getCookie(name) {
var parts = document.cookie.split(";"),
cookie,
i = 0,
l = parts.length;
name += "=";
for (; i < l; i++) {
cookie = parts[i].replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
if (cookie.indexOf(name) === 0) {
return cookie.substring(name.length, cookie.length);
}
}
return null;
}

function init(config) {
$yetify.socket = null;
$yetify.polls = 0;

var getCookie = function (sKey) {
// FIXME This breaks on IE6 and Android.
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
},
io = win.io,
var io = win.io,
socket,
resourcePaths = ["socket.io"];

Expand Down

0 comments on commit 24b5021

Please sign in to comment.