Socket
Socket
Sign inDemoInstall

socketcluster-client

Package Overview
Dependencies
3
Maintainers
1
Versions
234
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.4 to 0.9.5

lib/xmlhttprequest.js

11

lib/clustersocket.js

@@ -12,3 +12,3 @@ /**

*/
if (!Object.create) {

@@ -78,3 +78,3 @@ Object.create = (function () {

this._intervalDuration = 1000;
this._counter = 0;
this._counter = null;

@@ -102,3 +102,3 @@ if (window.addEventListener) {

ActivityManager.prototype._triggerBlur = function () {
ActivityManager.prototype._triggerBlur = function () {
var self = this;

@@ -123,3 +123,3 @@

var now = (new Date()).getTime();
if (now - this._counter >= this._intervalDuration * 3) {
if (this._counter != null && now - this._counter >= this._intervalDuration * 3) {
this.emit('wakeup');

@@ -169,5 +169,6 @@ }

Socket.prototype.on.call(this, 'error', function () {
Socket.prototype.on.call(this, 'error', function (err) {
self.connecting = false;
self._emitBuffer = [];
Emitter.prototype.emit.call(self, 'error', err);
});

@@ -174,0 +175,0 @@

@@ -30,3 +30,3 @@ /**

function noop () {};
function noop(){}

@@ -46,3 +46,3 @@ /**

if ('object' == typeof uri) {
if (uri && 'object' == typeof uri) {
opts = uri;

@@ -81,3 +81,3 @@ uri = null;

this.timestampParam = opts.timestampParam || 't';
this.timestampRequests = !!opts.timestampRequests;
this.timestampRequests = opts.timestampRequests;
this.flashPath = opts.flashPath || '';

@@ -93,3 +93,3 @@ this.transports = opts.transports || ['polling', 'websocket', 'flashsocket'];

Socket.sockets.evs.emit('add', this);
};
}

@@ -184,4 +184,5 @@ /**

Socket.prototype.open = function () {
var transport = this.transports[0];
this.readyState = 'opening';
var transport = this.createTransport(this.transports[0]);
var transport = this.createTransport(transport);
transport.open();

@@ -197,7 +198,8 @@ this.setTransport(transport);

Socket.prototype.setTransport = function (transport) {
Socket.prototype.setTransport = function(transport){
debug('setting transport %s', transport.name);
var self = this;
if (this.transport) {
debug('clearing existing transport');
debug('clearing existing transport %s', this.transport.name);
this.transport.removeAllListeners();

@@ -211,14 +213,14 @@ }

transport
.on('drain', function () {
self.onDrain();
})
.on('packet', function (packet) {
self.onPacket(packet);
})
.on('error', function (e) {
self.onError(e);
})
.on('close', function () {
self.onClose('transport close');
});
.on('drain', function(){
self.onDrain();
})
.on('packet', function(packet){
self.onPacket(packet);
})
.on('error', function(e){
self.onError(e);
})
.on('close', function(){
self.onClose('transport close');
});
};

@@ -270,3 +272,3 @@

err.transport = transport.name;
self.emit('error', err);
self.emit('upgradeError', err);
}

@@ -291,4 +293,4 @@ });

self.emit('error', error);
};
self.emit('upgradeError', error);
}

@@ -295,0 +297,0 @@ transport.open();

@@ -33,3 +33,3 @@

this.agent = opts.agent || false;
};
}

@@ -36,0 +36,0 @@ /**

@@ -93,3 +93,4 @@ /**

WebSocket.__addTask(function () {
WS.prototype.doOpen.call(self);
self.socket = new WebSocket(self.uri());
self.addEventListeners();
});

@@ -148,3 +149,3 @@ });

if (843 != self.policyPort) {
WebSocket.loadFlashPolicyFile('xmlsocket://' + self.host + ':' + self.policyPort);
WebSocket.loadFlashPolicyFile('xmlsocket://' + self.hostname + ':' + self.policyPort);
}

@@ -151,0 +152,0 @@

@@ -35,4 +35,3 @@

var xhr
, xd = false
, isXProtocol = false;
, xd = false;

@@ -49,10 +48,5 @@ if (global.location) {

xd = opts.hostname != location.hostname || port != opts.port;
isXProtocol = opts.secure != isSSL;
}
xhr = util.request(xd, opts);
/* See #7 at http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx */
if (isXProtocol && global.XDomainRequest && xhr instanceof global.XDomainRequest) {
return new JSONP(opts);
}

@@ -59,0 +53,0 @@ if (xhr && !opts.forceJSONP) {

@@ -57,3 +57,3 @@ /**

}
};
}

@@ -164,25 +164,12 @@ /**

xhr.open(this.method, this.uri, this.async);
try {
debug('xhr open %s: %s', this.method, this.uri);
xhr.open(this.method, this.uri, this.async);
if ('POST' == this.method) {
try {
if (xhr.setRequestHeader) {
// xmlhttprequest
if ('POST' == this.method) {
try {
xhr.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
} else {
// xdomainrequest
xhr.contentType = 'text/plain';
}
} catch (e) {}
}
} catch (e) {}
}
if (this.xd && global.XDomainRequest && xhr instanceof XDomainRequest) {
xhr.onerror = function(e){
self.onError(e);
};
xhr.onload = function(){
self.onData(xhr.responseText);
};
xhr.onprogress = empty;
} else {
// ie6 check

@@ -207,11 +194,19 @@ if ('withCredentials' in xhr) {

if (undefined !== data) {
if (null != data) {
self.onData(data);
}
};
debug('xhr data %s', this.data);
xhr.send(this.data);
} catch (e) {
// Need to defer since .create() is called directly from the constructor
// and thus the 'error' event can only be only bound *after* this exception
// occurs. Therefore, also, we cannot throw here at all.
setTimeout(function() {
self.onError(e);
}, 0);
return;
}
debug('sending xhr with url %s | data %s', this.uri, this.data);
xhr.send(this.data);
if (xobject) {

@@ -269,5 +264,2 @@ this.index = Request.requestsCount++;

// xdomainrequest
this.xhr.onload = this.xhr.onerror = empty;
try {

@@ -274,0 +266,0 @@ this.xhr.abort();

@@ -208,5 +208,10 @@ /**

// cache busting is forced for IE / android / iOS6 ಠ_ಠ
if (global.ActiveXObject || util.ua.chromeframe || util.ua.android || util.ua.ios6 ||
this.timestampRequests) {
query[this.timestampParam] = +new Date;
if ('ActiveXObject' in global
|| util.ua.chromeframe
|| util.ua.android
|| util.ua.ios6
|| this.timestampRequests) {
if (false !== this.timestampRequests) {
query[this.timestampParam] = +new Date;
}
}

@@ -213,0 +218,0 @@

@@ -66,2 +66,14 @@ /**

this.socket = new WebSocket(uri, protocols, opts);
this.addEventListeners();
};
/**
* Adds event listeners to the socket
*
* @api private
*/
WS.prototype.addEventListeners = function() {
var self = this;
this.socket.onopen = function(){

@@ -68,0 +80,0 @@ self.onOpen();

@@ -193,2 +193,5 @@

exports.request = function request (xdomain, opts) {
opts = opts || {};
opts.xdomain = xdomain;
try {

@@ -199,6 +202,2 @@ var _XMLHttpRequest = require('xmlhttprequest');

if (xdomain && 'undefined' != typeof XDomainRequest && !exports.ua.hasCORS) {
return new XDomainRequest();
}
// XMLHttpRequest can be disabled on IE

@@ -205,0 +204,0 @@ try {

{
"name": "socketcluster-client",
"description": "Client side of SocketCluster",
"version": "0.9.4",
"version": "0.9.5",
"homepage": "https://github.com/topcloud/socketcluster-client",

@@ -45,6 +45,3 @@ "contributors": [

},
"readmeFilename": "README.md",
"readme": "# Engine.IO client\n\n[![Build Status](https://secure.travis-ci.org/LearnBoost/engine.io-client.png)](http://travis-ci.org/LearnBoost/engine.io-client)\n[![NPM version](https://badge.fury.io/js/engine.io-client.png)](http://badge.fury.io/js/engine.io-client)\n\nThis is the client for [Engine](http://github.com/learnboost/engine.io), the\nimplementation of transport-based cross-browser/cross-device bi-directional\ncommunication layer for [Socket.IO](http://github.com/learnboost/socket.io).\n\n## Hello World\n\n### With component\n\nEngine.IO is a [component](http://github.com/component/component), which\nmeans you can include it by using `require` on the browser:\n\n```js\nvar socket = require('engine.io')('ws://localhost');\nsocket.onopen = function(){\n socket.onmessage = function(data){};\n socket.onclose = function(){};\n};\n```\n\n### Standalone\n\nIf you decide not to use component you can find a `engine.io.js` file in\nthis repository, which is a standalone build you can use as follows:\n\n```html\n<script src=\"/path/to/build.js\"></script>\n<script>\n // eio = Socket\n var socket = eio('ws://localhost');\n socket.onopen = function(){\n socket.onmessage = function(data){};\n socket.onclose = function(){};\n };\n</script>\n```\n\n### Node.JS\n\nAdd `engine.io-client` to your `package.json` and then:\n\n```js\nvar socket = require('engine.io-client')('ws://localhost');\nsocket.onopen = function(){\n socket.onmessage = function(data){};\n socket.onclose = function(){};\n};\n```\n\n## Features\n\n- Lightweight\n - Lazyloads Flash transport\n- Isomorphic with WebSocket API\n- Written for node, runs on browser thanks to\n [browserbuild](http://github.com/learnboost/browserbuild)\n - Maximizes code readability / maintenance.\n - Simplifies testing.\n- Transports are independent of `Engine`\n - Easy to debug\n - Easy to unit test\n- Runs inside HTML5 WebWorker\n\n## API\n\n<hr><br>\n\n### Socket\n\nThe client class. Mixes in [Emitter](http://github.com/component/emitter).\nExposed as `eio` in the browser standalone build.\n\n#### Properties\n\n- `protocol` _(Number)_: protocol revision number\n- `onopen` (_Function_)\n - `open` event handler\n- `onmessage` (_Function_)\n - `message` event handler\n- `onclose` (_Function_)\n - `message` event handler\n\n#### Events\n\n- `open`\n - Fired upon successful connection.\n- `message`\n - Fired when data is received from the server.\n - **Arguments**\n - `String`: utf-8 encoded data\n- `close`\n - Fired upon disconnection.\n- `error`\n - Fired when an error occurs.\n- `flush`\n - Fired upon completing a buffer flush\n- `drain`\n - Fired after `drain` event of transport if writeBuffer is empty\n\n#### Methods\n\n- **constructor**\n - Initializes the client\n - **Parameters**\n - `String` uri\n - `Object`: optional, options object\n - **Options**\n - `agent` (`http.Agent`): `http.Agent` to use, defaults to `false` (NodeJS only)\n - `upgrade` (`Boolean`): defaults to true, whether the client should try\n to upgrade the transport from long-polling to something better.\n - `forceJSONP` (`Boolean`): forces JSONP for polling transport.\n - `timestampRequests` (`Boolean`): whether to add the timestamp with\n each transport request. Note: this is ignored if the browser is\n IE or Android, in which case requests are always stamped (`false`)\n - `timestampParam` (`String`): timestamp parameter (`t`)\n - `flashPath` (`String`): path to flash client files with trailing slash\n - `policyPort` (`Number`): port the policy server listens on (`843`)\n - `transports` (`Array`): a list of transports to try (in order).\n Defaults to `['polling', 'websocket', 'flashsocket']`. `Engine`\n always attempts to connect directly with the first one, provided the\n feature detection test for it passes.\n- `send`\n - Sends a message to the server\n - **Parameters**\n - `String`: data to send\n - `Function`: optional, callback upon `drain`\n- `close`\n - Disconnects the client.\n\n### Transport\n\nThe transport class. Private. _Inherits from EventEmitter_.\n\n#### Events\n\n- `poll`: emitted by polling transports upon starting a new request\n- `pollComplete`: emitted by polling transports upon completing a request\n- `drain`: emitted by polling transports upon a buffer drain\n\n## Reconnecting\n\nA `Socket` instance can be reused. After closing (either by calling\n`Socket#close()` or network close), you can summon `open` again.\n\n## Flash transport\n\nIn order for the Flash transport to work correctly, ensure the `flashPath`\nproperty points to the location where the files `web_socket.js`,\n`swfobject.js` and `WebSocketMainInsecure.swf` are located.\n\nThese files can be found here\n[https://github.com/gimite/web-socket-js.git](https://github.com/gimite/web-socket-js.git)\n\n## Tests\n\n`engine.io-client` is used to test\n[engine](http://github.com/learnboost/engine.io). Running the `engine.io`\ntest suite ensures the client works and vice-versa.\n\nAdditionally, `engine.io-client` has a standalone test suite you can run\nwith `make test` or in the browser with `make test-browser`.\n\n## Support\n\nThe support channels for `engine.io-client` are the same as `socket.io`:\n - irc.freenode.net **#socket.io**\n - [Google Groups](http://groups.google.com/group/socket_io)\n - [Website](http://socket.io)\n\n## Development\n\nTo contribute patches, run tests or benchmarks, make sure to clone the\nrepository:\n\n```\ngit clone git://github.com/LearnBoost/engine.io-client.git\n```\n\nThen:\n\n```\ncd engine.io-client\nnpm install\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2011 Guillermo Rauch &lt;guillermo@learnboost.com&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"_id": "socketcluster-client@0.9.3",
"_from": "socketcluster-client@>= 0.9.3"
"readmeFilename": "README.md"
}

@@ -1,213 +0,7 @@

# Engine.IO client
# SocketCluster client
[![Build Status](https://secure.travis-ci.org/LearnBoost/engine.io-client.png)](http://travis-ci.org/LearnBoost/engine.io-client)
[![NPM version](https://badge.fury.io/js/engine.io-client.png)](http://badge.fury.io/js/engine.io-client)
To build, use:
This is the client for [Engine](http://github.com/learnboost/engine.io), the
implementation of transport-based cross-browser/cross-device bi-directional
communication layer for [Socket.IO](http://github.com/learnboost/socket.io).
## Hello World
### With component
Engine.IO is a [component](http://github.com/component/component), which
means you can include it by using `require` on the browser:
```js
var socket = require('engine.io')('ws://localhost');
socket.onopen = function(){
socket.onmessage = function(data){};
socket.onclose = function(){};
};
```
### Standalone
If you decide not to use component you can find a `engine.io.js` file in
this repository, which is a standalone build you can use as follows:
```html
<script src="/path/to/build.js"></script>
<script>
// eio = Socket
var socket = eio('ws://localhost');
socket.onopen = function(){
socket.onmessage = function(data){};
socket.onclose = function(){};
};
</script>
```
### Node.JS
Add `engine.io-client` to your `package.json` and then:
```js
var socket = require('engine.io-client')('ws://localhost');
socket.onopen = function(){
socket.onmessage = function(data){};
socket.onclose = function(){};
};
```
## Features
- Lightweight
- Lazyloads Flash transport
- Isomorphic with WebSocket API
- Written for node, runs on browser thanks to
[browserbuild](http://github.com/learnboost/browserbuild)
- Maximizes code readability / maintenance.
- Simplifies testing.
- Transports are independent of `Engine`
- Easy to debug
- Easy to unit test
- Runs inside HTML5 WebWorker
## API
<hr><br>
### Socket
The client class. Mixes in [Emitter](http://github.com/component/emitter).
Exposed as `eio` in the browser standalone build.
#### Properties
- `protocol` _(Number)_: protocol revision number
- `onopen` (_Function_)
- `open` event handler
- `onmessage` (_Function_)
- `message` event handler
- `onclose` (_Function_)
- `message` event handler
#### Events
- `open`
- Fired upon successful connection.
- `message`
- Fired when data is received from the server.
- **Arguments**
- `String`: utf-8 encoded data
- `close`
- Fired upon disconnection.
- `error`
- Fired when an error occurs.
- `flush`
- Fired upon completing a buffer flush
- `drain`
- Fired after `drain` event of transport if writeBuffer is empty
#### Methods
- **constructor**
- Initializes the client
- **Parameters**
- `String` uri
- `Object`: optional, options object
- **Options**
- `agent` (`http.Agent`): `http.Agent` to use, defaults to `false` (NodeJS only)
- `upgrade` (`Boolean`): defaults to true, whether the client should try
to upgrade the transport from long-polling to something better.
- `forceJSONP` (`Boolean`): forces JSONP for polling transport.
- `timestampRequests` (`Boolean`): whether to add the timestamp with
each transport request. Note: this is ignored if the browser is
IE or Android, in which case requests are always stamped (`false`)
- `timestampParam` (`String`): timestamp parameter (`t`)
- `flashPath` (`String`): path to flash client files with trailing slash
- `policyPort` (`Number`): port the policy server listens on (`843`)
- `transports` (`Array`): a list of transports to try (in order).
Defaults to `['polling', 'websocket', 'flashsocket']`. `Engine`
always attempts to connect directly with the first one, provided the
feature detection test for it passes.
- `send`
- Sends a message to the server
- **Parameters**
- `String`: data to send
- `Function`: optional, callback upon `drain`
- `close`
- Disconnects the client.
### Transport
The transport class. Private. _Inherits from EventEmitter_.
#### Events
- `poll`: emitted by polling transports upon starting a new request
- `pollComplete`: emitted by polling transports upon completing a request
- `drain`: emitted by polling transports upon a buffer drain
## Reconnecting
A `Socket` instance can be reused. After closing (either by calling
`Socket#close()` or network close), you can summon `open` again.
## Flash transport
In order for the Flash transport to work correctly, ensure the `flashPath`
property points to the location where the files `web_socket.js`,
`swfobject.js` and `WebSocketMainInsecure.swf` are located.
These files can be found here
[https://github.com/gimite/web-socket-js.git](https://github.com/gimite/web-socket-js.git)
## Tests
`engine.io-client` is used to test
[engine](http://github.com/learnboost/engine.io). Running the `engine.io`
test suite ensures the client works and vice-versa.
Additionally, `engine.io-client` has a standalone test suite you can run
with `make test` or in the browser with `make test-browser`.
## Support
The support channels for `engine.io-client` are the same as `socket.io`:
- irc.freenode.net **#socket.io**
- [Google Groups](http://groups.google.com/group/socket_io)
- [Website](http://socket.io)
## Development
To contribute patches, run tests or benchmarks, make sure to clone the
repository:
```
git clone git://github.com/LearnBoost/engine.io-client.git
```
Then:
```
cd engine.io-client
npm install
```
## License
(The MIT License)
Copyright (c) 2011 Guillermo Rauch &lt;guillermo@learnboost.com&gt;
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
component build -s socketCluster -n socketcluster -o .
```

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc