oox 0.3.4 → 0.3.5
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 +13 -0
- package/app.js +1 -1
- package/bin/cli.js +45 -12
- package/bin/configurer.js +6 -9
- package/bin/register.js +48 -15
- package/bin/starter.js +8 -0
- package/config.js +116 -0
- package/index.js +67 -46
- package/keepalive-connection.js +13 -0
- package/modules/http/index.js +52 -63
- package/modules/http/router.js +9 -4
- package/modules/index.js +78 -74
- package/modules/module.js +0 -9
- package/modules/socketio/adapter.js +24 -12
- package/modules/socketio/server.js +33 -15
- package/modules/socketio/utils.js +3 -1
- package/package.json +9 -5
- package/registry.js +90 -6
- package/samples/keepalive-connection-sample.js +40 -23
- package/types/app.d.ts +20 -20
- package/types/bin/configurer.d.ts +3 -1
- package/types/bin/register.d.ts +2 -1
- package/types/bin/starter.d.ts +1 -2
- package/types/config.d.ts +54 -0
- package/types/index.d.ts +34 -31
- package/types/keepalive-connection.d.ts +40 -15
- package/types/modules/http/index.d.ts +4 -7
- package/types/modules/index.d.ts +36 -21
- package/types/modules/module.d.ts +9 -9
- package/types/modules/socketio/adapter.d.ts +1 -1
- package/types/modules/socketio/server.d.ts +5 -3
- package/types/modules/socketio/utils.d.ts +3 -1
- package/types/registry.d.ts +28 -3
- package/types/samples/keepalive-connection-sample.d.ts +20 -11
- package/utils.js +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
enabled
|
|
1
|
+
export interface ModuleConfig {
|
|
2
|
+
enabled?: boolean;
|
|
3
3
|
}
|
|
4
|
-
export default class Module {
|
|
5
|
-
config: ModuleConfig;
|
|
6
|
-
name: string;
|
|
7
|
-
setConfig(config: any): void;
|
|
8
|
-
getConfig(): ModuleConfig;
|
|
9
|
-
serve(): Promise<void>;
|
|
10
|
-
stop(): Promise<void>;
|
|
4
|
+
export default abstract class Module {
|
|
5
|
+
abstract config: ModuleConfig;
|
|
6
|
+
abstract name: string;
|
|
7
|
+
abstract setConfig(config: any): void;
|
|
8
|
+
abstract getConfig(): ModuleConfig;
|
|
9
|
+
abstract serve(): Promise<void>;
|
|
10
|
+
abstract stop(): Promise<void>;
|
|
11
11
|
}
|
|
@@ -10,5 +10,5 @@ export default class SocketIOAdapter extends SampleKeepAliveConnectionAdapter<So
|
|
|
10
10
|
DISCONNECT: string;
|
|
11
11
|
ERROR: string;
|
|
12
12
|
};
|
|
13
|
-
newConnection(
|
|
13
|
+
newConnection(identify: string | URL | oox.KeepAliveConnectionData): oox.KeepAliveConnection<Socket>;
|
|
14
14
|
}
|
|
@@ -5,7 +5,8 @@ import * as oox from '../../index.js';
|
|
|
5
5
|
import { Module, ModuleConfig } from '../../index.js';
|
|
6
6
|
import { Socket } from './socket.js';
|
|
7
7
|
import SocketIOAdapter from './adapter.js';
|
|
8
|
-
export declare class SocketIOConfig
|
|
8
|
+
export declare class SocketIOConfig implements ModuleConfig {
|
|
9
|
+
enabled: boolean;
|
|
9
10
|
port: number;
|
|
10
11
|
path: string;
|
|
11
12
|
origin: string | string[];
|
|
@@ -20,9 +21,10 @@ export default class SocketIOServer extends Module {
|
|
|
20
21
|
#private;
|
|
21
22
|
name: string;
|
|
22
23
|
config: SocketIOConfig;
|
|
23
|
-
server: http.Server | https.Server;
|
|
24
|
-
socketServer: Server;
|
|
24
|
+
server: http.Server | https.Server | null;
|
|
25
|
+
socketServer: Server | null;
|
|
25
26
|
adapter: SocketIOAdapter;
|
|
27
|
+
constructor();
|
|
26
28
|
getURL(): URL;
|
|
27
29
|
setConfig(config: SocketIOConfig): void;
|
|
28
30
|
getConfig(): SocketIOConfig;
|
|
@@ -2,7 +2,9 @@ export declare enum OOXEvent {
|
|
|
2
2
|
READY = "oox:ready",
|
|
3
3
|
ENABLED = "oox:enabled",
|
|
4
4
|
DISABLED = "oox:disabled",
|
|
5
|
-
|
|
5
|
+
REGISTRY_SYNC_CONNECTIONS = "oox:registry:sync_connections",
|
|
6
|
+
REGISTRY_SUBSCRIBE = "oox:registry:subscribe",
|
|
7
|
+
REGISTRY_NOTIFY = "oox:registry:notify"
|
|
6
8
|
}
|
|
7
9
|
export declare function isWebSocketURL(url: string | URL): boolean;
|
|
8
10
|
export declare function genWebSocketURL(url: string): URL;
|
package/types/registry.d.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReturnsBody } from './index.js';
|
|
2
|
+
import { KeepAliveConnection, KeepAliveConnectionData, KeepAliveNativeConnection } from './keepalive-connection.js';
|
|
2
3
|
export interface SyncConnectionsQuery {
|
|
3
4
|
name?: string | string[];
|
|
4
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* 取消订阅连接列表
|
|
8
|
+
* @param connection
|
|
9
|
+
*/
|
|
10
|
+
export declare function unsubscribe(connection: KeepAliveConnection<KeepAliveNativeConnection>): void;
|
|
11
|
+
/**
|
|
12
|
+
* 订阅连接列表
|
|
13
|
+
* @param connection
|
|
14
|
+
* @param query
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function subscribe(connection: KeepAliveConnection<KeepAliveNativeConnection>, query: SyncConnectionsQuery): void;
|
|
18
|
+
/**
|
|
19
|
+
* 停止广播连接列表
|
|
20
|
+
*/
|
|
21
|
+
export declare function stopBroadcastTimer(): void;
|
|
22
|
+
/**
|
|
23
|
+
* 开始广播连接列表
|
|
24
|
+
*/
|
|
25
|
+
export declare function startBroadcastTimer(): void;
|
|
26
|
+
/**
|
|
27
|
+
* 广播连接列表
|
|
28
|
+
*/
|
|
29
|
+
export declare function broadcast(): void;
|
|
5
30
|
/**
|
|
6
31
|
* 服务器发送连接列表
|
|
7
32
|
* @param connection
|
|
8
33
|
* @param query
|
|
9
34
|
* @param callback
|
|
10
35
|
*/
|
|
11
|
-
export declare function onSyncConnections(connection: KeepAliveConnection<
|
|
36
|
+
export declare function onSyncConnections(connection: KeepAliveConnection<KeepAliveNativeConnection>, query: SyncConnectionsQuery, callback: (returns: ReturnsBody<KeepAliveConnectionData[]>) => void): void;
|
|
12
37
|
/**
|
|
13
38
|
* 同步连接列表
|
|
14
39
|
* @param datas 连接参数列表
|
|
15
40
|
*/
|
|
16
|
-
export declare function syncConnections(
|
|
41
|
+
export declare function syncConnections(returns: ReturnsBody<KeepAliveConnectionData[]>): void;
|
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
import * as oox from '../index.js';
|
|
2
|
-
export interface SampleKeepAliveNativeConnection {
|
|
2
|
+
export interface SampleKeepAliveNativeConnection extends oox.KeepAliveNativeConnection {
|
|
3
3
|
connected: boolean;
|
|
4
4
|
connect?(): void;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
off(event: string | symbol, listener?: (...args: any[]) => void): any;
|
|
5
|
+
on(event: string | symbol, listener: (...args: any[]) => any): any;
|
|
6
|
+
once(event: string | symbol, listener: (...args: any[]) => any): any;
|
|
7
|
+
off(event?: string | symbol, listener?: (...args: any[]) => any): any;
|
|
9
8
|
emit(event: string | symbol, ...args: any[]): any;
|
|
10
9
|
removeAllListeners(event?: string | symbol): any;
|
|
11
10
|
}
|
|
12
11
|
export declare abstract class SampleKeepAliveConnectionAdapter<NativeConnection extends SampleKeepAliveNativeConnection> implements oox.KeepAliveConnectionAdapter<NativeConnection> {
|
|
13
|
-
name: string;
|
|
12
|
+
abstract name: string;
|
|
14
13
|
OOXEvent: {
|
|
15
14
|
READY: string;
|
|
16
15
|
ENABLED: string;
|
|
17
16
|
DISABLED: string;
|
|
18
|
-
|
|
17
|
+
REGISTRY_SYNC_CONNECTIONS: string;
|
|
18
|
+
REGISTRY_SUBSCRIBE: string;
|
|
19
|
+
REGISTRY_NOTIFY: string;
|
|
19
20
|
};
|
|
20
21
|
nativeEvent: {
|
|
21
22
|
CONNECT: string;
|
|
22
23
|
DISCONNECT: string;
|
|
23
24
|
ERROR: string;
|
|
24
25
|
};
|
|
25
|
-
abstract newConnection(
|
|
26
|
+
abstract newConnection(identify: string | URL | oox.KeepAliveConnectionData): oox.KeepAliveConnection<NativeConnection>;
|
|
27
|
+
/**
|
|
28
|
+
* 通知连接列表
|
|
29
|
+
*/
|
|
30
|
+
['registry:notify'](connection: oox.KeepAliveConnection<NativeConnection>, datas: oox.KeepAliveConnectionData[]): void;
|
|
31
|
+
/**
|
|
32
|
+
* 订阅连接列表
|
|
33
|
+
*/
|
|
34
|
+
['registry:subscribe'](connection: oox.KeepAliveConnection<NativeConnection>, query: oox.KeepAliveSyncConnectionsQuery): void;
|
|
26
35
|
bindConnectionEvents(connection: oox.KeepAliveConnection<NativeConnection>): void;
|
|
27
|
-
open(
|
|
36
|
+
open(identify: string | URL | oox.KeepAliveConnectionData): Promise<oox.KeepAliveConnection<NativeConnection>>;
|
|
28
37
|
close(connection: oox.KeepAliveConnection<NativeConnection>): Promise<void>;
|
|
29
38
|
/**
|
|
30
39
|
* 发送事件
|
|
@@ -36,11 +45,11 @@ export declare abstract class SampleKeepAliveConnectionAdapter<NativeConnection
|
|
|
36
45
|
/**
|
|
37
46
|
* RPC
|
|
38
47
|
*/
|
|
39
|
-
rpc(connection: oox.KeepAliveConnection<NativeConnection>, action: string, params: [], context?: oox.
|
|
48
|
+
rpc(connection: oox.KeepAliveConnection<NativeConnection>, action: string, params: any[], context?: oox.KeepAliveRPCContext): Promise<any>;
|
|
40
49
|
/**
|
|
41
50
|
* 绑定 call 事件
|
|
42
51
|
* @param connection
|
|
43
52
|
*/
|
|
44
53
|
bindCall(connection: oox.KeepAliveConnection<NativeConnection>): void;
|
|
45
|
-
call(action: string, params: any[], context: oox.Context, callback?: (returns: any) => void): Promise<oox.ReturnsBody
|
|
54
|
+
call(action: string, params: any[], context: oox.Context, callback?: (returns: any) => void): Promise<oox.ReturnsBody<any>>;
|
|
46
55
|
}
|
package/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ export function getIPAddress(version = 4) {
|
|
|
3
3
|
const interfaces = networkInterfaces();
|
|
4
4
|
const ip = [];
|
|
5
5
|
for (const name of Object.keys(interfaces))
|
|
6
|
-
for (const intf of interfaces[name])
|
|
6
|
+
for (const intf of interfaces[name] || [])
|
|
7
7
|
if (intf.mac !== '00:00:00:00:00:00')
|
|
8
8
|
if ((version !== 4 && version !== 6) || 'IPv' + version === intf.family)
|
|
9
9
|
ip.push(intf.address);
|