@feathersjs/socketio
Advanced tools
Comparing version 5.0.0-pre.0 to 5.0.0-pre.1
@@ -6,2 +6,6 @@ # Change Log | ||
# [5.0.0-pre.1](https://github.com/feathersjs/feathers/compare/v4.5.11...v5.0.0-pre.1) (2020-12-17) | ||
# [5.0.0-pre.0](https://github.com/feathersjs/feathers/compare/v4.5.4...v5.0.0-pre.0) (2020-05-19) | ||
@@ -23,2 +27,72 @@ | ||
# [5.0.0-pre.0](https://github.com/feathersjs/feathers/compare/v4.5.4...v5.0.0-pre.0) (2020-05-19) | ||
### Features | ||
* **transport-commons:** Remove legacy message format and unnecessary client timeouts ([#1939](https://github.com/feathersjs/feathers/issues/1939)) ([5538881](https://github.com/feathersjs/feathers/commit/5538881a08bc130de42c5984055729d8336f8615)) | ||
### BREAKING CHANGES | ||
* **transport-commons:** Removes the old message format and client service timeout | ||
## [4.5.11](https://github.com/feathersjs/feathers/compare/v4.5.10...v4.5.11) (2020-12-05) | ||
**Note:** Version bump only for package @feathersjs/socketio | ||
## [4.5.10](https://github.com/feathersjs/feathers/compare/v4.5.9...v4.5.10) (2020-11-08) | ||
**Note:** Version bump only for package @feathersjs/socketio | ||
## [4.5.9](https://github.com/feathersjs/feathers/compare/v4.5.8...v4.5.9) (2020-10-09) | ||
**Note:** Version bump only for package @feathersjs/socketio | ||
## [4.5.8](https://github.com/feathersjs/feathers/compare/v4.5.7...v4.5.8) (2020-08-12) | ||
**Note:** Version bump only for package @feathersjs/socketio | ||
## [4.5.7](https://github.com/feathersjs/feathers/compare/v4.5.6...v4.5.7) (2020-07-24) | ||
**Note:** Version bump only for package @feathersjs/socketio | ||
## [4.5.6](https://github.com/feathersjs/feathers/compare/v4.5.5...v4.5.6) (2020-07-12) | ||
**Note:** Version bump only for package @feathersjs/socketio | ||
## [4.5.5](https://github.com/feathersjs/feathers/compare/v4.5.4...v4.5.5) (2020-07-11) | ||
**Note:** Version bump only for package @feathersjs/socketio | ||
## [4.5.4](https://github.com/feathersjs/feathers/compare/v4.5.3...v4.5.4) (2020-04-29) | ||
@@ -25,0 +99,0 @@ |
151
lib/index.js
@@ -1,85 +0,74 @@ | ||
const socketio = require('socket.io'); | ||
const Proto = require('uberproto'); | ||
const http = require('http'); | ||
const { socket: commons } = require('@feathersjs/transport-commons'); | ||
const debug = require('debug')('@feathersjs/socketio'); | ||
const middleware = require('./middleware'); | ||
function configureSocketio (port, options, config) { | ||
if (typeof port !== 'number') { | ||
config = options; | ||
options = port; | ||
port = null; | ||
} | ||
if (typeof options !== 'object') { | ||
config = options; | ||
options = {}; | ||
} | ||
return function (app) { | ||
// Function that gets the connection | ||
const getParams = socket => socket.feathers; | ||
// A mapping from connection to socket instance | ||
const socketMap = new WeakMap(); | ||
if (!app.version || app.version < '3.0.0') { | ||
throw new Error('@feathersjs/socketio is not compatible with this version of Feathers. Use the latest at @feathersjs/feathers.'); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
// @ts-ignore | ||
const uberproto_1 = __importDefault(require("uberproto")); | ||
const debug_1 = __importDefault(require("debug")); | ||
const socket_io_1 = require("socket.io"); | ||
const http_1 = __importDefault(require("http")); | ||
const transport_commons_1 = require("@feathersjs/transport-commons"); | ||
const middleware_1 = require("./middleware"); | ||
const debug = debug_1.default('@feathersjs/socketio'); | ||
function configureSocketio(port, options, config) { | ||
if (typeof port !== 'number') { | ||
config = options; | ||
options = port; | ||
port = null; | ||
} | ||
// Promise that resolves with the Socket.io `io` instance | ||
// when `setup` has been called (with a server) | ||
const done = new Promise(resolve => { | ||
Proto.mixin({ | ||
listen (...args) { | ||
if (typeof this._super === 'function') { | ||
// If `listen` already exists | ||
// usually the case when the app has been expressified | ||
return this._super(...args); | ||
} | ||
const server = http.createServer(); | ||
this.setup(server); | ||
return server.listen(...args); | ||
}, | ||
setup (server) { | ||
if (!this.io) { | ||
const io = this.io = socketio.listen(port || server, options); | ||
io.use(middleware.disconnect(app, getParams)); | ||
io.use(middleware.params(app, socketMap)); | ||
io.use(middleware.authentication(app, getParams)); | ||
// In Feathers it is easy to hit the standard Node warning limit | ||
// of event listeners (e.g. by registering 10 services). | ||
// So we set it to a higher number. 64 should be enough for everyone. | ||
io.sockets.setMaxListeners(64); | ||
} | ||
if (typeof config === 'function') { | ||
debug('Calling SocketIO configuration function'); | ||
config.call(this, this.io); | ||
} | ||
resolve(this.io); | ||
return this._super.apply(this, arguments); | ||
if (typeof options !== 'object') { | ||
config = options; | ||
options = {}; | ||
} | ||
return (app) => { | ||
// Function that gets the connection | ||
const getParams = (socket) => socket.feathers; | ||
// A mapping from connection to socket instance | ||
const socketMap = new WeakMap(); | ||
if (!app.version || app.version < '3.0.0') { | ||
throw new Error('@feathersjs/socketio is not compatible with this version of Feathers. Use the latest at @feathersjs/feathers.'); | ||
} | ||
}, app); | ||
}); | ||
app.configure(commons({ | ||
done, | ||
socketMap, | ||
getParams, | ||
emit: 'emit' | ||
})); | ||
}; | ||
// Promise that resolves with the Socket.io `io` instance | ||
// when `setup` has been called (with a server) | ||
const done = new Promise(resolve => { | ||
uberproto_1.default.mixin({ | ||
listen(...args) { | ||
if (typeof this._super === 'function') { | ||
// If `listen` already exists | ||
// usually the case when the app has been expressified | ||
return this._super(...args); | ||
} | ||
const server = http_1.default.createServer(); | ||
this.setup(server); | ||
return server.listen(...args); | ||
}, | ||
setup(server) { | ||
if (!this.io) { | ||
const io = this.io = new socket_io_1.Server(port || server, options); | ||
io.use(middleware_1.disconnect(app, getParams)); | ||
io.use(middleware_1.params(app, socketMap)); | ||
io.use(middleware_1.authentication(app, getParams)); | ||
// In Feathers it is easy to hit the standard Node warning limit | ||
// of event listeners (e.g. by registering 10 services). | ||
// So we set it to a higher number. 64 should be enough for everyone. | ||
io.sockets.setMaxListeners(64); | ||
} | ||
if (typeof config === 'function') { | ||
debug('Calling SocketIO configuration function'); | ||
config.call(this, this.io); | ||
} | ||
resolve(this.io); | ||
return this._super.apply(this, arguments); | ||
} | ||
}, app); | ||
}); | ||
app.configure(transport_commons_1.socket({ | ||
done, | ||
socketMap, | ||
getParams, | ||
emit: 'emit' | ||
})); | ||
}; | ||
} | ||
module.exports = configureSocketio; | ||
module.exports.default = configureSocketio; | ||
//# sourceMappingURL=index.js.map |
@@ -1,46 +0,56 @@ | ||
const debug = require('debug')('@feathersjs/socketio/middleware'); | ||
exports.disconnect = (app, getParams) => (socket, next) => { | ||
socket.once('disconnect', () => app.emit('disconnect', getParams(socket))); | ||
next(); | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
exports.params = (app, socketMap) => (socket, next) => { | ||
socket.feathers = { | ||
provider: 'socketio', | ||
headers: socket.handshake.headers | ||
}; | ||
socketMap.set(socket.feathers, socket); | ||
next(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.authentication = (app, getParams, settings = {}) => (socket, next) => { | ||
const service = app.defaultAuthentication ? app.defaultAuthentication(settings.service) : null; | ||
if (service === null) { | ||
return next(); | ||
} | ||
const config = service.configuration; | ||
const authStrategies = config.parseStrategies || config.authStrategies || []; | ||
if (authStrategies.length === 0) { | ||
return next(); | ||
} | ||
service.parse(socket.handshake, null, ...authStrategies) | ||
.then(async authentication => { | ||
if (authentication) { | ||
debug('Parsed authentication from HTTP header', authentication); | ||
socket.feathers.authentication = authentication; | ||
await service.create(authentication, { | ||
provider: 'socketio', | ||
connection: getParams(socket) | ||
}); | ||
} | ||
next(); | ||
}).catch(next); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.authentication = exports.params = exports.disconnect = void 0; | ||
const debug_1 = __importDefault(require("debug")); | ||
const debug = debug_1.default('@feathersjs/socketio/middleware'); | ||
const disconnect = (app, getParams) => (socket, next) => { | ||
socket.once('disconnect', () => app.emit('disconnect', getParams(socket))); | ||
next(); | ||
}; | ||
exports.disconnect = disconnect; | ||
const params = (_app, socketMap) => (socket, next) => { | ||
socket.feathers = { | ||
provider: 'socketio', | ||
headers: socket.handshake.headers | ||
}; | ||
socketMap.set(socket.feathers, socket); | ||
next(); | ||
}; | ||
exports.params = params; | ||
const authentication = (app, getParams, settings = {}) => (socket, next) => { | ||
const service = app.defaultAuthentication ? app.defaultAuthentication(settings.service) : null; | ||
if (service === null) { | ||
return next(); | ||
} | ||
const config = service.configuration; | ||
const authStrategies = config.parseStrategies || config.authStrategies || []; | ||
if (authStrategies.length === 0) { | ||
return next(); | ||
} | ||
service.parse(socket.handshake, null, ...authStrategies) | ||
.then((authentication) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (authentication) { | ||
debug('Parsed authentication from HTTP header', authentication); | ||
socket.feathers.authentication = authentication; | ||
yield service.create(authentication, { | ||
provider: 'socketio', | ||
connection: getParams(socket) | ||
}); | ||
} | ||
next(); | ||
})).catch(next); | ||
}; | ||
exports.authentication = authentication; | ||
//# sourceMappingURL=middleware.js.map |
{ | ||
"name": "@feathersjs/socketio", | ||
"description": "The Feathers Socket.io real-time API provider", | ||
"version": "5.0.0-pre.0", | ||
"version": "5.0.0-pre.1", | ||
"homepage": "https://feathersjs.com", | ||
"main": "lib/", | ||
"types": "index.d.ts", | ||
"keywords": [ | ||
@@ -14,4 +13,4 @@ "feathers", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/feathers" | ||
"type": "github", | ||
"url": "https://github.com/sponsors/daffl" | ||
}, | ||
@@ -34,4 +33,15 @@ "repository": { | ||
}, | ||
"files": [ | ||
"CHANGELOG.md", | ||
"LICENSE", | ||
"README.md", | ||
"src/**", | ||
"lib/**", | ||
"*.d.ts", | ||
"*.js" | ||
], | ||
"scripts": { | ||
"test": "mocha --config ../../.mocharc.json" | ||
"prepublish": "npm run compile", | ||
"compile": "shx rm -rf lib/ && tsc", | ||
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts" | ||
}, | ||
@@ -45,22 +55,22 @@ "directories": { | ||
"dependencies": { | ||
"@feathersjs/transport-commons": "^5.0.0-pre.0", | ||
"@types/socket.io": "^2.1.6", | ||
"debug": "^4.1.1", | ||
"socket.io": "^2.3.0", | ||
"@feathersjs/transport-commons": "^5.0.0-pre.1", | ||
"debug": "^4.3.1", | ||
"socket.io": "^3.0.3", | ||
"uberproto": "^2.0.6" | ||
}, | ||
"devDependencies": { | ||
"@feathersjs/commons": "^5.0.0-pre.0", | ||
"@feathersjs/express": "^5.0.0-pre.0", | ||
"@feathersjs/feathers": "^5.0.0-pre.0", | ||
"@feathersjs/tests": "^5.0.0-pre.0", | ||
"@types/mocha": "^7.0.2", | ||
"@types/mongodb": "^3.5.17", | ||
"@types/node": "^14.0.1", | ||
"feathers-memory": "^4.1.0", | ||
"lodash": "^4.17.15", | ||
"mocha": "^7.1.2", | ||
"socket.io-client": "^2.3.0" | ||
"@feathersjs/adapter-memory": "^5.0.0-pre.1", | ||
"@feathersjs/commons": "^5.0.0-pre.1", | ||
"@feathersjs/express": "^5.0.0-pre.1", | ||
"@feathersjs/feathers": "^5.0.0-pre.1", | ||
"@feathersjs/tests": "^5.0.0-pre.1", | ||
"@types/mocha": "^8.0.4", | ||
"@types/node": "^14.14.10", | ||
"lodash": "^4.17.20", | ||
"mocha": "^8.2.1", | ||
"shx": "^0.3.3", | ||
"socket.io-client": "^3.0.3", | ||
"typescript": "^4.1.2" | ||
}, | ||
"gitHead": "e6b82b809c21da298501a12b82e72e166468994b" | ||
"gitHead": "3756506935c520fc50d4be416ff649c2158afdac" | ||
} |
# @feathersjs/socketio | ||
[![CI](https://github.com/feathersjs/feathers/workflows/Node.js%20CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3A%22Node.js+CI%22) | ||
[![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI) | ||
[![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/socketio)](https://david-dm.org/feathersjs/feathers?path=packages/socketio) | ||
@@ -5,0 +5,0 @@ [![Download Status](https://img.shields.io/npm/dm/@feathersjs/socketio.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/socketio) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
48764
4
12
264
12
2
+ Added@types/component-emitter@1.2.14(transitive)
+ Added@types/cookie@0.4.1(transitive)
+ Added@types/cors@2.8.17(transitive)
+ Addedcors@2.8.5(transitive)
+ Addedengine.io@4.1.2(transitive)
+ Addedengine.io-parser@4.0.3(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedsocket.io@3.1.2(transitive)
+ Addedsocket.io-adapter@2.1.0(transitive)
+ Addedsocket.io-parser@4.0.5(transitive)
+ Addedvary@1.1.2(transitive)
+ Addedws@7.4.6(transitive)
- Removed@types/socket.io@^2.1.6
- Removed@socket.io/component-emitter@3.1.2(transitive)
- Removed@types/engine.io@3.1.10(transitive)
- Removed@types/socket.io@2.1.13(transitive)
- Removed@types/socket.io-parser@3.0.0(transitive)
- Removedafter@0.8.2(transitive)
- Removedarraybuffer.slice@0.0.7(transitive)
- Removedbacko2@1.0.2(transitive)
- Removedblob@0.0.5(transitive)
- Removedcomponent-bind@1.0.0(transitive)
- Removedcomponent-emitter@1.2.1(transitive)
- Removedcomponent-inherit@0.0.3(transitive)
- Removeddebug@3.1.04.1.1(transitive)
- Removedengine.io@3.6.2(transitive)
- Removedengine.io-client@3.5.4(transitive)
- Removedengine.io-parser@2.2.1(transitive)
- Removedhas-binary2@1.0.3(transitive)
- Removedhas-cors@1.1.0(transitive)
- Removedindexof@0.0.1(transitive)
- Removedisarray@2.0.1(transitive)
- Removedms@2.0.0(transitive)
- Removedparseqs@0.0.6(transitive)
- Removedparseuri@0.0.6(transitive)
- Removedsocket.io@2.5.1(transitive)
- Removedsocket.io-adapter@1.1.2(transitive)
- Removedsocket.io-client@2.5.0(transitive)
- Removedsocket.io-parser@3.3.43.4.34.2.4(transitive)
- Removedto-array@0.1.4(transitive)
- Removedws@7.5.10(transitive)
- Removedxmlhttprequest-ssl@1.6.3(transitive)
- Removedyeast@0.1.2(transitive)
Updateddebug@^4.3.1
Updatedsocket.io@^3.0.3