@feathersjs/socketio 5.0.0-pre.3 → 5.0.0-pre.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Feathers
3
+ Copyright (c) 2022 Feathers
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @feathersjs/socketio
2
2
 
3
3
  [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
4
- [![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
4
  [![Download Status](https://img.shields.io/npm/dm/@feathersjs/socketio.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/socketio)
5
+ [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx)
6
6
 
7
7
  > The Feathers Socket.io real-time API provider
8
8
 
@@ -18,6 +18,6 @@ Refer to the [Feathers SocketIO API documentation](https://docs.feathersjs.com/a
18
18
 
19
19
  ## License
20
20
 
21
- Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
21
+ Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
22
22
 
23
23
  Licensed under the [MIT license](LICENSE).
package/lib/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import http from 'http';
3
3
  import { Server, ServerOptions } from 'socket.io';
4
4
  import { Application } from '@feathersjs/feathers';
5
5
  declare module '@feathersjs/feathers/lib/declarations' {
6
- interface Application<ServiceTypes, AppSettings> {
6
+ interface Application<Services, Settings> {
7
7
  io: Server;
8
8
  listen(options: any): Promise<http.Server>;
9
9
  }
package/lib/index.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,7 +7,7 @@ const socket_io_1 = require("socket.io");
16
7
  const commons_1 = require("@feathersjs/commons");
17
8
  const transport_commons_1 = require("@feathersjs/transport-commons");
18
9
  const middleware_1 = require("./middleware");
19
- const debug = commons_1.createDebug('@feathersjs/socketio');
10
+ const debug = (0, commons_1.createDebug)('@feathersjs/socketio');
20
11
  function configureSocketio(port, options, config) {
21
12
  if (typeof port !== 'number') {
22
13
  config = options;
@@ -34,44 +25,40 @@ function configureSocketio(port, options, config) {
34
25
  const socketMap = new WeakMap();
35
26
  // Promise that resolves with the Socket.io `io` instance
36
27
  // when `setup` has been called (with a server)
37
- const done = new Promise(resolve => {
28
+ const done = new Promise((resolve) => {
38
29
  const { listen, setup } = app;
39
30
  Object.assign(app, {
40
- listen(...args) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (typeof listen === 'function') {
43
- // If `listen` already exists
44
- // usually the case when the app has been expressified
45
- return listen.call(this, ...args);
46
- }
47
- const server = http_1.default.createServer();
48
- yield this.setup(server);
49
- return server.listen(...args);
50
- });
31
+ async listen(...args) {
32
+ if (typeof listen === 'function') {
33
+ // If `listen` already exists
34
+ // usually the case when the app has been expressified
35
+ return listen.call(this, ...args);
36
+ }
37
+ const server = http_1.default.createServer();
38
+ await this.setup(server);
39
+ return server.listen(...args);
51
40
  },
52
- setup(server, ...rest) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- if (!this.io) {
55
- const io = this.io = new socket_io_1.Server(port || server, options);
56
- io.use(middleware_1.disconnect(app, getParams));
57
- io.use(middleware_1.params(app, socketMap));
58
- io.use(middleware_1.authentication(app, getParams));
59
- // In Feathers it is easy to hit the standard Node warning limit
60
- // of event listeners (e.g. by registering 10 services).
61
- // So we set it to a higher number. 64 should be enough for everyone.
62
- io.sockets.setMaxListeners(64);
63
- }
64
- if (typeof config === 'function') {
65
- debug('Calling SocketIO configuration function');
66
- config.call(this, this.io);
67
- }
68
- resolve(this.io);
69
- return setup.call(this, server, ...rest);
70
- });
41
+ async setup(server, ...rest) {
42
+ if (!this.io) {
43
+ const io = (this.io = new socket_io_1.Server(port || server, options));
44
+ io.use((0, middleware_1.disconnect)(app, getParams));
45
+ io.use((0, middleware_1.params)(app, socketMap));
46
+ io.use((0, middleware_1.authentication)(app, getParams));
47
+ // In Feathers it is easy to hit the standard Node warning limit
48
+ // of event listeners (e.g. by registering 10 services).
49
+ // So we set it to a higher number. 64 should be enough for everyone.
50
+ io.sockets.setMaxListeners(64);
51
+ }
52
+ if (typeof config === 'function') {
53
+ debug('Calling SocketIO configuration function');
54
+ config.call(this, this.io);
55
+ }
56
+ resolve(this.io);
57
+ return setup.call(this, server, ...rest);
71
58
  }
72
59
  });
73
60
  });
74
- app.configure(transport_commons_1.socket({
61
+ app.configure((0, transport_commons_1.socket)({
75
62
  done,
76
63
  socketMap,
77
64
  getParams,
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,gDAAwB;AACxB,yCAAkD;AAClD,iDAAkD;AAElD,qEAAuD;AAEvD,6CAAkF;AAElF,MAAM,KAAK,GAAG,qBAAW,CAAC,sBAAsB,CAAC,CAAC;AAYl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,EAAE,CAAC,GAAG,CAAC,IAAA,uBAAU,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;wBAClC,EAAE,CAAC,GAAG,CAAC,IAAA,mBAAM,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;wBAC9B,EAAE,CAAC,GAAG,CAAC,IAAA,2BAAc,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;wBAEtC,gEAAgE;wBAChE,wDAAwD;wBACxD,qEAAqE;wBACrE,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;qBAC/B;oBAED,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;wBAChC,KAAK,CAAC,yCAAyC,CAAC,CAAA;wBAChD,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;qBAC3B;oBAED,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;oBAEhB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,CAAA;gBAC1C,CAAC;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,GAAG,CAAC,SAAS,CACX,IAAA,0BAAM,EAAC;YACL,IAAI;YACJ,SAAS;YACT,SAAS;YACT,IAAI,EAAE,MAAM;SACb,CAAC,CACH,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AAED,iBAAS,iBAAiB,CAAA"}
@@ -3,7 +3,9 @@ import { Socket } from 'socket.io';
3
3
  export declare type ParamsGetter = (socket: Socket) => any;
4
4
  export declare type NextFunction = (err?: any) => void;
5
5
  export interface FeathersSocket extends Socket {
6
- feathers?: Params;
6
+ feathers?: Params & {
7
+ [key: string]: any;
8
+ };
7
9
  }
8
10
  export declare const disconnect: (app: Application, getParams: ParamsGetter) => (socket: FeathersSocket, next: NextFunction) => void;
9
11
  export declare const params: (_app: Application, socketMap: WeakMap<any, any>) => (socket: FeathersSocket, next: NextFunction) => void;
package/lib/middleware.js CHANGED
@@ -1,17 +1,8 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.authentication = exports.params = exports.disconnect = void 0;
13
4
  const commons_1 = require("@feathersjs/commons");
14
- const debug = commons_1.createDebug('@feathersjs/socketio/middleware');
5
+ const debug = (0, commons_1.createDebug)('@feathersjs/socketio/middleware');
15
6
  const disconnect = (app, getParams) => (socket, next) => {
16
7
  socket.once('disconnect', () => app.emit('disconnect', getParams(socket)));
17
8
  next();
@@ -27,7 +18,9 @@ const params = (_app, socketMap) => (socket, next) => {
27
18
  };
28
19
  exports.params = params;
29
20
  const authentication = (app, getParams, settings = {}) => (socket, next) => {
30
- const service = app.defaultAuthentication ? app.defaultAuthentication(settings.service) : null;
21
+ const service = app.defaultAuthentication
22
+ ? app.defaultAuthentication(settings.service)
23
+ : null;
31
24
  if (service === null) {
32
25
  return next();
33
26
  }
@@ -36,18 +29,20 @@ const authentication = (app, getParams, settings = {}) => (socket, next) => {
36
29
  if (authStrategies.length === 0) {
37
30
  return next();
38
31
  }
39
- service.parse(socket.handshake, null, ...authStrategies)
40
- .then((authentication) => __awaiter(void 0, void 0, void 0, function* () {
32
+ service
33
+ .parse(socket.handshake, null, ...authStrategies)
34
+ .then(async (authentication) => {
41
35
  if (authentication) {
42
36
  debug('Parsed authentication from HTTP header', authentication);
43
37
  socket.feathers.authentication = authentication;
44
- yield service.create(authentication, {
38
+ await service.create(authentication, {
45
39
  provider: 'socketio',
46
40
  connection: getParams(socket)
47
41
  });
48
42
  }
49
43
  next();
50
- })).catch(next);
44
+ })
45
+ .catch(next);
51
46
  };
52
47
  exports.authentication = authentication;
53
48
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iDAAkD;AAGlD,MAAM,KAAK,GAAG,qBAAW,CAAC,iCAAiC,CAAC,CAAC;AAQtD,MAAM,UAAU,GAAG,CAAC,GAAgB,EAAE,SAAuB,EAAE,EAAE,CACtE,CAAC,MAAsB,EAAE,IAAkB,EAAE,EAAE;IAC7C,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3E,IAAI,EAAE,CAAC;AACT,CAAC,CAAA;AAJU,QAAA,UAAU,cAIpB;AAEI,MAAM,MAAM,GAAG,CAAC,IAAiB,EAAE,SAA4B,EAAE,EAAE,CACxE,CAAC,MAAsB,EAAE,IAAkB,EAAE,EAAE;IAC7C,MAAM,CAAC,QAAQ,GAAG;QAChB,QAAQ,EAAE,UAAU;QACpB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO;KAClC,CAAC;IAEF,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEvC,IAAI,EAAE,CAAC;AACT,CAAC,CAAA;AAVU,QAAA,MAAM,UAUhB;AAEI,MAAM,cAAc,GAAG,CAAC,GAAgB,EAAE,SAAuB,EAAE,WAAgB,EAAE,EAAE,EAAE,CAC9F,CAAC,MAAsB,EAAE,IAAkB,EAAE,EAAE;IAC7C,MAAM,OAAO,GAAI,GAAW,CAAC,qBAAqB,CAAC,CAAC,CAAE,GAAW,CAAC,qBAAqB,CA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AAA;YAC/D,MAAM,CAAC,QAAQ,CAAC,cAAc,GAAG,cAAc,CAAA;YAC/C,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE;gBACnC,QAAQ,EAAE,UAAU;gBACpB,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC;aAC9B,CAAC,CAAA;SACH;QAED,IAAI,EAAE,CAAA;IACR,CAAC,CAAC;SACD,KAAK,CAAC,IAAI,CAAC,CAAA;AAChB,CAAC,CAAA;AAjCU,QAAA,cAAc,kBAiCxB"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@feathersjs/socketio",
3
3
  "description": "The Feathers Socket.io real-time API provider",
4
- "version": "5.0.0-pre.3",
4
+ "version": "5.0.0-pre.31",
5
5
  "homepage": "https://feathersjs.com",
6
6
  "main": "lib/",
7
+ "types": "lib/",
7
8
  "keywords": [
8
9
  "feathers",
9
10
  "feathers-plugin"
@@ -15,7 +16,8 @@
15
16
  },
16
17
  "repository": {
17
18
  "type": "git",
18
- "url": "git://github.com/feathersjs/feathers.git"
19
+ "url": "git://github.com/feathersjs/feathers.git",
20
+ "directory": "packages/socketio"
19
21
  },
20
22
  "author": {
21
23
  "name": "Feathers contributors",
@@ -40,7 +42,8 @@
40
42
  ],
41
43
  "scripts": {
42
44
  "prepublish": "npm run compile",
43
- "compile": "shx rm -rf lib/ && tsc",
45
+ "pack": "npm pack --pack-destination ../cli/test/build",
46
+ "compile": "shx rm -rf lib/ && tsc && npm run pack",
44
47
  "test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
45
48
  },
46
49
  "directories": {
@@ -50,23 +53,22 @@
50
53
  "access": "public"
51
54
  },
52
55
  "dependencies": {
53
- "@feathersjs/commons": "^5.0.0-pre.3",
54
- "@feathersjs/transport-commons": "^5.0.0-pre.3",
55
- "socket.io": "^4.0.1"
56
+ "@feathersjs/commons": "^5.0.0-pre.31",
57
+ "@feathersjs/feathers": "^5.0.0-pre.31",
58
+ "@feathersjs/transport-commons": "^5.0.0-pre.31",
59
+ "socket.io": "^4.5.2"
56
60
  },
57
61
  "devDependencies": {
58
- "@feathersjs/adapter-memory": "^5.0.0-pre.3",
59
- "@feathersjs/commons": "^5.0.0-pre.2",
60
- "@feathersjs/express": "^5.0.0-pre.3",
61
- "@feathersjs/feathers": "^5.0.0-pre.3",
62
- "@feathersjs/tests": "^5.0.0-pre.3",
63
- "@types/mocha": "^8.2.2",
64
- "@types/node": "^14.14.41",
62
+ "@feathersjs/express": "^5.0.0-pre.31",
63
+ "@feathersjs/memory": "^5.0.0-pre.31",
64
+ "@feathersjs/tests": "^5.0.0-pre.31",
65
+ "@types/mocha": "^10.0.0",
66
+ "@types/node": "^18.8.2",
65
67
  "lodash": "^4.17.21",
66
- "mocha": "^8.3.2",
67
- "shx": "^0.3.3",
68
- "socket.io-client": "^4.0.1",
69
- "typescript": "^4.2.4"
68
+ "mocha": "^10.0.0",
69
+ "shx": "^0.3.4",
70
+ "socket.io-client": "^4.5.2",
71
+ "typescript": "^4.8.4"
70
72
  },
71
- "gitHead": "d332eaca9945aab0c222413a7e46cec1c0601648"
73
+ "gitHead": "4500dbeb8cea566678cf88b3313a88efd93a2ed9"
72
74
  }
package/src/index.ts CHANGED
@@ -1,93 +1,104 @@
1
- import http from 'http';
2
- import { Server, ServerOptions } from 'socket.io';
3
- import { createDebug } from '@feathersjs/commons';
4
- import { Application } from '@feathersjs/feathers';
5
- import { socket } from '@feathersjs/transport-commons';
1
+ import http from 'http'
2
+ import { Server, ServerOptions } from 'socket.io'
3
+ import { createDebug } from '@feathersjs/commons'
4
+ import { Application } from '@feathersjs/feathers'
5
+ import { socket } from '@feathersjs/transport-commons'
6
6
 
7
- import { disconnect, params, authentication, FeathersSocket } from './middleware';
7
+ import { disconnect, params, authentication, FeathersSocket } from './middleware'
8
8
 
9
- const debug = createDebug('@feathersjs/socketio');
9
+ const debug = createDebug('@feathersjs/socketio')
10
10
 
11
11
  declare module '@feathersjs/feathers/lib/declarations' {
12
- interface Application<ServiceTypes, AppSettings> { // eslint-disable-line
13
- io: Server;
14
- listen (options: any): Promise<http.Server>;
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
+ interface Application<Services, Settings> {
14
+ // eslint-disable-line
15
+ io: Server
16
+ listen(options: any): Promise<http.Server>
15
17
  }
16
18
  }
17
19
 
18
- function configureSocketio (callback?: (io: Server) => void): (app: Application) => void;
19
- function configureSocketio (options: number | Partial<ServerOptions>, callback?: (io: Server) => void): (app: Application) => void;
20
- function configureSocketio (port: number, options?: Partial<ServerOptions>, callback?: (io: Server) => void): (app: Application) => void;
21
- function configureSocketio (port?: any, options?: any, config?: any) {
20
+ function configureSocketio(callback?: (io: Server) => void): (app: Application) => void
21
+ function configureSocketio(
22
+ options: number | Partial<ServerOptions>,
23
+ callback?: (io: Server) => void
24
+ ): (app: Application) => void
25
+ function configureSocketio(
26
+ port: number,
27
+ options?: Partial<ServerOptions>,
28
+ callback?: (io: Server) => void
29
+ ): (app: Application) => void
30
+ function configureSocketio(port?: any, options?: any, config?: any) {
22
31
  if (typeof port !== 'number') {
23
- config = options;
24
- options = port;
25
- port = null;
32
+ config = options
33
+ options = port
34
+ port = null
26
35
  }
27
36
 
28
37
  if (typeof options !== 'object') {
29
- config = options;
30
- options = {};
38
+ config = options
39
+ options = {}
31
40
  }
32
41
 
33
42
  return (app: Application) => {
34
43
  // Function that gets the connection
35
- const getParams = (socket: FeathersSocket) => socket.feathers;
44
+ const getParams = (socket: FeathersSocket) => socket.feathers
36
45
  // A mapping from connection to socket instance
37
- const socketMap = new WeakMap();
46
+ const socketMap = new WeakMap()
38
47
  // Promise that resolves with the Socket.io `io` instance
39
48
  // when `setup` has been called (with a server)
40
- const done = new Promise(resolve => {
41
- const { listen, setup } = app as any;
49
+ const done = new Promise((resolve) => {
50
+ const { listen, setup } = app as any
42
51
 
43
52
  Object.assign(app, {
44
- async listen (this: any, ...args: any[]) {
53
+ async listen(this: any, ...args: any[]) {
45
54
  if (typeof listen === 'function') {
46
55
  // If `listen` already exists
47
56
  // usually the case when the app has been expressified
48
- return listen.call(this, ...args);
57
+ return listen.call(this, ...args)
49
58
  }
50
59
 
51
- const server = http.createServer();
60
+ const server = http.createServer()
52
61
 
53
- await this.setup(server);
62
+ await this.setup(server)
54
63
 
55
- return server.listen(...args);
64
+ return server.listen(...args)
56
65
  },
57
66
 
58
- async setup (this: any, server: http.Server, ...rest: any[]) {
67
+ async setup(this: any, server: http.Server, ...rest: any[]) {
59
68
  if (!this.io) {
60
- const io = this.io = new Server(port || server, options);
69
+ const io = (this.io = new Server(port || server, options))
61
70
 
62
- io.use(disconnect(app, getParams));
63
- io.use(params(app, socketMap));
64
- io.use(authentication(app, getParams));
71
+ io.use(disconnect(app, getParams))
72
+ io.use(params(app, socketMap))
73
+ io.use(authentication(app, getParams))
65
74
 
66
75
  // In Feathers it is easy to hit the standard Node warning limit
67
76
  // of event listeners (e.g. by registering 10 services).
68
77
  // So we set it to a higher number. 64 should be enough for everyone.
69
- io.sockets.setMaxListeners(64);
78
+ io.sockets.setMaxListeners(64)
70
79
  }
71
80
 
72
81
  if (typeof config === 'function') {
73
- debug('Calling SocketIO configuration function');
74
- config.call(this, this.io);
82
+ debug('Calling SocketIO configuration function')
83
+ config.call(this, this.io)
75
84
  }
76
85
 
77
- resolve(this.io);
86
+ resolve(this.io)
78
87
 
79
- return setup.call(this, server, ...rest);
88
+ return setup.call(this, server, ...rest)
80
89
  }
81
- });
82
- });
83
-
84
- app.configure(socket({
85
- done,
86
- socketMap,
87
- getParams,
88
- emit: 'emit'
89
- }));
90
- };
90
+ })
91
+ })
92
+
93
+ app.configure(
94
+ socket({
95
+ done,
96
+ socketMap,
97
+ getParams,
98
+ emit: 'emit'
99
+ })
100
+ )
101
+ }
91
102
  }
92
103
 
93
- export = configureSocketio;
104
+ export = configureSocketio
package/src/middleware.ts CHANGED
@@ -1,59 +1,64 @@
1
- import { Application, Params } from '@feathersjs/feathers';
2
- import { createDebug } from '@feathersjs/commons';
3
- import { Socket } from 'socket.io';
1
+ import { Application, Params } from '@feathersjs/feathers'
2
+ import { createDebug } from '@feathersjs/commons'
3
+ import { Socket } from 'socket.io'
4
4
 
5
- const debug = createDebug('@feathersjs/socketio/middleware');
5
+ const debug = createDebug('@feathersjs/socketio/middleware')
6
6
 
7
- export type ParamsGetter = (socket: Socket) => any;
8
- export type NextFunction = (err?: any) => void;
7
+ export type ParamsGetter = (socket: Socket) => any
8
+ export type NextFunction = (err?: any) => void
9
9
  export interface FeathersSocket extends Socket {
10
- feathers?: Params
10
+ feathers?: Params & { [key: string]: any }
11
11
  }
12
12
 
13
- export const disconnect = (app: Application, getParams: ParamsGetter) =>
14
- (socket: FeathersSocket, next: NextFunction) => {
15
- socket.once('disconnect', () => app.emit('disconnect', getParams(socket)));
16
- next();
13
+ export const disconnect =
14
+ (app: Application, getParams: ParamsGetter) => (socket: FeathersSocket, next: NextFunction) => {
15
+ socket.once('disconnect', () => app.emit('disconnect', getParams(socket)))
16
+ next()
17
17
  }
18
18
 
19
- export const params = (_app: Application, socketMap: WeakMap<any, any>) =>
20
- (socket: FeathersSocket, next: NextFunction) => {
19
+ export const params =
20
+ (_app: Application, socketMap: WeakMap<any, any>) => (socket: FeathersSocket, next: NextFunction) => {
21
21
  socket.feathers = {
22
22
  provider: 'socketio',
23
23
  headers: socket.handshake.headers
24
- };
24
+ }
25
25
 
26
- socketMap.set(socket.feathers, socket);
26
+ socketMap.set(socket.feathers, socket)
27
27
 
28
- next();
28
+ next()
29
29
  }
30
30
 
31
- export const authentication = (app: Application, getParams: ParamsGetter, settings: any = {}) =>
31
+ export const authentication =
32
+ (app: Application, getParams: ParamsGetter, settings: any = {}) =>
32
33
  (socket: FeathersSocket, next: NextFunction) => {
33
- const service = (app as any).defaultAuthentication ? (app as any).defaultAuthentication(settings.service) : null;
34
+ const service = (app as any).defaultAuthentication
35
+ ? (app as any).defaultAuthentication(settings.service)
36
+ : null
34
37
 
35
38
  if (service === null) {
36
- return next();
39
+ return next()
37
40
  }
38
41
 
39
- const config = service.configuration;
40
- const authStrategies = config.parseStrategies || config.authStrategies || [];
42
+ const config = service.configuration
43
+ const authStrategies = config.parseStrategies || config.authStrategies || []
41
44
 
42
45
  if (authStrategies.length === 0) {
43
- return next();
46
+ return next()
44
47
  }
45
48
 
46
- service.parse(socket.handshake, null, ...authStrategies)
49
+ service
50
+ .parse(socket.handshake, null, ...authStrategies)
47
51
  .then(async (authentication: any) => {
48
52
  if (authentication) {
49
- debug('Parsed authentication from HTTP header', authentication);
50
- socket.feathers.authentication = authentication;
53
+ debug('Parsed authentication from HTTP header', authentication)
54
+ socket.feathers.authentication = authentication
51
55
  await service.create(authentication, {
52
56
  provider: 'socketio',
53
57
  connection: getParams(socket)
54
- });
58
+ })
55
59
  }
56
60
 
57
- next();
58
- }).catch(next);
61
+ next()
62
+ })
63
+ .catch(next)
59
64
  }