Skip to content

Commit 1245bf2

Browse files
committed
Release 1.6.4
1 parent 23f3f03 commit 1245bf2

File tree

3 files changed

+96
-32
lines changed

3 files changed

+96
-32
lines changed

History.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
1.6.4 / 2015-12-04
3+
==================
4+
5+
* ipv6 url support
6+
* README: fix the description of the `timestampRequests` option
7+
* transports: use `yeast` to generate the cache busting id
8+
* fix arraybuffer > base64 for binary sends
9+
210
1.6.3 / 2015-12-01
311
==================
412

engine.io.js

Lines changed: 86 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,20 @@ function Socket(uri, opts){
6363

6464
if (uri) {
6565
uri = parseuri(uri);
66-
opts.host = uri.host;
66+
opts.hostname = uri.host;
6767
opts.secure = uri.protocol == 'https' || uri.protocol == 'wss';
6868
opts.port = uri.port;
6969
if (uri.query) opts.query = uri.query;
70+
} else if (opts.host) {
71+
opts.hostname = parseuri(opts.host).host;
7072
}
7173

7274
this.secure = null != opts.secure ? opts.secure :
7375
(global.location && 'https:' == location.protocol);
7476

75-
if (opts.host) {
76-
var match = opts.host.match(/(\[.+\])(.+)?/)
77-
, pieces;
78-
79-
if (match) {
80-
opts.hostname = match[1];
81-
if (match[2]) opts.port = match[2].slice(1);
82-
} else {
83-
pieces = opts.host.split(':');
84-
opts.hostname = pieces.shift();
85-
if (pieces.length) opts.port = pieces.pop();
86-
}
87-
88-
// if `host` does not include a port and one is not specified manually,
89-
// use the protocol default
90-
if (!opts.port) opts.port = this.secure ? '443' : '80';
77+
if (opts.hostname && !opts.port) {
78+
// if no port is specified manually, use the protocol default
79+
opts.port = this.secure ? '443' : '80';
9180
}
9281

9382
this.agent = opts.agent || false;
@@ -810,13 +799,6 @@ function Transport (opts) {
810799

811800
Emitter(Transport.prototype);
812801

813-
/**
814-
* A counter used to prevent collisions in the timestamps used
815-
* for cache busting.
816-
*/
817-
818-
Transport.timestamps = 0;
819-
820802
/**
821803
* Emits an error.
822804
*
@@ -1640,6 +1622,7 @@ var Transport = _dereq_('../transport');
16401622
var parseqs = _dereq_('parseqs');
16411623
var parser = _dereq_('engine.io-parser');
16421624
var inherit = _dereq_('component-inherit');
1625+
var yeast = _dereq_('yeast');
16431626
var debug = _dereq_('debug')('engine.io-client:polling');
16441627

16451628
/**
@@ -1855,7 +1838,7 @@ Polling.prototype.uri = function(){
18551838

18561839
// cache busting is forced
18571840
if (false !== this.timestampRequests) {
1858-
query[this.timestampParam] = +new Date + '-' + Transport.timestamps++;
1841+
query[this.timestampParam] = yeast();
18591842
}
18601843

18611844
if (!this.supportsBinary && !query.sid) {
@@ -1875,10 +1858,11 @@ Polling.prototype.uri = function(){
18751858
query = '?' + query;
18761859
}
18771860

1878-
return schema + '://' + this.hostname + port + this.path + query;
1861+
var ipv6 = this.hostname.indexOf(':') !== -1;
1862+
return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
18791863
};
18801864

1881-
},{"../transport":4,"component-inherit":15,"debug":16,"engine.io-parser":18,"parseqs":27,"xmlhttprequest-ssl":10}],9:[function(_dereq_,module,exports){
1865+
},{"../transport":4,"component-inherit":15,"debug":16,"engine.io-parser":18,"parseqs":27,"xmlhttprequest-ssl":10,"yeast":31}],9:[function(_dereq_,module,exports){
18821866
(function (global){
18831867
/**
18841868
* Module dependencies.
@@ -1888,6 +1872,7 @@ var Transport = _dereq_('../transport');
18881872
var parser = _dereq_('engine.io-parser');
18891873
var parseqs = _dereq_('parseqs');
18901874
var inherit = _dereq_('component-inherit');
1875+
var yeast = _dereq_('yeast');
18911876
var debug = _dereq_('debug')('engine.io-client:websocket');
18921877

18931878
/**
@@ -2134,7 +2119,7 @@ WS.prototype.uri = function(){
21342119

21352120
// append timestamp to URI
21362121
if (this.timestampRequests) {
2137-
query[this.timestampParam] = +new Date;
2122+
query[this.timestampParam] = yeast();
21382123
}
21392124

21402125
// communicate binary support capabilities
@@ -2149,7 +2134,8 @@ WS.prototype.uri = function(){
21492134
query = '?' + query;
21502135
}
21512136

2152-
return schema + '://' + this.hostname + port + this.path + query;
2137+
var ipv6 = this.hostname.indexOf(':') !== -1;
2138+
return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
21532139
};
21542140

21552141
/**
@@ -2164,7 +2150,7 @@ WS.prototype.check = function(){
21642150
};
21652151

21662152
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
2167-
},{"../transport":4,"component-inherit":15,"debug":16,"engine.io-parser":18,"parseqs":27,"ws":30}],10:[function(_dereq_,module,exports){
2153+
},{"../transport":4,"component-inherit":15,"debug":16,"engine.io-parser":18,"parseqs":27,"ws":30,"yeast":31}],10:[function(_dereq_,module,exports){
21682154
// browser shim for xmlhttprequest module
21692155
var hasCORS = _dereq_('has-cors');
21702156

@@ -4218,5 +4204,75 @@ function ws(uri, protocols, opts) {
42184204

42194205
if (WebSocket) ws.prototype = WebSocket.prototype;
42204206

4207+
},{}],31:[function(_dereq_,module,exports){
4208+
'use strict';
4209+
4210+
var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
4211+
, length = 64
4212+
, map = {}
4213+
, seed = 0
4214+
, i = 0
4215+
, prev;
4216+
4217+
/**
4218+
* Return a string representing the specified number.
4219+
*
4220+
* @param {Number} num The number to convert.
4221+
* @returns {String} The string representation of the number.
4222+
* @api public
4223+
*/
4224+
function encode(num) {
4225+
var encoded = '';
4226+
4227+
do {
4228+
encoded = alphabet[num % length] + encoded;
4229+
num = Math.floor(num / length);
4230+
} while (num > 0);
4231+
4232+
return encoded;
4233+
}
4234+
4235+
/**
4236+
* Return the integer value specified by the given string.
4237+
*
4238+
* @param {String} str The string to convert.
4239+
* @returns {Number} The integer value represented by the string.
4240+
* @api public
4241+
*/
4242+
function decode(str) {
4243+
var decoded = 0;
4244+
4245+
for (i = 0; i < str.length; i++) {
4246+
decoded = decoded * length + map[str.charAt(i)];
4247+
}
4248+
4249+
return decoded;
4250+
}
4251+
4252+
/**
4253+
* Yeast: A tiny growing id generator.
4254+
*
4255+
* @returns {String} A unique id.
4256+
* @api public
4257+
*/
4258+
function yeast() {
4259+
var now = encode(+new Date());
4260+
4261+
if (now !== prev) return seed = 0, prev = now;
4262+
return now +'.'+ encode(seed++);
4263+
}
4264+
4265+
//
4266+
// Map each character to its index.
4267+
//
4268+
for (; i < length; i++) map[alphabet[i]] = i;
4269+
4270+
//
4271+
// Expose the `yeast`, `encode` and `decode` functions.
4272+
//
4273+
yeast.encode = encode;
4274+
yeast.decode = decode;
4275+
module.exports = yeast;
4276+
42214277
},{}]},{},[1])(1)
42224278
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "engine.io-client",
33
"description": "Client for the realtime Engine",
44
"license": "MIT",
5-
"version": "1.6.3",
5+
"version": "1.6.4",
66
"homepage": "https://github.com/socketio/engine.io-client",
77
"contributors": [
88
{
@@ -41,7 +41,7 @@
4141
"browserify": "6.2.0",
4242
"concat-stream": "1.4.6",
4343
"derequire": "1.2.0",
44-
"engine.io": "1.6.3",
44+
"engine.io": "1.6.4",
4545
"expect.js": "0.2.0",
4646
"express": "3.4.8",
4747
"istanbul": "0.2.3",

0 commit comments

Comments
 (0)