@midwayjs/socketio 4.0.0-alpha.1 → 4.0.0-beta.10
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/README.md +1 -1
- package/dist/framework.d.ts +2 -1
- package/dist/framework.js +16 -8
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +20 -0
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/framework.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager } from '
|
|
|
2
2
|
import { Application, IMidwaySocketIOOptions, Context, NextFunction } from './interface';
|
|
3
3
|
export declare class MidwaySocketIOFramework extends BaseFramework<Application, Context, IMidwaySocketIOOptions> {
|
|
4
4
|
private namespaceList;
|
|
5
|
-
app: Application;
|
|
6
5
|
protected connectionMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
|
|
6
|
+
protected socketServerPort: number;
|
|
7
7
|
configure(): IMidwaySocketIOOptions;
|
|
8
8
|
applicationInitialize(): Promise<void>;
|
|
9
9
|
run(): Promise<void>;
|
|
10
|
+
getSocketServerPort(): number;
|
|
10
11
|
protected beforeStop(): Promise<void>;
|
|
11
12
|
private loadMidwayController;
|
|
12
13
|
private addNamespace;
|
package/dist/framework.js
CHANGED
|
@@ -12,12 +12,11 @@ const util_1 = require("util");
|
|
|
12
12
|
const debug = (0, util_1.debuglog)('midway:socket.io');
|
|
13
13
|
const socket_io_1 = require("socket.io");
|
|
14
14
|
const core_2 = require("@midwayjs/core");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
15
16
|
let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseFramework {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.connectionMiddlewareManager = this.createMiddlewareManager();
|
|
20
|
-
}
|
|
17
|
+
namespaceList = [];
|
|
18
|
+
connectionMiddlewareManager = this.createMiddlewareManager();
|
|
19
|
+
socketServerPort;
|
|
21
20
|
configure() {
|
|
22
21
|
return this.configService.getConfiguration('socketIO');
|
|
23
22
|
}
|
|
@@ -39,15 +38,24 @@ let MidwaySocketIOFramework = class MidwaySocketIOFramework extends core_1.BaseF
|
|
|
39
38
|
this.logger.debug('[midway:socketio] init socket.io-redis ready!');
|
|
40
39
|
}
|
|
41
40
|
// listen port when http server not exist
|
|
42
|
-
if (this.configurationOptions.port) {
|
|
43
|
-
this.
|
|
44
|
-
|
|
41
|
+
if (typeof this.configurationOptions.port === 'number') {
|
|
42
|
+
let customPort = this.configurationOptions.port;
|
|
43
|
+
if (customPort === 0) {
|
|
44
|
+
customPort = await (0, utils_1.getFreePort)();
|
|
45
|
+
this.logger.info(`[midway:socketio] server has auto-assigned port ${customPort}`);
|
|
46
|
+
}
|
|
47
|
+
this.app.listen(customPort, this.configurationOptions);
|
|
48
|
+
this.socketServerPort = customPort;
|
|
49
|
+
this.logger.info(`[midway:socketio] Socket.io server port = ${customPort} start success`);
|
|
45
50
|
}
|
|
46
51
|
else if (this.applicationContext.hasObject(core_1.HTTP_SERVER_KEY)) {
|
|
47
52
|
this.app.attach(this.applicationContext.get(core_1.HTTP_SERVER_KEY), this.configurationOptions);
|
|
48
53
|
this.logger.info('[midway:socketio] Socket.io server start success and attach to web server');
|
|
49
54
|
}
|
|
50
55
|
}
|
|
56
|
+
getSocketServerPort() {
|
|
57
|
+
return this.socketServerPort;
|
|
58
|
+
}
|
|
51
59
|
async beforeStop() {
|
|
52
60
|
return new Promise(resolve => {
|
|
53
61
|
this.app.close(() => {
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFreePort = getFreePort;
|
|
4
|
+
const net_1 = require("net");
|
|
5
|
+
async function getFreePort() {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const server = (0, net_1.createServer)();
|
|
8
|
+
server.listen(0, () => {
|
|
9
|
+
try {
|
|
10
|
+
const port = server.address().port;
|
|
11
|
+
server.close();
|
|
12
|
+
resolve(port);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
reject(err);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/socketio",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.10",
|
|
4
4
|
"description": "Midway Web Framework for socket.io",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/core": "^4.0.0-
|
|
28
|
-
"fs-extra": "11.
|
|
27
|
+
"@midwayjs/core": "^4.0.0-beta.10",
|
|
28
|
+
"fs-extra": "11.3.3",
|
|
29
29
|
"socket.io-client": "4.8.1"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"url": "https://github.com/midwayjs/midway.git"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
40
|
+
"node": ">=20"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1b1856629913703f67304155aaf611ec936a81ac"
|
|
43
43
|
}
|