Commit 7e67c0f0 authored by Wandenberg's avatar Wandenberg

fix error handler for WebSocket connections to call onerror with proper event...

fix error handler for WebSocket connections to call onerror with proper event type. closes #213 and closes #214 issues
parent 3da6cb0e
......@@ -61,6 +61,8 @@ begin
require File.expand_path('misc/spec/spec_helper', project_dir)
include NginxTestHelper
template = File.read(File.expand_path('misc/nginx.conf', project_dir))
template.gsub!(/push_stream_subscriber_connection_ttl.*;/, 'push_stream_subscriber_connection_ttl 3s;')
template.gsub!(/push_stream_longpolling_connection_ttl.*;/, 'push_stream_longpolling_connection_ttl 3s;')
config = NginxTestHelper::Config.new "jasmine", {:configuration_template => (RUBY_PLATFORM =~ /darwin/) ? template.gsub('epoll', 'kqueue') : template }
abort "Could not start test server" if start_server(config).include?("[emerg]")
end
......
......@@ -535,7 +535,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
return;
}
this._closeCurrentConnection();
this.pushstream._onerror({type: ((event && ((event.type === "load") || (event.type === "close"))) || (this.pushstream.readyState === PushStream.CONNECTING)) ? "load" : "timeout"});
this.pushstream._onerror({type: ((event && ((event.type === "load") || ((event.type === "close") && (event.code === 1006)))) || (this.pushstream.readyState === PushStream.CONNECTING)) ? "load" : "timeout"});
};
/* wrappers */
......@@ -732,6 +732,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
_onframeloaded: function() {
Log4js.info("[Stream] frame loaded (disconnected by server)");
this.pushstream._onerror({type: "timeout"});
this.connection.onload = null;
this.disconnect();
},
......
......@@ -397,6 +397,36 @@ describe("PushStream", function() {
});
});
if ((mode === "websocket") || (mode === "stream")) {
describe("when the connection timeout", function() {
it("should call onerror callback with a timeout error type", function(done) {
var error = null;
pushstream = new PushStream({
modes: mode,
port: port,
onerror: function(err) {
error = err;
}
});
pushstream.addChannel(channelName);
pushstream.connect();
waitsForAndRuns(
function() { return error !== null; },
function() {
expect(pushstream.readyState).toBe(PushStream.CLOSED);
expect(error.type).toBe("timeout");
done();
},
6000
);
});
});
}
describe("when adding a new channel", function() {
it("should reconnect", function(done) {
var status = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment