Skip to content

Commit

Permalink
Merge branch 'r2.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
pl committed Jan 9, 2014
2 parents 3fd7e6f + 04b4938 commit 272a656
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 58 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.1.6 (2013-01-09)

[NEW] Ping on offline events to detect disconnections quicker

[CHANGED] Added an exception when handshake does not contain the activity timeout

[FIXED] Encrypted transports not being cached correctly

## 2.1.5 (2013-12-16)

[NEW] Server can suggest a lower activity timeout in the handshake
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.5'
version '2.1.6'

bundle 'pusher.js' do
license 'pusher-licence.js'
Expand Down
2 changes: 1 addition & 1 deletion dist/flashfallback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Pusher JavaScript Library v2.1.5
* Pusher JavaScript Library v2.1.6
* http://pusherapp.com/
*
* Copyright 2011, Pusher
Expand Down
2 changes: 1 addition & 1 deletion dist/flashfallback.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 32 additions & 20 deletions dist/pusher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Pusher JavaScript Library v2.1.5
* Pusher JavaScript Library v2.1.6
* http://pusherapp.com/
*
* Copyright 2013, Pusher
Expand Down Expand Up @@ -599,7 +599,7 @@
}).call(this);

;(function() {
Pusher.VERSION = '2.1.5';
Pusher.VERSION = '2.1.6';
Pusher.PROTOCOL = 7;

// DEPRECATED: WS connection parameters
Expand Down Expand Up @@ -2452,7 +2452,8 @@
cached: returnWithOriginalContext(function(context, ttl, strategy){
return new Pusher.CachedStrategy(strategy, context.transports, {
ttl: ttl,
timeline: context.timeline
timeline: context.timeline,
encrypted: context.encrypted
});
}),

Expand Down Expand Up @@ -2607,6 +2608,9 @@
message = this.decodeMessage(message);

if (message.event === "pusher:connection_established") {
if (!message.data.activity_timeout) {
throw "No activity timeout specified in handshake";
}
return {
action: "connected",
id: message.data.socket_id,
Expand Down Expand Up @@ -2956,6 +2960,9 @@
});
Pusher.Network.bind("offline", function() {
self.timeline.info({ netinfo: "offline" });
if (self.state === "connected") {
self.sendActivityCheck();
}
});

this.updateStrategy();
Expand Down Expand Up @@ -3027,6 +3034,7 @@
self.runner = self.strategy.connect(0, callback);
} else {
if (handshake.action === "error") {
self.emit("error", { type: "HandshakeError", error: handshake.error });
self.timeline.error({ handshakeError: handshake.error });
} else {
self.abortConnecting(); // we don't support switching connections yet
Expand Down Expand Up @@ -3105,26 +3113,30 @@
}
};

/** @private */
prototype.sendActivityCheck = function() {
var self = this;
self.stopActivityCheck();
self.send_event('pusher:ping', {});
// wait for pong response
self.activityTimer = new Pusher.Timer(
self.options.pongTimeout,
function() {
self.timeline.error({ pong_timed_out: self.options.pongTimeout });
self.retryIn(0);
}
);
};

/** @private */
prototype.resetActivityCheck = function() {
this.stopActivityCheck();
var self = this;
self.stopActivityCheck();
// send ping after inactivity
if (!this.connection.supportsPing()) {
var self = this;
self.activityTimer = new Pusher.Timer(
self.activityTimeout,
function() {
self.send_event('pusher:ping', {});
// wait for pong response
self.activityTimer = new Pusher.Timer(
self.options.pongTimeout,
function() {
self.timeline.error({ pong_timed_out: self.options.pongTimeout });
self.retryIn(0);
}
);
}
);
if (!self.connection.supportsPing()) {
self.activityTimer = new Pusher.Timer(self.activityTimeout, function() {
self.sendActivityCheck();
});
}
};

Expand Down
31 changes: 17 additions & 14 deletions dist/pusher.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion spec/javascripts/integration/falling_back_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ describeIntegration("Falling back", function() {
data: JSON.stringify({
event: "pusher:connection_established",
data: {
socket_id: "123.456"
socket_id: "123.456",
activity_timeout: 120
}
})
});
Expand Down
4 changes: 4 additions & 0 deletions spec/javascripts/integration/pusher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ describeIntegration("Pusher", function() {
expect(channel1.members.get(pusher2.connection.socket_id))
.toBe(null);

expect(channel1.members.me).toEqual(member1);

channel1.bind("pusher:member_added", onMemberAdded);
channel2 = subscribe(pusher2, channelName, onSubscribed2);
});
Expand All @@ -337,6 +339,8 @@ describeIntegration("Pusher", function() {
.toEqual(member1);
expect(channel2.members.get(pusher2.connection.socket_id))
.toEqual(member2);

expect(channel2.members.me).toEqual(member2);
});
waitsFor(function() {
return onMemberAdded.calls.length > 0;
Expand Down
20 changes: 18 additions & 2 deletions spec/javascripts/unit/connection/connection_manager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,24 @@ describe("ConnectionManager", function() {
describe("on ping", function() {
it("should reply with a pusher:pong event", function() {
connection.emit("ping");
expect(connection.send_event)
.toHaveBeenCalledWith("pusher:pong", {}, undefined);
expect(connection.send_event).toHaveBeenCalledWith(
"pusher:pong", {}, undefined
);
});
});

describe("on offline event", function() {
it("should send an activity check and disconnect after no pong response", function() {
Pusher.Network.emit("offline");
expect(connection.send_event).toHaveBeenCalledWith(
"pusher:ping", {}, undefined
);

jasmine.Clock.tick(2344);
expect(manager.state).toEqual("connected");

jasmine.Clock.tick(1);
expect(manager.state).toEqual("connecting");
});
});
});
Expand Down
13 changes: 13 additions & 0 deletions spec/javascripts/unit/connection/protocol_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ describe("Protocol", function() {
});
});

it("should throw an exception when activity timeout is unspecified", function() {
expect(function() {
return Pusher.Protocol.processHandshake({
data: JSON.stringify({
event: "pusher:connection_established",
data: {
socket_id: "123.456"
}
})
});
}).toThrow("No activity timeout specified in handshake");
});

it("should throw an exception on invalid handshake", function() {
expect(function() {
return Pusher.Protocol.processHandshake({
Expand Down
10 changes: 10 additions & 0 deletions spec/javascripts/unit/strategies/strategy_builder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ describe("StrategyBuilder", function() {
expect(strategy.timeoutLimit).toEqual(8000);
});

it("should construct a cached strategy", function() {
var strategy = Pusher.StrategyBuilder.build([
[":def_transport", "sub", "flash", 2, { disableFlash: true }],
[":def", "strategy", [":cached", 1234, ":sub"]]
], { encrypted: true });
expect(strategy).toEqual(jasmine.any(Pusher.CachedStrategy));
expect(strategy.ttl).toEqual(1234);
expect(strategy.encrypted).toEqual(true);
});

it("should construct a first connected strategy", function() {
var strategy = Pusher.StrategyBuilder.build([
[":def_transport", "sub", "flash", 2, { disableFlash: true }],
Expand Down
42 changes: 25 additions & 17 deletions src/connection/connection_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
});
Pusher.Network.bind("offline", function() {
self.timeline.info({ netinfo: "offline" });
if (self.state === "connected") {
self.sendActivityCheck();
}
});

this.updateStrategy();
Expand Down Expand Up @@ -120,6 +123,7 @@
self.runner = self.strategy.connect(0, callback);
} else {
if (handshake.action === "error") {
self.emit("error", { type: "HandshakeError", error: handshake.error });
self.timeline.error({ handshakeError: handshake.error });
} else {
self.abortConnecting(); // we don't support switching connections yet
Expand Down Expand Up @@ -198,26 +202,30 @@
}
};

/** @private */
prototype.sendActivityCheck = function() {
var self = this;
self.stopActivityCheck();
self.send_event('pusher:ping', {});
// wait for pong response
self.activityTimer = new Pusher.Timer(
self.options.pongTimeout,
function() {
self.timeline.error({ pong_timed_out: self.options.pongTimeout });
self.retryIn(0);
}
);
};

/** @private */
prototype.resetActivityCheck = function() {
this.stopActivityCheck();
var self = this;
self.stopActivityCheck();
// send ping after inactivity
if (!this.connection.supportsPing()) {
var self = this;
self.activityTimer = new Pusher.Timer(
self.activityTimeout,
function() {
self.send_event('pusher:ping', {});
// wait for pong response
self.activityTimer = new Pusher.Timer(
self.options.pongTimeout,
function() {
self.timeline.error({ pong_timed_out: self.options.pongTimeout });
self.retryIn(0);
}
);
}
);
if (!self.connection.supportsPing()) {
self.activityTimer = new Pusher.Timer(self.activityTimeout, function() {
self.sendActivityCheck();
});
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/connection/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
message = this.decodeMessage(message);

if (message.event === "pusher:connection_established") {
if (!message.data.activity_timeout) {
throw "No activity timeout specified in handshake";
}
return {
action: "connected",
id: message.data.socket_id,
Expand Down
3 changes: 2 additions & 1 deletion src/strategies/strategy_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
cached: returnWithOriginalContext(function(context, ttl, strategy){
return new Pusher.CachedStrategy(strategy, context.transports, {
ttl: ttl,
timeline: context.timeline
timeline: context.timeline,
encrypted: context.encrypted
});
}),

Expand Down

0 comments on commit 272a656

Please sign in to comment.