Skip to content

Commit

Permalink
Merge branch 'r2.0.9' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pl committed Oct 21, 2013
2 parents 36aa5a0 + 696ef78 commit 28efbbc
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 23 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 2.0.9 (2013-10-21)

[CHANGED] Updated the json2 library

[FIXED] Catch exceptions when accessing localStorage and parsing its contents

[FIXED] Flush transport cache if it's corrupted

[FIXED] Stop raising exceptions when stats requests fail

[CHANGED] Don't report stats when offline

## 2.0.8 (2013-08-09)

[FIXED] Race condition in SockJS heartbeats
Expand Down
2 changes: 1 addition & 1 deletion JFile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ target_dir './dist'

src_dir './src'

version '2.0.8'
version '2.0.9'

bundle 'pusher.js' do
license 'pusher-licence.js'
Expand Down
9 changes: 9 additions & 0 deletions spec/javascripts/unit/timeline/timeline_sender_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe("TimelineSender", function() {
expect(onSend).toHaveBeenCalled();
});

it("should call back after an unsuccessful JSONP request", function() {
sender.send(false, onSend);

expect(onSend).not.toHaveBeenCalled();
var jsonpCallback = Pusher.JSONPRequest.send.calls[0].args[1];
jsonpCallback(true, undefined);
expect(onSend).toHaveBeenCalled();
});

it("should send secure JSONP requests when encrypted", function() {
sender = new Pusher.TimelineSender(timeline, {
encrypted: true,
Expand Down
12 changes: 12 additions & 0 deletions spec/javascripts/unit/timeline/timeline_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ describe("Timeline", function() {
});

describe("on send", function() {
beforeEach(function() {
spyOn(Pusher.Network, "isOnline").andReturn(true);
});

it("should include key, session id, features, version and params", function() {
var timeline = new Pusher.Timeline("foobar", 666, {
features: ["x", "y", "z"],
Expand Down Expand Up @@ -148,5 +152,13 @@ describe("Timeline", function() {
jasmine.any(Function)
);
});

it("should not send the timeline when offline", function() {
Pusher.Network.isOnline.andReturn(false);
timeline.log(Pusher.Timeline.INFO, {});

expect(timeline.send(sendJSONP, onSend)).toBe(false);
expect(sendJSONP).not.toHaveBeenCalled();
});
});
});
15 changes: 7 additions & 8 deletions src/json2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json2.js
2011-10-19
json2.js
2013-05-26
Public Domain.
Expand Down Expand Up @@ -159,13 +159,12 @@
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.

var JSON;
if (!JSON) {
if (typeof JSON !== 'object') {
JSON = {};
}

(function () {
'use strict';
'use strict';

function f(n) {
// Format integers to have at least two digits.
Expand All @@ -174,7 +173,7 @@ if (!JSON) {

if (typeof Date.prototype.toJSON !== 'function') {

Date.prototype.toJSON = function (key) {
Date.prototype.toJSON = function () {

return isFinite(this.valueOf())
? this.getUTCFullYear() + '-' +
Expand All @@ -188,7 +187,7 @@ if (!JSON) {

String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
Boolean.prototype.toJSON = function () {
return this.valueOf();
};
}
Expand Down Expand Up @@ -484,4 +483,4 @@ if (!JSON) {
throw new SyntaxError('JSON.parse');
};
}
}());
}());
14 changes: 9 additions & 5 deletions src/strategies/cached_strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@
function fetchTransportInfo() {
var storage = Pusher.Util.getLocalStorage();
if (storage) {
var info = storage.pusherTransport;
if (info) {
return JSON.parse(storage.pusherTransport);
try {
var info = storage.pusherTransport;
if (info) {
return JSON.parse(info);
}
} catch (e) {
flushTransportInfo();
}
}
return null;
Expand All @@ -85,7 +89,7 @@
transport: transport,
latency: latency
});
} catch(e) {
} catch (e) {
// catch over quota exceptions raised by localStorage
}
}
Expand All @@ -96,7 +100,7 @@
if (storage && storage.pusherTransport) {
try {
delete storage.pusherTransport;
} catch(e) {
} catch (e) {
storage.pusherTransport = undefined;
}
}
Expand Down
20 changes: 12 additions & 8 deletions src/timeline/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,25 @@
prototype.send = function(sendJSONP, callback) {
var self = this;

if (Pusher.Network.isOnline() === false) {
return false;
}

var data = {};
if (this.sent === 0) {
if (self.sent === 0) {
data = Pusher.Util.extend({
key: this.key,
features: this.options.features,
version: this.options.version
}, this.options.params || {});
key: self.key,
features: self.options.features,
version: self.options.version
}, self.options.params || {});
}
data.session = this.session;
data.timeline = this.events;
data.session = self.session;
data.timeline = self.events;
data = Pusher.Util.filterObject(data, function(v) {
return v !== undefined;
});

this.events = [];
self.events = [];
sendJSONP(data, function(error, result) {
if (!error) {
self.sent++;
Expand Down
2 changes: 1 addition & 1 deletion src/timeline/timeline_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
receiver: Pusher.JSONP
};
return Pusher.JSONPRequest.send(params, function(error, result) {
if (result.host) {
if (result && result.host) {
self.host = result.host;
}
if (callback) {
Expand Down

0 comments on commit 28efbbc

Please sign in to comment.