Skip to content

Commit

Permalink
Servers should always return supportedConnectionTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Nov 22, 2011
1 parent b13e7b8 commit bb65dcf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 54 deletions.
12 changes: 5 additions & 7 deletions javascript/protocol/client.js
Expand Up @@ -98,13 +98,11 @@ Faye.Client = Faye.Class({
this._clientId = response.clientId;

var connectionTypes = response.supportedConnectionTypes;
if (connectionTypes) {
Faye.each(this._disabled, function(feature) {
var index = Faye.indexOf(connectionTypes, feature);
if (index >= 0) connectionTypes.splice(index, 1);
}, this);
this._selectTransport(connectionTypes);
}
Faye.each(this._disabled, function(feature) {
var index = Faye.indexOf(connectionTypes, feature);
if (index >= 0) connectionTypes.splice(index, 1);
}, this);
this._selectTransport(connectionTypes);

this.info('Handshake successful: ?', this._clientId);

Expand Down
22 changes: 10 additions & 12 deletions javascript/protocol/server.js
Expand Up @@ -139,18 +139,16 @@ Faye.Server = Faye.Class({
var clientConns = message.supportedConnectionTypes,
commonConns;

if (!local) {
response.supportedConnectionTypes = Faye.CONNECTION_TYPES;

if (clientConns) {
commonConns = Faye.filter(clientConns, function(conn) {
return Faye.indexOf(Faye.CONNECTION_TYPES, conn) >= 0;
});
if (commonConns.length === 0)
response.error = Faye.Error.conntypeMismatch(clientConns);
} else {
response.error = Faye.Error.parameterMissing('supportedConnectionTypes');
}
response.supportedConnectionTypes = Faye.CONNECTION_TYPES;

if (clientConns) {
commonConns = Faye.filter(clientConns, function(conn) {
return Faye.indexOf(Faye.CONNECTION_TYPES, conn) >= 0;
});
if (commonConns.length === 0)
response.error = Faye.Error.conntypeMismatch(clientConns);
} else {
response.error = Faye.Error.parameterMissing('supportedConnectionTypes');
}

response.successful = !response.error;
Expand Down
4 changes: 2 additions & 2 deletions lib/faye/protocol/client.rb
Expand Up @@ -93,8 +93,8 @@ def handshake(&block)
@state = CONNECTED
@client_id = response['clientId']

connection_types = response['supportedConnectionTypes']
select_transport(connection_types - @disabled) if connection_types
connection_types = response['supportedConnectionTypes'] - @disabled
select_transport(connection_types)

info('Handshake successful: ?', @client_id)

Expand Down
16 changes: 7 additions & 9 deletions lib/faye/protocol/server.rb
Expand Up @@ -125,15 +125,13 @@ def handshake(message, local = false, &callback)

client_conns = message['supportedConnectionTypes']

unless local
response['supportedConnectionTypes'] = CONNECTION_TYPES

if client_conns
common_conns = client_conns.select { |c| CONNECTION_TYPES.include?(c) }
response['error'] = Error.conntype_mismatch(*client_conns) if common_conns.empty?
else
response['error'] = Error.parameter_missing('supportedConnectionTypes')
end
response['supportedConnectionTypes'] = CONNECTION_TYPES

if client_conns
common_conns = client_conns.select { |c| CONNECTION_TYPES.include?(c) }
response['error'] = Error.conntype_mismatch(*client_conns) if common_conns.empty?
else
response['error'] = Error.parameter_missing('supportedConnectionTypes')
end

response['successful'] = response['error'].nil?
Expand Down
12 changes: 0 additions & 12 deletions spec/javascript/server/handshake_spec.js
Expand Up @@ -90,18 +90,6 @@ JS.ENV.Server.HandshakeSpec = JS.Test.describe("Server handshake", function() {
}, response)
})
}})

it("returns a successful response for local clients", function() { with(this) {
expect(engine, "createClient").yields(["clientid"])
server.handshake(message, true, function(response) {
assertEqual({
channel: "/meta/handshake",
successful: true,
version: "1.0",
clientId: "clientid"
}, response)
})
}})
}})

describe("with no matching supportedConnectionTypes", function() { with(this) {
Expand Down
12 changes: 0 additions & 12 deletions spec/ruby/server/handshake_spec.rb
Expand Up @@ -92,18 +92,6 @@
}
end
end

it "returns a successful response for local clients" do
engine.stub(:create_client).and_yield "clientid"
server.handshake(message, true) do |response|
response.should == {
"channel" => "/meta/handshake",
"successful" => true,
"version" => "1.0",
"clientId" => "clientid"
}
end
end
end

describe "with no matching supportedConnectionTypes" do
Expand Down

0 comments on commit bb65dcf

Please sign in to comment.