@eleven-am/pondsocket-nest 0.0.47 → 0.0.48
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/package.json +1 -1
- package/services/pondSocket.js +12 -4
package/package.json
CHANGED
package/services/pondSocket.js
CHANGED
|
@@ -15,6 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.PondSocketService = void 0;
|
|
16
16
|
const http_1 = require("http");
|
|
17
17
|
const pondsocket_1 = __importDefault(require("@eleven-am/pondsocket"));
|
|
18
|
+
// eslint-disable-next-line import/no-unresolved
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
18
20
|
const constants_1 = require("../constants");
|
|
19
21
|
const channel_1 = require("../managers/channel");
|
|
20
22
|
const channelInstance_1 = require("../managers/channelInstance");
|
|
@@ -31,6 +33,7 @@ class PondSocketService {
|
|
|
31
33
|
this.discovery = discovery;
|
|
32
34
|
this.adapterHost = adapterHost;
|
|
33
35
|
this.externalGuards = externalGuards;
|
|
36
|
+
this.logger = new common_1.Logger(PondSocketService.name);
|
|
34
37
|
const httpAdapter = this.adapterHost.httpAdapter;
|
|
35
38
|
httpAdapter.listen = (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
36
39
|
const socket = yield this.init(httpAdapter);
|
|
@@ -69,13 +72,14 @@ class PondSocketService {
|
|
|
69
72
|
response.accept();
|
|
70
73
|
}
|
|
71
74
|
}));
|
|
75
|
+
this.logger.log(`Mapped {${metadata}} endpoint`);
|
|
72
76
|
setEndpoint(endpoint);
|
|
73
77
|
const channels = [...new Set([...groupedInstance.channels.map((channel) => channel)])];
|
|
74
78
|
channels.forEach((channel) => {
|
|
75
|
-
this.manageChannel(channel, endpoint);
|
|
79
|
+
this.manageChannel(channel, endpoint, metadata);
|
|
76
80
|
});
|
|
77
81
|
}
|
|
78
|
-
manageChannel(channel, endpoint) {
|
|
82
|
+
manageChannel(channel, endpoint, endpointPath) {
|
|
79
83
|
const instance = channel.instance;
|
|
80
84
|
const constructor = instance.constructor;
|
|
81
85
|
const path = (0, channel_1.manageChannel)(constructor).get();
|
|
@@ -95,6 +99,7 @@ class PondSocketService {
|
|
|
95
99
|
response.accept();
|
|
96
100
|
}
|
|
97
101
|
}));
|
|
102
|
+
this.logger.log(`Mapped {${endpointPath}:${path}} channel`);
|
|
98
103
|
setChannel(channelInstance);
|
|
99
104
|
const { get: getEventHandlers } = (0, event_1.manageEvent)(instance);
|
|
100
105
|
const { get: getLeaveHandlers } = (0, leave_1.manageLeave)(instance);
|
|
@@ -102,12 +107,14 @@ class PondSocketService {
|
|
|
102
107
|
channelInstance.onEvent(handler.path, (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
103
108
|
yield handler.value(instance, this.moduleRef, request, response);
|
|
104
109
|
}));
|
|
110
|
+
this.logger.log(`Mapped {${endpointPath}:${path}} event {${handler.path}}`);
|
|
105
111
|
});
|
|
106
112
|
const [leaveHandler] = getLeaveHandlers();
|
|
107
113
|
if (leaveHandler) {
|
|
108
114
|
channelInstance.onLeave((event) => __awaiter(this, void 0, void 0, function* () {
|
|
109
115
|
yield leaveHandler.value(instance, this.moduleRef, event);
|
|
110
116
|
}));
|
|
117
|
+
this.logger.log(`Mapped {${endpointPath}:${path}} leave handler`);
|
|
111
118
|
}
|
|
112
119
|
}
|
|
113
120
|
getGroupedInstances() {
|
|
@@ -144,10 +151,11 @@ class PondSocketService {
|
|
|
144
151
|
}))).flat();
|
|
145
152
|
const baseEndpoint = endpoints.find((endpoint) => endpoint.discoveredClass.parentModule.name === 'AppModule');
|
|
146
153
|
if (channelsWithNoEndpoints.length > 0) {
|
|
147
|
-
if (baseEndpoint) {
|
|
154
|
+
if (baseEndpoint || endpoints.length === 1) {
|
|
155
|
+
const newEndpoint = baseEndpoint ? baseEndpoint.discoveredClass : endpoints[0].discoveredClass;
|
|
148
156
|
const channels = channelsWithNoEndpoints.map((instance) => instance.channels).flat();
|
|
149
157
|
groupedInstances.push({
|
|
150
|
-
endpoint:
|
|
158
|
+
endpoint: newEndpoint,
|
|
151
159
|
channels,
|
|
152
160
|
});
|
|
153
161
|
}
|