forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket-module.ts
More file actions
36 lines (29 loc) · 1.3 KB
/
Copy pathsocket-module.ts
File metadata and controls
36 lines (29 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import "reflect-metadata";
import { NestContainer, InstanceWrapper } from "../core/injector/container";
import { Gateway } from "./interfaces/gateway.interface";
import { SocketsContainer } from "./container";
import { SubjectsController } from "./subjects-controller";
import { Injectable } from "../common/interfaces/injectable.interface";
import { SocketServerProvider } from "./socket-server-provider";
export class SocketModule {
private static socketsContainer = new SocketsContainer();
private static subjectsController;
static setup(container: NestContainer) {
this.subjectsController = new SubjectsController(
new SocketServerProvider(this.socketsContainer));
const modules = container.getModules();
modules.forEach(({ components }) => this.hookGatewaysIntoServers(components));
}
static hookGatewaysIntoServers(components: Map<Injectable, InstanceWrapper<Injectable>>) {
components.forEach(({ instance }, componentType) => {
const metadataKeys = Reflect.getMetadataKeys(componentType);
if (metadataKeys.indexOf("__isGateway") < 0) {
return;
}
this.subjectsController.hookGatewayIntoServer(
<Gateway>instance,
componentType
);
});
}
}