Skip to content

Commit

Permalink
Merge branch 'r2.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pl committed Jul 8, 2013
2 parents 17c77c8 + 5239b0c commit c62fe75
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 67 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.1.1 (2013-07-08)

[FIXED] Disable transports that raise protocol errors

[FIXED] Keep trying all transports if a handshake raises an error

[CHANGED] Send less verbose error and closed event logs to stats

[FIXED] Add missing `connecting_in` event

[FIXED] Catch exceptions raised when accessing `window.localStorage` in some environments

## 2.1.0 (2013-06-17)

[NEW] Added support for clusters
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.1.0'
version '2.1.1'

bundle 'pusher.js' do
license 'pusher-licence.js'
Expand Down
6 changes: 4 additions & 2 deletions spec/javascripts/integration/cluster_config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ describeIntegration("Cluster Configuration", function() {
});
}

describeClusterTest({ ws: true, encrypted: false});
describeClusterTest({ ws: true, encrypted: true});
if (Pusher.WSTransport.isSupported() || Pusher.FlashTransport.isSupported()) {
describeClusterTest({ ws: true, encrypted: false});
describeClusterTest({ ws: true, encrypted: true});
}
describeClusterTest({ ws: false, encrypted: false});
describeClusterTest({ ws: false, encrypted: true});
});
27 changes: 27 additions & 0 deletions spec/javascripts/unit/connection/connection_manager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,13 @@ describe("ConnectionManager", function() {

describe("with 'backoff' action", function() {
var handshake;
var onConnectingIn;

beforeEach(function() {
handshake = { action: "backoff" };
onConnectingIn = jasmine.createSpy("onConnectingIn");

manager.bind("connecting_in", onConnectingIn);
strategy._callback(null, handshake);
});

Expand All @@ -242,6 +246,29 @@ describe("ConnectionManager", function() {
jasmine.Clock.tick(1);
expect(strategy.connect.calls.length).toEqual(2);
});

it("should emit 'connecting_in' event", function() {
expect(onConnectingIn.calls.length).toEqual(1);
expect(onConnectingIn).toHaveBeenCalledWith(1);
});
});

describe("with 'error' action", function() {
var handshake;
var onConnectingIn;

beforeEach(function() {
handshake = { action: "error", error: "boom" };
strategy._callback(null, handshake);
});

it("should log the error to the timeline", function() {
expect(timeline.error).toHaveBeenCalledWith({ handshakeError: "boom" });
});

it("should not abort the strategy", function() {
expect(strategy._abort).not.toHaveBeenCalled();
});
});
});

Expand Down
64 changes: 29 additions & 35 deletions spec/javascripts/unit/transports/abstract_transport_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,58 +249,52 @@ describe("AbstractTransport", function() {
this.transport.connect();
});

it("should emit error and closed events", function() {
it("should emit errors", function() {
var onError = jasmine.createSpy("onError");
var onClosed = jasmine.createSpy("onClosed");
this.transport.bind("error", onError);
this.transport.bind("closed", onClosed);

this.socket.onerror("We're doomed");
this.socket.onclose();

expect(onError).toHaveBeenCalledWith({
type: "WebSocketError",
error: "We're doomed"
});
expect(onError.calls.length).toEqual(1);
})

it("should emit a closed event with correct params", function() {
var onClosed = jasmine.createSpy("onClosed");
this.transport.bind("closed", onClosed);

this.socket.onclose({
code: 1234,
reason: "testing",
wasClean: true,
foo: "bar"
});

expect(onClosed).toHaveBeenCalledWith({
code: 1234,
reason: "testing",
wasClean: true
});
expect(onClosed.calls.length).toEqual(1);
expect(this.transport.state).toEqual("closed");
});

it("should log an error string to timeline", function() {
this.socket.onerror("error message");
expect(this.timeline.error).toHaveBeenCalledWith({
cid: 667,
error: "error message"
});
});
it("should emit a closed events without params when no details were provided", function() {
var onClosed = jasmine.createSpy("onClosed");
this.transport.bind("closed", onClosed);

it("should log an error object to timeline", function() {
this.socket.onerror({
name: "doom",
number: 1,
bool: true,
o: { nope: true },
f: function() {}
});
expect(this.timeline.error).toHaveBeenCalledWith({
cid: 667,
error: {
name: "doom",
number: 1,
bool: true,
o: "object",
f: "function"
}
});
this.socket.onclose();

expect(onClosed).toHaveBeenCalledWith(undefined);
expect(onClosed.calls.length).toEqual(1);
});

it("should log type of an error if it's not a string or object", function() {
this.socket.onerror(function() {});
expect(this.timeline.error).toHaveBeenCalledWith({
cid: 667,
error: "function"
});
it("should log an error without details to timeline", function() {
this.socket.onerror("error message");
expect(this.timeline.error).toHaveBeenCalledWith({ cid: 667 });
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ describe("AssistantToTheTransportManager", function() {
});
});

describe("after an opened connection closed with a protocol error (code 1002)", function() {
var connection;

beforeEach(function() {
connection = assistant.createConnection("x", 1, "a", {});
Pusher.Util.now.andReturn(1);
connection.emit("open");
Pusher.Util.now.andReturn(100001);
connection.emit("closed", { wasClean: true, code: 1002 });
});

it("should report its death to the manager", function() {
expect(transportManager.reportDeath).toHaveBeenCalled();
});
});

describe("after an opened connection closed with a unsupported error (code 1003)", function() {
var connection;

beforeEach(function() {
connection = assistant.createConnection("x", 1, "a", {});
Pusher.Util.now.andReturn(1);
connection.emit("open");
Pusher.Util.now.andReturn(100001);
connection.emit("closed", { wasClean: true, code: 1003 });
});

it("should report its death to the manager", function() {
expect(transportManager.reportDeath).toHaveBeenCalled();
});
});

describe("after an opened connection died after less than 2*maxPingDelay", function() {
var connection;
var assistant;
Expand Down
13 changes: 10 additions & 3 deletions src/connection/connection_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@
if (error) {
self.runner = self.strategy.connect(0, callback);
} else {
// we don't support switching connections yet
self.runner.abort();
self.handshakeCallbacks[handshake.action](handshake);
if (handshake.action === "error") {
self.timeline.error({ handshakeError: handshake.error });
} else {
// we don't support switching connections yet
self.runner.abort();
self.handshakeCallbacks[handshake.action](handshake);
}
}
};
self.runner = self.strategy.connect(0, callback);
Expand Down Expand Up @@ -169,6 +173,9 @@
prototype.retryIn = function(delay) {
var self = this;
self.timeline.info({ action: "retry", delay: delay });
if (delay > 0) {
self.emit("connecting_in", Math.round(delay / 1000));
}
self.retryTimer = new Pusher.Timer(delay || 0, function() {
self.disconnect();
self.connect();
Expand Down
30 changes: 10 additions & 20 deletions src/transports/abstract_transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,20 @@
/** @protected */
prototype.onError = function(error) {
this.emit("error", { type: 'WebSocketError', error: error });
this.timeline.error(this.buildTimelineMessage({
error: getErrorDetails(error)
}));
this.timeline.error(this.buildTimelineMessage({}));
};

/** @protected */
prototype.onClose = function(closeEvent) {
this.changeState("closed", closeEvent);
if (closeEvent) {
this.changeState("closed", {
code: closeEvent.code,
reason: closeEvent.reason,
wasClean: closeEvent.wasClean
});
} else {
this.changeState("closed");
}
this.socket = undefined;
};

Expand Down Expand Up @@ -240,21 +246,5 @@
return Pusher.Util.extend({ cid: this.id }, message);
};

function getErrorDetails(error) {
if (typeof error === "string") {
return error;
}
if (typeof error === "object") {
return Pusher.Util.mapObject(error, function(value) {
var valueType = typeof value;
if (valueType === "object" || valueType == "function") {
return valueType;
}
return value;
});
}
return typeof error;
}

Pusher.AbstractTransport = AbstractTransport;
}).call(this);
10 changes: 5 additions & 5 deletions src/transports/assistant_to_the_transport_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
pingTimer = null;
}

if (closeEvent.wasClean) {
return;
}

if (openTimestamp) {
if (closeEvent.code === 1002 || closeEvent.code === 1003) {
// we don't want to use transports not obeying the protocol
self.manager.reportDeath();
} else if (!closeEvent.wasClean && openTimestamp) {
// report deaths only for short-living transport
var lifespan = Pusher.Util.now() - openTimestamp;
if (lifespan < 2 * self.maxPingDelay) {
self.manager.reportDeath();
Expand Down
6 changes: 5 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@
},

getLocalStorage: function() {
return window.localStorage;
try {
return window.localStorage;
} catch (e) {
return undefined;
}
},

getClientFeatures: function() {
Expand Down

0 comments on commit c62fe75

Please sign in to comment.