Skip to content

Commit

Permalink
Allowed non-specifying of host:port combination
Browse files Browse the repository at this point in the history
  • Loading branch information
Wildhoney committed Aug 13, 2014
1 parent 2e32daa commit f490ea5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
34 changes: 26 additions & 8 deletions dist/ember-sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @type {String}
* @default 'localhost'
*/
host: 'localhost',
host: '',

/**
* @property secure
Expand Down Expand Up @@ -57,14 +57,32 @@
*/
init: function init() {

/**
* @property server
* @type {String}
*/
var server = '';

(function determineHost(controller) {

var host = $ember.get(controller, 'host'),
port = $ember.get(controller, 'port'),
scheme = $ember.get(controller, 'secure') === true ? 'https' : 'http',
path = $ember.get(controller, 'path') || '';

if (!host && !port) {
return;
}

// Use the host to compile the connect string.
server = !port ? '%@://%@/%@'.fmt(scheme, host, path)
: '%@://%@:%@/%@'.fmt(scheme, host, port, path);

})(this);

// Create the host:port string for connecting, and then attempt to establish
// a connection.
var host = $ember.get(this, 'host'),
port = $ember.get(this, 'port'),
scheme = $ember.get(this, 'secure') === true ? 'https' : 'http',
path = $ember.get(this, 'path') || '',
options = $ember.get(this, 'options') || {},
server = !port ? '%@://%@/%@'.fmt(scheme, host, path) : '%@://%@:%@/%@'.fmt(scheme, host, port, path),
var options = $ember.get(this, 'options') || {},
socket = $io(server, options);

socket.on('error', this.error);
Expand Down Expand Up @@ -314,4 +332,4 @@
});
});

})(window, window.Ember, window.io);
})(window, window.Ember, window.io);
2 changes: 1 addition & 1 deletion dist/ember-sockets.min.js

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

1 change: 0 additions & 1 deletion example/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
$window.App = Ember.Application.create({

Socket: EmberSockets.extend({
host: 'localhost',
controllers: ['index']
})

Expand Down
34 changes: 26 additions & 8 deletions package/ember-sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @type {String}
* @default 'localhost'
*/
host: 'localhost',
host: '',

/**
* @property secure
Expand Down Expand Up @@ -57,14 +57,32 @@
*/
init: function init() {

/**
* @property server
* @type {String}
*/
var server = '';

(function determineHost(controller) {

var host = $ember.get(controller, 'host'),
port = $ember.get(controller, 'port'),
scheme = $ember.get(controller, 'secure') === true ? 'https' : 'http',
path = $ember.get(controller, 'path') || '';

if (!host && !port) {
return;
}

// Use the host to compile the connect string.
server = !port ? '%@://%@/%@'.fmt(scheme, host, path)
: '%@://%@:%@/%@'.fmt(scheme, host, port, path);

})(this);

// Create the host:port string for connecting, and then attempt to establish
// a connection.
var host = $ember.get(this, 'host'),
port = $ember.get(this, 'port'),
scheme = $ember.get(this, 'secure') === true ? 'https' : 'http',
path = $ember.get(this, 'path') || '',
options = $ember.get(this, 'options') || {},
server = !port ? '%@://%@/%@'.fmt(scheme, host, path) : '%@://%@:%@/%@'.fmt(scheme, host, port, path),
var options = $ember.get(this, 'options') || {},
socket = $io(server, options);

socket.on('error', this.error);
Expand Down Expand Up @@ -314,4 +332,4 @@
});
});

})(window, window.Ember, window.io);
})(window, window.Ember, window.io);

0 comments on commit f490ea5

Please sign in to comment.