Socket
Socket
Sign inDemoInstall

engine.io-client

Package Overview
Dependencies
Maintainers
2
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

engine.io-client - npm Package Compare versions

Comparing version 4.0.0-alpha.1 to 4.0.0

dist/engine.io.min.js

38

CHANGELOG.md

@@ -0,1 +1,37 @@

# [4.0.0](https://github.com/socketio/engine.io-client/compare/v4.0.0-alpha.1...4.0.0) (2020-09-10)
More details about this release in the blog post: https://socket.io/blog/engine-io-4-release/
### Bug Fixes
* **react-native:** restrict the list of options for the WebSocket object ([2f5c948](https://github.com/socketio/engine.io-client/commit/2f5c948abe8fd1c0fdb010e88f96bd933a3792ea))
* use globalThis polyfill instead of self/global ([#634](https://github.com/socketio/engine.io-client/issues/634)) ([3f3a6f9](https://github.com/socketio/engine.io-client/commit/3f3a6f991404ef601252193382d2d2029cff6c45))
### Features
* strip debug from the browser bundle ([f7ba966](https://github.com/socketio/engine.io-client/commit/f7ba966e53f4609f755880be8fa504f7252b0817))
#### Links
- Diff: [v4.0.0-alpha.1...4.0.0](https://github.com/socketio/engine.io-client/compare/v4.0.0-alpha.1...4.0.0)
- Full diff: [3.4.0...4.0.0](https://github.com/socketio/engine.io-client/compare/3.4.0...4.0.0)
- Server release: [4.0.0](https://github.com/socketio/engine.io/releases/tag/4.0.0)
- ws version: [~7.2.1](https://github.com/websockets/ws/releases/tag/7.2.1)
## [3.4.1](https://github.com/socketio/engine.io-client/compare/3.4.0...3.4.1) (2020-04-17)
### Bug Fixes
* use globalThis polyfill instead of self/global ([357f01d](https://github.com/socketio/engine.io-client/commit/357f01d90448d8565b650377bc7cabb351d991bd))
#### Links
- Diff: [3.4.0...3.4.1](https://github.com/socketio/engine.io-client/compare/3.4.0...3.4.1)
- Server release: [3.4.1](https://github.com/socketio/engine.io/releases/tag/3.4.1)
- ws version: [~6.1.0](https://github.com/websockets/ws/releases/tag/6.1.0)
# [4.0.0-alpha.1](https://github.com/socketio/engine.io-client/compare/v4.0.0-alpha.0...v4.0.0-alpha.1) (2020-02-12)

@@ -10,2 +46,3 @@

- Diff: [v4.0.0-alpha.0...v4.0.0-alpha.1](https://github.com/socketio/engine.io-client/compare/v4.0.0-alpha.0...v4.0.0-alpha.1)
- Server release: [v4.0.0-alpha.1](https://github.com/socketio/engine.io/releases/tag/v4.0.0-alpha.1)

@@ -38,3 +75,4 @@ - ws version: [~7.2.1](https://github.com/websockets/ws/releases/tag/7.2.1)

- Diff: [3.4.0...v4.0.0-alpha.0](https://github.com/socketio/engine.io-client/compare/3.4.0...v4.0.0-alpha.0)
- Server release: [v4.0.0-alpha.0](https://github.com/socketio/engine.io/releases/tag/v4.0.0-alpha.0)
- ws version: [~7.2.1](https://github.com/websockets/ws/releases/tag/7.2.1)

9

lib/socket.js
const transports = require("./transports/index");
const Emitter = require("component-emitter");
const debug = require("debug")("engine.io-client:socket");
const index = require("indexof");
const parser = require("engine.io-parser");

@@ -85,8 +84,2 @@ const parseuri = require("parseuri");

// detect ReactNative environment
this.opts.isReactNative =
typeof navigator !== "undefined" &&
typeof navigator.product === "string" &&
navigator.product.toLowerCase() === "reactnative";
// set on handshake

@@ -647,3 +640,3 @@ this.id = null;

for (; i < j; i++) {
if (~index(this.transports, upgrades[i]))
if (~this.transports.indexOf(upgrades[i]))
filteredUpgrades.push(upgrades[i]);

@@ -650,0 +643,0 @@ }

const Polling = require("./polling");
const globalThis = require("../globalThis");

@@ -34,3 +35,3 @@ const rNewline = /\n/g;

// we need to consider multiple engines in the same page
callbacks = global.___eio = global.___eio || [];
callbacks = globalThis.___eio = globalThis.___eio || [];
}

@@ -37,0 +38,0 @@

@@ -7,2 +7,3 @@ /* global attachEvent */

const { pick } = require("../util");
const globalThis = require("../globalThis");

@@ -365,3 +366,3 @@ const debug = require("debug")("engine.io-client:polling-xhr");

} else if (typeof addEventListener === "function") {
const terminationEvent = "onpagehide" in self ? "pagehide" : "unload";
const terminationEvent = "onpagehide" in globalThis ? "pagehide" : "unload";
addEventListener(terminationEvent, unloadHandler, false);

@@ -368,0 +369,0 @@ }

@@ -105,3 +105,3 @@ const Transport = require("../transport");

// decode payload
parser.decodePayload(data, this.socket.binaryType, callback);
parser.decodePayload(data, this.socket.binaryType).forEach(callback);

@@ -154,11 +154,9 @@ // if an event did not trigger closing

write(packets) {
const self = this;
this.writable = false;
const callbackfn = function() {
self.writable = true;
self.emit("drain");
};
parser.encodePayload(packets, this.supportsBinary, function(data) {
self.doWrite(data, callbackfn);
parser.encodePayload(packets, data => {
this.doWrite(data, () => {
this.writable = true;
this.emit("drain");
});
});

@@ -165,0 +163,0 @@ }

@@ -6,27 +6,16 @@ const Transport = require("../transport");

const { pick } = require("../util");
const {
WebSocket,
usingBrowserWebSocket,
defaultBinaryType
} = require("./websocket-constructor");
const debug = require("debug")("engine.io-client:websocket");
let BrowserWebSocket, NodeWebSocket;
// detect ReactNative environment
const isReactNative =
typeof navigator !== "undefined" &&
typeof navigator.product === "string" &&
navigator.product.toLowerCase() === "reactnative";
if (typeof WebSocket !== "undefined") {
BrowserWebSocket = WebSocket;
} else if (typeof self !== "undefined") {
BrowserWebSocket = self.WebSocket || self.MozWebSocket;
}
if (typeof window === "undefined") {
try {
NodeWebSocket = require("ws");
} catch (e) {}
}
/**
* Get either the `WebSocket` or `MozWebSocket` globals
* in the browser or try to resolve WebSocket-compatible
* interface exposed by `ws` for Node-like environment.
*/
let WebSocketImpl = BrowserWebSocket || NodeWebSocket;
class WS extends Transport {

@@ -46,6 +35,2 @@ /**

}
this.usingBrowserWebSocket = BrowserWebSocket && !opts.forceNode;
if (!this.usingBrowserWebSocket) {
WebSocketImpl = NodeWebSocket;
}
// WebSockets support binary

@@ -77,15 +62,22 @@ this.supportsBinary = true;

const protocols = this.opts.protocols;
const opts = pick(
this.opts,
"agent",
"perMessageDeflate",
"pfx",
"key",
"passphrase",
"cert",
"ca",
"ciphers",
"rejectUnauthorized",
"localAddress"
);
let opts;
if (isReactNative) {
opts = pick(this.opts, "localAddress");
} else {
opts = pick(
this.opts,
"agent",
"perMessageDeflate",
"pfx",
"key",
"passphrase",
"cert",
"ca",
"ciphers",
"rejectUnauthorized",
"localAddress"
);
}
if (this.opts.extraHeaders) {

@@ -97,7 +89,7 @@ opts.headers = this.opts.extraHeaders;

this.ws =
this.usingBrowserWebSocket && !this.opts.isReactNative
usingBrowserWebSocket && !isReactNative
? protocols
? new WebSocketImpl(uri, protocols)
: new WebSocketImpl(uri)
: new WebSocketImpl(uri, protocols, opts);
? new WebSocket(uri, protocols)
: new WebSocket(uri)
: new WebSocket(uri, protocols, opts);
} catch (err) {

@@ -107,13 +99,4 @@ return this.emit("error", err);

if (this.ws.binaryType === undefined) {
this.supportsBinary = false;
}
this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
if (this.ws.supports && this.ws.supports.binary) {
this.supportsBinary = true;
this.ws.binaryType = "nodebuffer";
} else {
this.ws.binaryType = "arraybuffer";
}
this.addEventListeners();

@@ -164,3 +147,3 @@ }

const opts = {};
if (!self.usingBrowserWebSocket) {
if (!usingBrowserWebSocket) {
if (packet.options) {

@@ -185,3 +168,3 @@ opts.compress = packet.options.compress;

try {
if (self.usingBrowserWebSocket) {
if (usingBrowserWebSocket) {
// TypeError is thrown when passing the second argument on Safari

@@ -288,4 +271,4 @@ self.ws.send(data);

return (
!!WebSocketImpl &&
!("__initialize" in WebSocketImpl && this.name === WS.prototype.name)
!!WebSocket &&
!("__initialize" in WebSocket && this.name === WS.prototype.name)
);

@@ -292,0 +275,0 @@ }

// browser shim for xmlhttprequest module
const hasCORS = require("has-cors");
const globalThis = require("./globalThis");

@@ -34,3 +35,3 @@ module.exports = function(opts) {

try {
return new self[["Active"].concat("Object").join("X")](
return new globalThis[["Active"].concat("Object").join("X")](
"Microsoft.XMLHTTP"

@@ -37,0 +38,0 @@ );

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "4.0.0-alpha.1",
"version": "4.0.0",
"main": "lib/index.js",

@@ -28,8 +28,8 @@ "homepage": "https://github.com/socketio/engine.io-client",

"dependencies": {
"component-emitter": "1.2.1",
"base64-arraybuffer": "0.1.4",
"component-emitter": "~1.3.0",
"debug": "~4.1.0",
"engine.io-parser": "~4.0.0-alpha.0",
"engine.io-parser": "~4.0.1",
"has-cors": "1.1.0",
"indexof": "0.0.1",
"parseqs": "0.0.5",
"parseqs": "0.0.6",
"parseuri": "0.0.5",

@@ -47,3 +47,3 @@ "ws": "~7.2.1",

"blob": "^0.0.4",
"engine.io": "git+https://github.com/socketio/engine.io.git#v4",
"engine.io": "4.0.0",
"eslint": "^6.8.0",

@@ -55,4 +55,6 @@ "eslint-config-prettier": "^6.9.0",

"prettier": "^1.19.1",
"socket.io-browsers": "~1.0.4",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-remove-debug": "^0.1.0",
"zuul": "3.11.1",

@@ -66,5 +68,5 @@ "zuul-builder-webpack": "^1.2.0",

"test:browser": "zuul test/index.js",
"build": "webpack --config ./support/webpack.config.js",
"format:check": "prettier --check 'lib/**/*.js' 'test/**/*.js'",
"format:fix": "prettier --write 'lib/**/*.js' 'test/**/*.js'",
"build": "webpack --config ./support/webpack.config.js --config ./support/prod.config.js",
"format:check": "prettier --check 'lib/**/*.js' 'test/**/*.js' 'support/**/*.js'",
"format:fix": "prettier --write 'lib/**/*.js' 'test/**/*.js' 'support/**/*.js'",
"lint": "eslint lib/**/*.js test/**/*.js"

@@ -74,3 +76,5 @@ },

"ws": false,
"xmlhttprequest-ssl": "./lib/xmlhttprequest.js"
"xmlhttprequest-ssl": "./lib/xmlhttprequest.js",
"./lib/transports/websocket-constructor.js": "./lib/transports/websocket-constructor.browser.js",
"./lib/globalThis.js": "./lib/globalThis.browser.js"
},

@@ -77,0 +81,0 @@ "repository": {

@@ -22,6 +22,6 @@

// eio = Socket
var socket = eio('ws://localhost');
socket.on('open', function(){
socket.on('message', function(data){});
socket.on('close', function(){});
const socket = eio('ws://localhost');
socket.on('open', () => {
socket.on('message', (data) => {});
socket.on('close', () => {});
});

@@ -45,6 +45,6 @@ </script>

```js
var socket = require('engine.io-client')('ws://localhost');
socket.on('open', function(){
socket.on('message', function(data){});
socket.on('close', function(){});
const socket = require('engine.io-client')('ws://localhost');
socket.on('open', () => {
socket.on('message', (data) => {});
socket.on('close', () => {});
});

@@ -70,8 +70,8 @@ ```

<script>
var socket = new eio.Socket('ws://localhost/');
const socket = new eio.Socket('ws://localhost/');
socket.binaryType = 'blob';
socket.on('open', function () {
socket.on('open', () => {
socket.send(new Int8Array(5));
socket.on('message', function(blob){});
socket.on('close', function(){ });
socket.on('message', (blob) => {});
socket.on('close', () => {});
});

@@ -86,6 +86,6 @@ </script>

```js
var socket = require('engine.io-client')('ws://localhost');
socket.on('open', function(){
socket.on('message', function(data){});
socket.on('close', function(){});
const socket = require('engine.io-client')('ws://localhost');
socket.on('open', () => {
socket.on('message', (data) => {});
socket.on('close', () => {});
});

@@ -96,3 +96,3 @@ ```

```js
var opts = {
const opts = {
key: fs.readFileSync('test/fixtures/client.key'),

@@ -103,6 +103,6 @@ cert: fs.readFileSync('test/fixtures/client.crt'),

var socket = require('engine.io-client')('ws://localhost', opts);
socket.on('open', function(){
socket.on('message', function(data){});
socket.on('close', function(){});
const socket = require('engine.io-client')('ws://localhost', opts);
socket.on('open', () => {
socket.on('message', (data) => {});
socket.on('close', () => {});
});

@@ -113,3 +113,3 @@ ```

```js
var opts = {
const opts = {
extraHeaders: {

@@ -121,9 +121,44 @@ 'X-Custom-Header-For-My-Project': 'my-secret-access-token',

var socket = require('engine.io-client')('ws://localhost', opts);
socket.on('open', function(){
socket.on('message', function(data){});
socket.on('close', function(){});
const socket = require('engine.io-client')('ws://localhost', opts);
socket.on('open', () => {
socket.on('message', (data) => {});
socket.on('close', () => {});
});
```
In the browser, the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) object does not support additional headers.
In case you want to add some headers as part of some authentication mechanism, you can use the `transportOptions` attribute.
Please note that in this case the headers won't be sent in the WebSocket upgrade request.
```js
// WILL NOT WORK in the browser
require('engine.io-client')('http://localhost', {
extraHeaders: {
'X-Custom-Header-For-My-Project': 'will not be sent'
}
});
// WILL NOT WORK
require('engine.io-client')('http://localhost', {
transports: ['websocket'], // polling is disabled
transportOptions: {
polling: {
extraHeaders: {
'X-Custom-Header-For-My-Project': 'will not be sent'
}
}
}
});
// WILL WORK
require('engine.io-client')('http://localhost', {
transports: ['polling', 'websocket'],
transportOptions: {
polling: {
extraHeaders: {
'X-Custom-Header-For-My-Project': 'will be used'
}
}
}
});
```
## Features

@@ -130,0 +165,0 @@

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc