@eleven-am/pondsocket-nest 0.0.64 → 0.0.65
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/index.d.ts +13 -0
- package/modules/pondSocket.js +34 -2
- package/package.json +5 -5
- package/services/pondSocket.js +4 -4
package/index.d.ts
CHANGED
|
@@ -29,10 +29,21 @@ interface CanActivate {
|
|
|
29
29
|
canActivate(context: Context): boolean | Promise<boolean>;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
interface PubSubOptions {
|
|
33
|
+
redisUrl: string;
|
|
34
|
+
db: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
interface Metadata extends Omit<ModuleMetadata, 'controllers'> {
|
|
33
38
|
guards?: Constructor<CanActivate>[];
|
|
34
39
|
appModuleName?: string;
|
|
35
40
|
isGlobal?: boolean;
|
|
41
|
+
options?: PubSubOptions;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface AsyncMetadata extends Metadata {
|
|
45
|
+
useFactory: (...args: unknown[]) => Promise<PubSubOptions> | PubSubOptions;
|
|
46
|
+
inject: any[];
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
type NestFuncType<Event extends string, Payload extends PondMessage, Presence extends PondPresence, Assigns extends PondAssigns = PondAssigns> = {
|
|
@@ -302,5 +313,7 @@ declare function createParamDecorator<Input, ParamType> (callback: ParamDecorato
|
|
|
302
313
|
|
|
303
314
|
declare class PondSocketModule {
|
|
304
315
|
static forRoot({ guards, providers, imports, exports, isGlobal, appModuleName }: Metadata): DynamicModule;
|
|
316
|
+
|
|
317
|
+
static forRootAsync({ guards, providers, imports, exports, isGlobal, useFactory, inject }: AsyncMetadata): DynamicModule;
|
|
305
318
|
}
|
|
306
319
|
|
package/modules/pondSocket.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.PondSocketModule = void 0;
|
|
4
13
|
const nestjs_discovery_1 = require("@golevelup/nestjs-discovery");
|
|
@@ -7,11 +16,11 @@ const core_1 = require("@nestjs/core");
|
|
|
7
16
|
const guards_1 = require("../managers/guards");
|
|
8
17
|
const pondSocket_1 = require("../services/pondSocket");
|
|
9
18
|
class PondSocketModule {
|
|
10
|
-
static forRoot({ guards = [], providers = [], imports = [], exports = [], isGlobal = false, }) {
|
|
19
|
+
static forRoot({ guards = [], providers = [], imports = [], exports = [], isGlobal = false, options, }) {
|
|
11
20
|
const localGuards = (0, guards_1.getLocalGuards)();
|
|
12
21
|
const pondSocketProvider = {
|
|
13
22
|
provide: pondSocket_1.PondSocketService,
|
|
14
|
-
useFactory: (moduleRef, adapterHost, discovery) => new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, guards),
|
|
23
|
+
useFactory: (moduleRef, adapterHost, discovery) => new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, guards, options !== null && options !== void 0 ? options : {}),
|
|
15
24
|
inject: [core_1.ModuleRef, core_1.HttpAdapterHost, nestjs_discovery_1.DiscoveryService],
|
|
16
25
|
};
|
|
17
26
|
guards = [...new Set([...localGuards, ...guards])];
|
|
@@ -27,5 +36,28 @@ class PondSocketModule {
|
|
|
27
36
|
],
|
|
28
37
|
};
|
|
29
38
|
}
|
|
39
|
+
static forRootAsync({ guards = [], providers = [], imports = [], exports = [], isGlobal = false, useFactory, inject, }) {
|
|
40
|
+
const provider = {
|
|
41
|
+
provide: pondSocket_1.PondSocketService,
|
|
42
|
+
useFactory: (moduleRef, adapterHost, discovery, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const options = yield useFactory(...args);
|
|
44
|
+
const localGuards = (0, guards_1.getLocalGuards)();
|
|
45
|
+
guards = [...new Set([...localGuards, ...guards])];
|
|
46
|
+
return new pondSocket_1.PondSocketService(moduleRef, discovery, adapterHost, guards, options);
|
|
47
|
+
}),
|
|
48
|
+
inject: [core_1.ModuleRef, core_1.HttpAdapterHost, nestjs_discovery_1.DiscoveryService, ...(inject || [])],
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
exports,
|
|
52
|
+
global: isGlobal,
|
|
53
|
+
imports: [...imports, nestjs_discovery_1.DiscoveryModule],
|
|
54
|
+
module: PondSocketModule,
|
|
55
|
+
providers: [
|
|
56
|
+
provider,
|
|
57
|
+
...providers,
|
|
58
|
+
...guards,
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
30
62
|
}
|
|
31
63
|
exports.PondSocketModule = PondSocketModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket-nest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"pipeline": "npm run lint && npm run build && npm run push"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@eleven-am/pondsocket": "^0.1.
|
|
31
|
+
"@eleven-am/pondsocket": "^0.1.161",
|
|
32
32
|
"@golevelup/nestjs-discovery": "^4.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@nestjs/common": "^10.3.
|
|
36
|
-
"@nestjs/core": "^10.3.
|
|
35
|
+
"@nestjs/common": "^10.3.10",
|
|
36
|
+
"@nestjs/core": "^10.3.10",
|
|
37
37
|
"@types/jest": "^29.5.12",
|
|
38
38
|
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
39
39
|
"eslint-plugin-file-progress": "^1.3.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"ts-jest": "^29.1.5",
|
|
44
44
|
"ts-loader": "^9.5.1",
|
|
45
45
|
"ts-node": "^10.9.2",
|
|
46
|
-
"typescript": "^5.5.
|
|
46
|
+
"typescript": "^5.5.3"
|
|
47
47
|
},
|
|
48
48
|
"jest": {
|
|
49
49
|
"moduleFileExtensions": [
|
package/services/pondSocket.js
CHANGED
|
@@ -28,21 +28,21 @@ const guards_1 = require("../managers/guards");
|
|
|
28
28
|
const join_1 = require("../managers/join");
|
|
29
29
|
const leave_1 = require("../managers/leave");
|
|
30
30
|
class PondSocketService {
|
|
31
|
-
constructor(moduleRef, discovery, adapterHost, externalGuards) {
|
|
31
|
+
constructor(moduleRef, discovery, adapterHost, externalGuards, pubSubOptions) {
|
|
32
32
|
this.moduleRef = moduleRef;
|
|
33
33
|
this.discovery = discovery;
|
|
34
34
|
this.adapterHost = adapterHost;
|
|
35
35
|
this.externalGuards = externalGuards;
|
|
36
36
|
this.logger = new common_1.Logger(PondSocketService.name);
|
|
37
37
|
const httpAdapter = this.adapterHost.httpAdapter;
|
|
38
|
-
void this.init(httpAdapter);
|
|
38
|
+
void this.init(httpAdapter, pubSubOptions);
|
|
39
39
|
}
|
|
40
|
-
init(httpAdapter) {
|
|
40
|
+
init(httpAdapter, options) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
42
|
const groupedInstances = yield this.getGroupedInstances();
|
|
43
43
|
const app = httpAdapter.getInstance();
|
|
44
44
|
const server = (0, http_1.createServer)(app);
|
|
45
|
-
const socket = new pondsocket_1.default(server);
|
|
45
|
+
const socket = new pondsocket_1.default(Object.assign(Object.assign({}, options), { server }));
|
|
46
46
|
groupedInstances.forEach((groupedInstance) => {
|
|
47
47
|
this.manageEndpoint(socket, groupedInstance);
|
|
48
48
|
});
|