@eleven-am/pondsocket 0.1.91 → 0.1.93
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/nest.d.ts +4 -21
- package/nest.js +345 -369
- package/package.json +1 -1
- package/types.d.ts +44 -7
package/nest.d.ts
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
export {
|
|
2
2
|
OnJoinRequest,
|
|
3
3
|
ChannelInstance,
|
|
4
4
|
DChannel as Channel,
|
|
5
|
-
Channels,
|
|
6
5
|
OnConnectionRequest,
|
|
7
6
|
DEndpoint as Endpoint,
|
|
8
7
|
OnEvent, PondSocketModule,
|
|
9
8
|
GetEventParams, GetEventQuery,
|
|
10
9
|
GetEventRequest, GetEventResponse,
|
|
11
|
-
GetJoinParams, GetJoinRequest,
|
|
12
10
|
GetJoinResponse, GetConnectionParams,
|
|
13
|
-
GetConnectionRequest, GetConnectionResponse,
|
|
14
11
|
GetConnectionQuery, GetConnectionHeaders,
|
|
15
|
-
|
|
12
|
+
GetConnectionRequest, GetConnectionResponse,
|
|
16
13
|
GetUserData, GetUserPresences, GetInternalChannel,
|
|
14
|
+
GetConnectionRequestId, GetEventPayload, PondGuards,
|
|
15
|
+
GetJoinParams, GetJoinRequest, createParamDecorator,
|
|
17
16
|
} from './types';
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
OnJoinRequest,
|
|
21
|
-
ChannelInstance,
|
|
22
|
-
OnConnectionRequest,
|
|
23
|
-
Endpoint, PondSocketModule,
|
|
24
|
-
OnEvent, Channel, Channels,
|
|
25
|
-
GetEventQuery, GetJoinParams,
|
|
26
|
-
GetEventParams, GetJoinResponse,
|
|
27
|
-
GetEventRequest, GetJoinRequest,
|
|
28
|
-
GetEventResponse, GetConnectionQuery,
|
|
29
|
-
GetConnectionRequestId, GetEventPayload,
|
|
30
|
-
GetConnectionParams, GetConnectionRequest,
|
|
31
|
-
GetConnectionResponse, GetConnectionHeaders,
|
|
32
|
-
GetUserData, GetUserPresences, GetInternalChannel,
|
|
33
|
-
}
|
package/nest.js
CHANGED
|
@@ -20,29 +20,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.PondSocketModule = exports.Endpoint = exports.Channel = exports.EndpointInstance = exports.ChannelInstance = exports.OnConnectionRequest = exports.
|
|
23
|
+
exports.PondSocketModule = exports.Endpoint = exports.Channel = exports.EndpointInstance = exports.ChannelInstance = exports.OnEvent = exports.OnLeaveEvent = exports.OnJoinRequest = exports.OnConnectionRequest = exports.GetLeaveEvent = exports.GetEventRequest = exports.GetEventResponse = exports.GetEventQuery = exports.GetEventParams = exports.GetEventPayload = exports.GetJoinParams = exports.GetJoinResponse = exports.GetJoinRequest = exports.GetConnectionQuery = exports.GetConnectionHeaders = exports.GetConnectionParams = exports.GetConnectionRequestId = exports.GetConnectionResponse = exports.GetConnectionRequest = exports.GetUserPresences = exports.GetInternalChannel = exports.GetUserData = exports.createParamDecorator = exports.PondGuards = void 0;
|
|
24
24
|
const http_1 = require("http");
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
|
+
// eslint-disable-next-line import/no-unresolved
|
|
26
27
|
const core_1 = require("@nestjs/core");
|
|
27
28
|
require("reflect-metadata");
|
|
28
29
|
const pondSocket_1 = require("./server/pondSocket");
|
|
29
|
-
const joinRequestKey = Symbol('joinRequestKey');
|
|
30
|
-
const joinResponseKey = Symbol('joinResponseKey');
|
|
31
|
-
const joinParamsKey = Symbol('joinParamsKey');
|
|
32
|
-
const userDataKey = Symbol('userDataKey');
|
|
33
|
-
const internalChannelKey = Symbol('internalChannelKey');
|
|
34
|
-
const userPresenceKey = Symbol('userPresenceKey');
|
|
35
|
-
const eventRequestKey = Symbol('eventRequestKey');
|
|
36
|
-
const eventPayloadKey = Symbol('eventPayloadKey');
|
|
37
|
-
const eventParamsKey = Symbol('eventParamsKey');
|
|
38
|
-
const eventQueryKey = Symbol('eventQueryKey');
|
|
39
|
-
const eventResponseKey = Symbol('eventResponseKey');
|
|
40
|
-
const connectionRequestKey = Symbol('connectionRequestKey');
|
|
41
|
-
const connectionResponseKey = Symbol('connectionResponseKey');
|
|
42
|
-
const connectionRequestIdKey = Symbol('connectionRequestIdKey');
|
|
43
|
-
const connectionParamsKey = Symbol('connectionParamsKey');
|
|
44
|
-
const connectionQueryKey = Symbol('connectionQueryKey');
|
|
45
|
-
const connectionHeadersKey = Symbol('connectionHeadersKey');
|
|
46
30
|
const onJoinHandlerKey = Symbol('onJoinHandlerKey');
|
|
47
31
|
const onEventHandlerKey = Symbol('onEventHandlerKey');
|
|
48
32
|
const onConnectionHandlerKey = Symbol('onConnectionHandlerKey');
|
|
@@ -51,6 +35,8 @@ const endpointInstanceKey = Symbol('endpointInstanceKey');
|
|
|
51
35
|
const channelClassKey = Symbol('channel');
|
|
52
36
|
const endpointClassKey = Symbol('endpoint');
|
|
53
37
|
const channelsClassKey = Symbol('channels');
|
|
38
|
+
const parametersKey = Symbol('generalParametersKey');
|
|
39
|
+
const pondGuardsKey = Symbol('pondGuardsKey');
|
|
54
40
|
function isNotEmpty(value) {
|
|
55
41
|
return value !== null &&
|
|
56
42
|
value !== undefined &&
|
|
@@ -65,22 +51,6 @@ function getClassMetadata(key, target) {
|
|
|
65
51
|
var _a;
|
|
66
52
|
return (_a = Reflect.getMetadata(key, target)) !== null && _a !== void 0 ? _a : null;
|
|
67
53
|
}
|
|
68
|
-
function createParamDecorator(key, error) {
|
|
69
|
-
return (target, propertyKey, parameterIndex) => {
|
|
70
|
-
const existingParams = Reflect.getMetadata(key, target, propertyKey);
|
|
71
|
-
if (existingParams) {
|
|
72
|
-
throw new Error(error);
|
|
73
|
-
}
|
|
74
|
-
Reflect.defineMetadata(key, parameterIndex, target, propertyKey);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function resolveParamDecorator(key, target, propertyKey) {
|
|
78
|
-
const index = Reflect.getMetadata(key, target, propertyKey);
|
|
79
|
-
if (typeof index !== 'number') {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return index;
|
|
83
|
-
}
|
|
84
54
|
function manageClassData(key, target) {
|
|
85
55
|
return {
|
|
86
56
|
get() {
|
|
@@ -91,6 +61,16 @@ function manageClassData(key, target) {
|
|
|
91
61
|
},
|
|
92
62
|
};
|
|
93
63
|
}
|
|
64
|
+
function manageMethodData(key, target, propertyKey) {
|
|
65
|
+
return {
|
|
66
|
+
get() {
|
|
67
|
+
return Reflect.getMetadata(key, target, propertyKey);
|
|
68
|
+
},
|
|
69
|
+
set(value) {
|
|
70
|
+
Reflect.defineMetadata(key, value, target, propertyKey);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
94
74
|
function manageHandlers(key, target) {
|
|
95
75
|
const { get, set } = manageClassData(key, target);
|
|
96
76
|
return {
|
|
@@ -109,6 +89,25 @@ function manageHandlers(key, target) {
|
|
|
109
89
|
},
|
|
110
90
|
};
|
|
111
91
|
}
|
|
92
|
+
function manageParameters(target, propertyKey) {
|
|
93
|
+
function getter() {
|
|
94
|
+
var _a;
|
|
95
|
+
return (_a = Reflect.getMetadata(parametersKey, target, propertyKey)) !== null && _a !== void 0 ? _a : [];
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
get: getter,
|
|
99
|
+
set(index, callback) {
|
|
100
|
+
const handlers = getter();
|
|
101
|
+
Reflect.defineMetadata(parametersKey, [
|
|
102
|
+
...handlers,
|
|
103
|
+
{
|
|
104
|
+
index,
|
|
105
|
+
callback,
|
|
106
|
+
},
|
|
107
|
+
], target, propertyKey);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
112
111
|
function managePropertyData(key, target) {
|
|
113
112
|
function build(propertyKey, callback) {
|
|
114
113
|
Object.defineProperty(target, propertyKey, {
|
|
@@ -134,15 +133,41 @@ function managePropertyData(key, target) {
|
|
|
134
133
|
set,
|
|
135
134
|
};
|
|
136
135
|
}
|
|
136
|
+
function PondGuards(...guards) {
|
|
137
|
+
return (target, propertyKey) => {
|
|
138
|
+
if (propertyKey) {
|
|
139
|
+
const { get, set } = manageMethodData(pondGuardsKey, target, propertyKey);
|
|
140
|
+
set([...get(), ...guards]);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const { get, set } = manageClassData(pondGuardsKey, target);
|
|
144
|
+
set([...get(), ...guards]);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
exports.PondGuards = PondGuards;
|
|
149
|
+
function resolveGuards(moduleRef, request, target, propertyKey) {
|
|
150
|
+
var _a, _b;
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const { get: getClassGuards } = manageClassData(pondGuardsKey, target);
|
|
153
|
+
const { get: getMethodGuards } = manageMethodData(pondGuardsKey, target, propertyKey.toString());
|
|
154
|
+
const classGuards = (_a = getClassGuards()) !== null && _a !== void 0 ? _a : [];
|
|
155
|
+
const methodGuards = (_b = getMethodGuards()) !== null && _b !== void 0 ? _b : [];
|
|
156
|
+
const instances = [...classGuards, ...methodGuards].map((guard) => moduleRef.get(guard, { strict: false }));
|
|
157
|
+
const promises = instances.map((instance) => instance.canActivate(request));
|
|
158
|
+
const results = yield Promise.all(promises);
|
|
159
|
+
return results.every((result) => result);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function manageConnectionHandlers(target) {
|
|
163
|
+
return manageHandlers(onConnectionHandlerKey, target);
|
|
164
|
+
}
|
|
137
165
|
function manageJoinHandlers(target) {
|
|
138
166
|
return manageHandlers(onJoinHandlerKey, target);
|
|
139
167
|
}
|
|
140
168
|
function manageEventHandlers(target) {
|
|
141
169
|
return manageHandlers(onEventHandlerKey, target);
|
|
142
170
|
}
|
|
143
|
-
function manageConnectionHandlers(target) {
|
|
144
|
-
return manageHandlers(onConnectionHandlerKey, target);
|
|
145
|
-
}
|
|
146
171
|
function manageOnLeaveHandlers(target) {
|
|
147
172
|
return manageHandlers(onConnectionHandlerKey, target);
|
|
148
173
|
}
|
|
@@ -152,326 +177,293 @@ function manageChannelInstance(target) {
|
|
|
152
177
|
function manageEndpointInstance(target) {
|
|
153
178
|
return managePropertyData(endpointInstanceKey, target);
|
|
154
179
|
}
|
|
155
|
-
function
|
|
156
|
-
return
|
|
180
|
+
function createParamDecorator(callback) {
|
|
181
|
+
return (data) => (target, propertyKey, index) => {
|
|
182
|
+
const { set } = manageParameters(target, propertyKey);
|
|
183
|
+
set(index, (request, response) => callback(data, request, response));
|
|
184
|
+
};
|
|
157
185
|
}
|
|
158
|
-
exports.
|
|
159
|
-
function
|
|
160
|
-
|
|
186
|
+
exports.createParamDecorator = createParamDecorator;
|
|
187
|
+
function resolveParameters(request, response, target, propertyKey) {
|
|
188
|
+
const { get } = manageParameters(target, propertyKey);
|
|
189
|
+
const values = get()
|
|
190
|
+
.map(({ callback, index }) => ({
|
|
191
|
+
value: callback(request, response),
|
|
192
|
+
index,
|
|
193
|
+
}));
|
|
194
|
+
return values
|
|
195
|
+
.sort((a, b) => a.index - b.index)
|
|
196
|
+
.map(({ value }) => value);
|
|
161
197
|
}
|
|
162
|
-
exports.GetJoinResponse = GetJoinResponse;
|
|
163
|
-
function GetJoinParams() {
|
|
164
|
-
return createParamDecorator(joinParamsKey, 'JoinParams decorator already applied');
|
|
165
|
-
}
|
|
166
|
-
exports.GetJoinParams = GetJoinParams;
|
|
167
198
|
function GetUserData() {
|
|
168
|
-
return createParamDecorator(
|
|
199
|
+
return createParamDecorator((_, request) => {
|
|
200
|
+
const { joinRequest, eventRequest } = request;
|
|
201
|
+
if (joinRequest) {
|
|
202
|
+
return joinRequest.user;
|
|
203
|
+
}
|
|
204
|
+
else if (eventRequest) {
|
|
205
|
+
return eventRequest.user;
|
|
206
|
+
}
|
|
207
|
+
throw new Error('Invalid decorator usage: GetUserData');
|
|
208
|
+
})(null);
|
|
169
209
|
}
|
|
170
210
|
exports.GetUserData = GetUserData;
|
|
171
211
|
function GetInternalChannel() {
|
|
172
|
-
return createParamDecorator(
|
|
212
|
+
return createParamDecorator((_, request) => {
|
|
213
|
+
const { joinRequest, eventRequest } = request;
|
|
214
|
+
if (joinRequest) {
|
|
215
|
+
return joinRequest.channel;
|
|
216
|
+
}
|
|
217
|
+
else if (eventRequest) {
|
|
218
|
+
return eventRequest.channel;
|
|
219
|
+
}
|
|
220
|
+
throw new Error('Invalid decorator usage: GetInternalChannel');
|
|
221
|
+
})(null);
|
|
173
222
|
}
|
|
174
223
|
exports.GetInternalChannel = GetInternalChannel;
|
|
175
224
|
function GetUserPresences() {
|
|
176
|
-
return createParamDecorator(
|
|
225
|
+
return createParamDecorator((_, request) => {
|
|
226
|
+
const { joinRequest, eventRequest } = request;
|
|
227
|
+
if (joinRequest) {
|
|
228
|
+
return joinRequest.presence;
|
|
229
|
+
}
|
|
230
|
+
else if (eventRequest) {
|
|
231
|
+
return eventRequest.presence;
|
|
232
|
+
}
|
|
233
|
+
throw new Error('Invalid decorator usage: GetUserPresences');
|
|
234
|
+
})(null);
|
|
177
235
|
}
|
|
178
236
|
exports.GetUserPresences = GetUserPresences;
|
|
179
|
-
function GetEventPayload() {
|
|
180
|
-
return createParamDecorator(eventPayloadKey, 'EventPayload decorator already applied');
|
|
181
|
-
}
|
|
182
|
-
exports.GetEventPayload = GetEventPayload;
|
|
183
|
-
function GetEventParams() {
|
|
184
|
-
return createParamDecorator(eventParamsKey, 'EventParams decorator already applied');
|
|
185
|
-
}
|
|
186
|
-
exports.GetEventParams = GetEventParams;
|
|
187
|
-
function GetEventQuery() {
|
|
188
|
-
return createParamDecorator(eventQueryKey, 'EventQuery decorator already applied');
|
|
189
|
-
}
|
|
190
|
-
exports.GetEventQuery = GetEventQuery;
|
|
191
|
-
function GetEventResponse() {
|
|
192
|
-
return createParamDecorator(eventResponseKey, 'EventResponse decorator already applied');
|
|
193
|
-
}
|
|
194
|
-
exports.GetEventResponse = GetEventResponse;
|
|
195
|
-
function GetEventRequest() {
|
|
196
|
-
return createParamDecorator(eventRequestKey, 'EventRequest decorator already applied');
|
|
197
|
-
}
|
|
198
|
-
exports.GetEventRequest = GetEventRequest;
|
|
199
237
|
function GetConnectionRequest() {
|
|
200
|
-
return createParamDecorator(
|
|
238
|
+
return createParamDecorator((_, request) => {
|
|
239
|
+
const { connection } = request;
|
|
240
|
+
if (connection) {
|
|
241
|
+
return connection;
|
|
242
|
+
}
|
|
243
|
+
throw new Error('Invalid decorator usage: GetConnectionRequest');
|
|
244
|
+
})(null);
|
|
201
245
|
}
|
|
202
246
|
exports.GetConnectionRequest = GetConnectionRequest;
|
|
203
247
|
function GetConnectionResponse() {
|
|
204
|
-
return createParamDecorator(
|
|
248
|
+
return createParamDecorator((_, __, response) => {
|
|
249
|
+
const { connection } = response;
|
|
250
|
+
if (connection) {
|
|
251
|
+
return connection;
|
|
252
|
+
}
|
|
253
|
+
throw new Error('Invalid decorator usage: GetConnectionResponse');
|
|
254
|
+
})(null);
|
|
205
255
|
}
|
|
206
256
|
exports.GetConnectionResponse = GetConnectionResponse;
|
|
207
257
|
function GetConnectionRequestId() {
|
|
208
|
-
return createParamDecorator(
|
|
258
|
+
return createParamDecorator((_, request) => {
|
|
259
|
+
const { connection } = request;
|
|
260
|
+
if (connection) {
|
|
261
|
+
return connection.id;
|
|
262
|
+
}
|
|
263
|
+
throw new Error('Invalid decorator usage: GetConnectionRequestId');
|
|
264
|
+
})(null);
|
|
209
265
|
}
|
|
210
266
|
exports.GetConnectionRequestId = GetConnectionRequestId;
|
|
211
267
|
function GetConnectionParams() {
|
|
212
|
-
return createParamDecorator(
|
|
268
|
+
return createParamDecorator((_, request) => {
|
|
269
|
+
const { connection } = request;
|
|
270
|
+
if (connection) {
|
|
271
|
+
return connection.params;
|
|
272
|
+
}
|
|
273
|
+
throw new Error('Invalid decorator usage: GetConnectionParams');
|
|
274
|
+
})(null);
|
|
213
275
|
}
|
|
214
276
|
exports.GetConnectionParams = GetConnectionParams;
|
|
215
277
|
function GetConnectionHeaders() {
|
|
216
|
-
return createParamDecorator(
|
|
278
|
+
return createParamDecorator((_, request) => {
|
|
279
|
+
const { connection } = request;
|
|
280
|
+
if (connection) {
|
|
281
|
+
return connection.headers;
|
|
282
|
+
}
|
|
283
|
+
throw new Error('Invalid decorator usage: GetConnectionHeaders');
|
|
284
|
+
})(null);
|
|
217
285
|
}
|
|
218
286
|
exports.GetConnectionHeaders = GetConnectionHeaders;
|
|
219
287
|
function GetConnectionQuery() {
|
|
220
|
-
return createParamDecorator(
|
|
288
|
+
return createParamDecorator((_, request) => {
|
|
289
|
+
const { connection } = request;
|
|
290
|
+
if (connection) {
|
|
291
|
+
return connection.query;
|
|
292
|
+
}
|
|
293
|
+
throw new Error('Invalid decorator usage: GetConnectionQuery');
|
|
294
|
+
})(null);
|
|
221
295
|
}
|
|
222
296
|
exports.GetConnectionQuery = GetConnectionQuery;
|
|
223
|
-
function
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
case joinResponseKey:
|
|
229
|
-
return 'GetJoinResponse';
|
|
230
|
-
case joinParamsKey:
|
|
231
|
-
return 'GetJoinParams';
|
|
232
|
-
case userDataKey:
|
|
233
|
-
return 'GetUserData';
|
|
234
|
-
case internalChannelKey:
|
|
235
|
-
return 'GetInternalChannel';
|
|
236
|
-
case userPresenceKey:
|
|
237
|
-
return 'GetUserPresences';
|
|
238
|
-
case eventPayloadKey:
|
|
239
|
-
return 'GetEventPayload';
|
|
240
|
-
case eventParamsKey:
|
|
241
|
-
return 'GetEventParams';
|
|
242
|
-
case eventQueryKey:
|
|
243
|
-
return 'GetEventQuery';
|
|
244
|
-
case eventResponseKey:
|
|
245
|
-
return 'GetEventResponse';
|
|
246
|
-
case eventRequestKey:
|
|
247
|
-
return 'GetEventRequest';
|
|
248
|
-
case connectionRequestKey:
|
|
249
|
-
return 'GetConnectionRequest';
|
|
250
|
-
case connectionResponseKey:
|
|
251
|
-
return 'GetConnectionResponse';
|
|
252
|
-
case connectionRequestIdKey:
|
|
253
|
-
return 'GetConnectionRequestId';
|
|
254
|
-
case connectionParamsKey:
|
|
255
|
-
return 'GetConnectionParams';
|
|
256
|
-
case connectionQueryKey:
|
|
257
|
-
return 'GetConnectionQuery';
|
|
258
|
-
case connectionHeadersKey:
|
|
259
|
-
return 'GetConnectionHeaders';
|
|
260
|
-
default:
|
|
261
|
-
throw new Error('Invalid parameter decorator');
|
|
297
|
+
function GetJoinRequest() {
|
|
298
|
+
return createParamDecorator((_, request) => {
|
|
299
|
+
const { joinRequest } = request;
|
|
300
|
+
if (joinRequest) {
|
|
301
|
+
return joinRequest;
|
|
262
302
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
.map((key) => ({
|
|
266
|
-
key,
|
|
267
|
-
name: symbolToString(key),
|
|
268
|
-
}))
|
|
269
|
-
.filter(({ key }) => resolveParamDecorator(key, target, propertyKey) !== null);
|
|
270
|
-
if (rejected.length) {
|
|
271
|
-
throw new Error(`Invalid parameter decorators: ${rejected.map(({ name }) => name).join(', ')}`);
|
|
272
|
-
}
|
|
303
|
+
throw new Error('Invalid decorator usage: GetJoinRequest');
|
|
304
|
+
})(null);
|
|
273
305
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const eventQueryIndex = resolveParamDecorator(eventQueryKey, target, propertyKey);
|
|
281
|
-
const JoinResponseIndex = resolveParamDecorator(joinResponseKey, target, propertyKey);
|
|
282
|
-
const array = [
|
|
283
|
-
joinRequestIndex,
|
|
284
|
-
joinParamsIndex,
|
|
285
|
-
userDataIndex,
|
|
286
|
-
internalChannelIndex,
|
|
287
|
-
eventParamsIndex,
|
|
288
|
-
eventQueryIndex,
|
|
289
|
-
JoinResponseIndex,
|
|
290
|
-
].filter((index) => typeof index === 'number');
|
|
291
|
-
manageRejectedKeys([
|
|
292
|
-
eventPayloadKey,
|
|
293
|
-
eventRequestKey,
|
|
294
|
-
eventResponseKey,
|
|
295
|
-
userPresenceKey,
|
|
296
|
-
connectionRequestKey,
|
|
297
|
-
connectionResponseKey,
|
|
298
|
-
connectionRequestIdKey,
|
|
299
|
-
connectionParamsKey,
|
|
300
|
-
connectionQueryKey,
|
|
301
|
-
], target, propertyKey);
|
|
302
|
-
return array
|
|
303
|
-
.sort((a, b) => a - b)
|
|
304
|
-
.map((index) => {
|
|
305
|
-
switch (index) {
|
|
306
|
-
case joinRequestIndex:
|
|
307
|
-
return request;
|
|
308
|
-
case joinParamsIndex:
|
|
309
|
-
return request.joinParams;
|
|
310
|
-
case userDataIndex:
|
|
311
|
-
return request.user;
|
|
312
|
-
case internalChannelIndex:
|
|
313
|
-
return request.channel;
|
|
314
|
-
case eventParamsIndex:
|
|
315
|
-
return request.event.params;
|
|
316
|
-
case eventQueryIndex:
|
|
317
|
-
return request.event.query;
|
|
318
|
-
case JoinResponseIndex:
|
|
319
|
-
return response;
|
|
320
|
-
default:
|
|
321
|
-
throw new Error('Invalid parameter decorator');
|
|
306
|
+
exports.GetJoinRequest = GetJoinRequest;
|
|
307
|
+
function GetJoinResponse() {
|
|
308
|
+
return createParamDecorator((_, __, response) => {
|
|
309
|
+
const { joinResponse } = response;
|
|
310
|
+
if (joinResponse) {
|
|
311
|
+
return joinResponse;
|
|
322
312
|
}
|
|
323
|
-
|
|
313
|
+
throw new Error('Invalid decorator usage: GetJoinResponse');
|
|
314
|
+
})(null);
|
|
324
315
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const eventPayloadIndex = resolveParamDecorator(eventPayloadKey, target, propertyKey);
|
|
332
|
-
const eventResponseIndex = resolveParamDecorator(eventResponseKey, target, propertyKey);
|
|
333
|
-
const eventRequestIndex = resolveParamDecorator(eventRequestKey, target, propertyKey);
|
|
334
|
-
const array = [
|
|
335
|
-
userDataIndex,
|
|
336
|
-
internalChannelIndex,
|
|
337
|
-
eventParamsIndex,
|
|
338
|
-
eventQueryIndex,
|
|
339
|
-
eventPayloadIndex,
|
|
340
|
-
eventResponseIndex,
|
|
341
|
-
eventRequestIndex,
|
|
342
|
-
userPresenceIndex,
|
|
343
|
-
].filter((index) => typeof index === 'number');
|
|
344
|
-
manageRejectedKeys([
|
|
345
|
-
joinRequestKey,
|
|
346
|
-
joinResponseKey,
|
|
347
|
-
joinParamsKey,
|
|
348
|
-
connectionRequestKey,
|
|
349
|
-
connectionResponseKey,
|
|
350
|
-
connectionRequestIdKey,
|
|
351
|
-
connectionParamsKey,
|
|
352
|
-
connectionQueryKey,
|
|
353
|
-
], target, propertyKey);
|
|
354
|
-
return array
|
|
355
|
-
.sort((a, b) => a - b)
|
|
356
|
-
.map((index) => {
|
|
357
|
-
switch (index) {
|
|
358
|
-
case userDataIndex:
|
|
359
|
-
return request.user;
|
|
360
|
-
case internalChannelIndex:
|
|
361
|
-
return request.channel;
|
|
362
|
-
case eventParamsIndex:
|
|
363
|
-
return request.event.params;
|
|
364
|
-
case eventQueryIndex:
|
|
365
|
-
return request.event.query;
|
|
366
|
-
case eventPayloadIndex:
|
|
367
|
-
return request.event.payload;
|
|
368
|
-
case eventResponseIndex:
|
|
369
|
-
return response;
|
|
370
|
-
case eventRequestIndex:
|
|
371
|
-
return request;
|
|
372
|
-
case userPresenceIndex:
|
|
373
|
-
return request.presence;
|
|
374
|
-
default:
|
|
375
|
-
throw new Error('Invalid parameter decorator');
|
|
316
|
+
exports.GetJoinResponse = GetJoinResponse;
|
|
317
|
+
function GetJoinParams() {
|
|
318
|
+
return createParamDecorator((_, request) => {
|
|
319
|
+
const { joinRequest } = request;
|
|
320
|
+
if (joinRequest) {
|
|
321
|
+
return joinRequest.joinParams;
|
|
376
322
|
}
|
|
377
|
-
|
|
323
|
+
throw new Error('Invalid decorator usage: GetJoinParams');
|
|
324
|
+
})(null);
|
|
378
325
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
connectionRequestKey,
|
|
386
|
-
connectionResponseKey,
|
|
387
|
-
connectionRequestIdKey,
|
|
388
|
-
connectionParamsKey,
|
|
389
|
-
connectionQueryKey,
|
|
390
|
-
eventParamsKey,
|
|
391
|
-
eventQueryKey,
|
|
392
|
-
eventPayloadKey,
|
|
393
|
-
eventResponseKey,
|
|
394
|
-
eventRequestKey,
|
|
395
|
-
userPresenceKey,
|
|
396
|
-
internalChannelKey,
|
|
397
|
-
], target, propertyKey);
|
|
398
|
-
if (userDataIndex === null) {
|
|
399
|
-
return [];
|
|
400
|
-
}
|
|
401
|
-
return [event.assigns];
|
|
402
|
-
}
|
|
403
|
-
function resolveConnectionParameters(request, response, target, propertyKey) {
|
|
404
|
-
const connectionRequestIndex = resolveParamDecorator(connectionRequestKey, target, propertyKey);
|
|
405
|
-
const connectionResponseIndex = resolveParamDecorator(connectionResponseKey, target, propertyKey);
|
|
406
|
-
const connectionRequestIdIndex = resolveParamDecorator(connectionRequestIdKey, target, propertyKey);
|
|
407
|
-
const connectionParamsIndex = resolveParamDecorator(connectionParamsKey, target, propertyKey);
|
|
408
|
-
const connectionQueryIndex = resolveParamDecorator(connectionQueryKey, target, propertyKey);
|
|
409
|
-
const connectionHeadersIndex = resolveParamDecorator(connectionHeadersKey, target, propertyKey);
|
|
410
|
-
const array = [
|
|
411
|
-
connectionRequestIndex,
|
|
412
|
-
connectionResponseIndex,
|
|
413
|
-
connectionRequestIdIndex,
|
|
414
|
-
connectionParamsIndex,
|
|
415
|
-
connectionQueryIndex,
|
|
416
|
-
connectionHeadersIndex,
|
|
417
|
-
].filter((index) => typeof index === 'number');
|
|
418
|
-
manageRejectedKeys([
|
|
419
|
-
joinRequestKey,
|
|
420
|
-
joinResponseKey,
|
|
421
|
-
joinParamsKey,
|
|
422
|
-
userDataKey,
|
|
423
|
-
internalChannelKey,
|
|
424
|
-
eventParamsKey,
|
|
425
|
-
eventQueryKey,
|
|
426
|
-
eventPayloadKey,
|
|
427
|
-
eventResponseKey,
|
|
428
|
-
userPresenceKey,
|
|
429
|
-
eventRequestKey,
|
|
430
|
-
], target, propertyKey);
|
|
431
|
-
return array
|
|
432
|
-
.sort((a, b) => a - b)
|
|
433
|
-
.map((index) => {
|
|
434
|
-
switch (index) {
|
|
435
|
-
case connectionRequestIndex:
|
|
436
|
-
return request;
|
|
437
|
-
case connectionResponseIndex:
|
|
438
|
-
return response;
|
|
439
|
-
case connectionRequestIdIndex:
|
|
440
|
-
return request.id;
|
|
441
|
-
case connectionParamsIndex:
|
|
442
|
-
return request.params;
|
|
443
|
-
case connectionQueryIndex:
|
|
444
|
-
return request.query;
|
|
445
|
-
case connectionHeadersIndex:
|
|
446
|
-
return request.headers;
|
|
447
|
-
default:
|
|
448
|
-
throw new Error('Invalid parameter decorator');
|
|
326
|
+
exports.GetJoinParams = GetJoinParams;
|
|
327
|
+
function GetEventPayload() {
|
|
328
|
+
return createParamDecorator((_, request) => {
|
|
329
|
+
const { eventRequest } = request;
|
|
330
|
+
if (eventRequest) {
|
|
331
|
+
return eventRequest.event.payload;
|
|
449
332
|
}
|
|
450
|
-
|
|
333
|
+
throw new Error('Invalid decorator usage: GetEventPayload');
|
|
334
|
+
})(null);
|
|
335
|
+
}
|
|
336
|
+
exports.GetEventPayload = GetEventPayload;
|
|
337
|
+
function GetEventParams() {
|
|
338
|
+
return createParamDecorator((_, request) => {
|
|
339
|
+
const { eventRequest } = request;
|
|
340
|
+
if (eventRequest) {
|
|
341
|
+
return eventRequest.event.params;
|
|
342
|
+
}
|
|
343
|
+
throw new Error('Invalid decorator usage: GetEventParams');
|
|
344
|
+
})(null);
|
|
345
|
+
}
|
|
346
|
+
exports.GetEventParams = GetEventParams;
|
|
347
|
+
function GetEventQuery() {
|
|
348
|
+
return createParamDecorator((_, request) => {
|
|
349
|
+
const { eventRequest } = request;
|
|
350
|
+
if (eventRequest) {
|
|
351
|
+
return eventRequest.event.query;
|
|
352
|
+
}
|
|
353
|
+
throw new Error('Invalid decorator usage: GetEventQuery');
|
|
354
|
+
})(null);
|
|
355
|
+
}
|
|
356
|
+
exports.GetEventQuery = GetEventQuery;
|
|
357
|
+
function GetEventResponse() {
|
|
358
|
+
return createParamDecorator((_, __, response) => {
|
|
359
|
+
const { eventResponse } = response;
|
|
360
|
+
if (eventResponse) {
|
|
361
|
+
return eventResponse;
|
|
362
|
+
}
|
|
363
|
+
throw new Error('Invalid decorator usage: GetEventResponse');
|
|
364
|
+
})(null);
|
|
365
|
+
}
|
|
366
|
+
exports.GetEventResponse = GetEventResponse;
|
|
367
|
+
function GetEventRequest() {
|
|
368
|
+
return createParamDecorator((_, request) => {
|
|
369
|
+
const { eventRequest } = request;
|
|
370
|
+
if (eventRequest) {
|
|
371
|
+
return eventRequest;
|
|
372
|
+
}
|
|
373
|
+
throw new Error('Invalid decorator usage: GetEventRequest');
|
|
374
|
+
})(null);
|
|
375
|
+
}
|
|
376
|
+
exports.GetEventRequest = GetEventRequest;
|
|
377
|
+
function GetLeaveEvent() {
|
|
378
|
+
return createParamDecorator((_, request) => {
|
|
379
|
+
const { leveeEvent } = request;
|
|
380
|
+
if (leveeEvent) {
|
|
381
|
+
return leveeEvent;
|
|
382
|
+
}
|
|
383
|
+
throw new Error('Invalid decorator usage: GetLeaveEvent');
|
|
384
|
+
})(null);
|
|
385
|
+
}
|
|
386
|
+
exports.GetLeaveEvent = GetLeaveEvent;
|
|
387
|
+
function OnConnectionRequest() {
|
|
388
|
+
return (target, propertyKey, descriptor) => {
|
|
389
|
+
const originalMethod = descriptor.value;
|
|
390
|
+
const { set } = manageConnectionHandlers(target);
|
|
391
|
+
set('', (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
392
|
+
try {
|
|
393
|
+
const req = {
|
|
394
|
+
connection: request,
|
|
395
|
+
};
|
|
396
|
+
const res = {
|
|
397
|
+
connection: response,
|
|
398
|
+
};
|
|
399
|
+
const canProceed = yield resolveGuards(moduleRef, req, target, propertyKey);
|
|
400
|
+
if (canProceed) {
|
|
401
|
+
const data = yield originalMethod.apply(instance, resolveParameters(req, res, target, propertyKey));
|
|
402
|
+
if (!response.hasResponded) {
|
|
403
|
+
if (data) {
|
|
404
|
+
const { event, assigns } = data, rest = __rest(data, ["event", "assigns"]);
|
|
405
|
+
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
406
|
+
response.send(event, rest, assigns);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
response.accept();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
response.reject('Unauthorized', 401);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
if (!response.hasResponded && error instanceof Error) {
|
|
423
|
+
response.reject(error.message);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}));
|
|
427
|
+
};
|
|
451
428
|
}
|
|
429
|
+
exports.OnConnectionRequest = OnConnectionRequest;
|
|
452
430
|
function OnJoinRequest() {
|
|
453
431
|
return (target, propertyKey, descriptor) => {
|
|
454
432
|
const originalMethod = descriptor.value;
|
|
455
433
|
const { set } = manageJoinHandlers(target);
|
|
456
|
-
set('', (instance, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
434
|
+
set('', (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
457
435
|
try {
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
436
|
+
const req = {
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
438
|
+
// @ts-expect-error
|
|
439
|
+
joinRequest: request,
|
|
440
|
+
};
|
|
441
|
+
const res = {
|
|
442
|
+
joinResponse: response,
|
|
443
|
+
};
|
|
444
|
+
const canProceed = yield resolveGuards(moduleRef, req, target, propertyKey);
|
|
445
|
+
if (canProceed) {
|
|
446
|
+
const data = yield originalMethod.apply(instance, resolveParameters(req, res, target, propertyKey));
|
|
447
|
+
if (!response.hasResponded) {
|
|
448
|
+
if (data) {
|
|
449
|
+
const { event, presence, assigns } = data, rest = __rest(data, ["event", "presence", "assigns"]);
|
|
450
|
+
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
451
|
+
response.send(event, rest, assigns);
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
455
|
+
}
|
|
456
|
+
if (presence) {
|
|
457
|
+
response.trackPresence(presence);
|
|
458
|
+
}
|
|
464
459
|
}
|
|
465
460
|
else {
|
|
466
|
-
response.accept(
|
|
467
|
-
}
|
|
468
|
-
if (presence) {
|
|
469
|
-
response.trackPresence(presence);
|
|
461
|
+
response.accept();
|
|
470
462
|
}
|
|
471
463
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
response.reject('Unauthorized', 401);
|
|
475
467
|
}
|
|
476
468
|
}
|
|
477
469
|
catch (error) {
|
|
@@ -487,9 +479,11 @@ function OnLeaveEvent() {
|
|
|
487
479
|
return (target, propertyKey, descriptor) => {
|
|
488
480
|
const originalMethod = descriptor.value;
|
|
489
481
|
const { set } = manageOnLeaveHandlers(target);
|
|
490
|
-
set('', (instance, event) => __awaiter(this, void 0, void 0, function* () {
|
|
482
|
+
set('', (instance, _, event) => __awaiter(this, void 0, void 0, function* () {
|
|
491
483
|
try {
|
|
492
|
-
yield originalMethod.apply(instance,
|
|
484
|
+
yield originalMethod.apply(instance, resolveParameters({
|
|
485
|
+
leveeEvent: event,
|
|
486
|
+
}, {}, target, propertyKey));
|
|
493
487
|
}
|
|
494
488
|
catch (error) {
|
|
495
489
|
if (error instanceof Error) {
|
|
@@ -504,59 +498,42 @@ function OnEvent(event = '*') {
|
|
|
504
498
|
return (target, propertyKey, descriptor) => {
|
|
505
499
|
const originalMethod = descriptor.value;
|
|
506
500
|
const { set } = manageEventHandlers(target);
|
|
507
|
-
set(event, (instance, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
501
|
+
set(event, (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
508
502
|
try {
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
503
|
+
const req = {
|
|
504
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
505
|
+
// @ts-expect-error
|
|
506
|
+
eventRequest: request,
|
|
507
|
+
};
|
|
508
|
+
const res = {
|
|
509
|
+
eventResponse: response,
|
|
510
|
+
};
|
|
511
|
+
const canProceed = yield resolveGuards(moduleRef, req, target, propertyKey);
|
|
512
|
+
if (canProceed) {
|
|
513
|
+
const data = yield originalMethod.apply(instance, resolveParameters(req, res, target, propertyKey));
|
|
514
|
+
if (!response.hasResponded) {
|
|
515
|
+
if (data) {
|
|
516
|
+
const { event, presence, updatePresence, assigns } = data, rest = __rest(data, ["event", "presence", "updatePresence", "assigns"]);
|
|
517
|
+
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
518
|
+
response.send(event, rest, assigns);
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
522
|
+
}
|
|
523
|
+
if (presence) {
|
|
524
|
+
response.trackPresence(presence);
|
|
525
|
+
}
|
|
526
|
+
else if (updatePresence) {
|
|
527
|
+
response.updatePresence(updatePresence);
|
|
528
|
+
}
|
|
515
529
|
}
|
|
516
530
|
else {
|
|
517
|
-
response.accept(
|
|
518
|
-
}
|
|
519
|
-
if (presence) {
|
|
520
|
-
response.trackPresence(presence);
|
|
531
|
+
response.accept();
|
|
521
532
|
}
|
|
522
|
-
else if (updatePresence) {
|
|
523
|
-
response.updatePresence(updatePresence);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
else {
|
|
527
|
-
response.accept();
|
|
528
533
|
}
|
|
529
534
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
if (!response.hasResponded && error instanceof Error) {
|
|
533
|
-
response.reject(error.message);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}));
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
exports.OnEvent = OnEvent;
|
|
540
|
-
function OnConnectionRequest() {
|
|
541
|
-
return (target, propertyKey, descriptor) => {
|
|
542
|
-
const originalMethod = descriptor.value;
|
|
543
|
-
const { set } = manageConnectionHandlers(target);
|
|
544
|
-
set('', (instance, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
545
|
-
try {
|
|
546
|
-
const data = yield originalMethod.apply(instance, resolveConnectionParameters(request, response, target, propertyKey));
|
|
547
|
-
if (!response.hasResponded) {
|
|
548
|
-
if (data) {
|
|
549
|
-
const { event, assigns } = data, rest = __rest(data, ["event", "assigns"]);
|
|
550
|
-
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
551
|
-
response.send(event, rest, assigns);
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
response.accept();
|
|
559
|
-
}
|
|
535
|
+
else {
|
|
536
|
+
response.reject('Unauthorized', 401);
|
|
560
537
|
}
|
|
561
538
|
}
|
|
562
539
|
catch (error) {
|
|
@@ -567,7 +544,7 @@ function OnConnectionRequest() {
|
|
|
567
544
|
}));
|
|
568
545
|
};
|
|
569
546
|
}
|
|
570
|
-
exports.
|
|
547
|
+
exports.OnEvent = OnEvent;
|
|
571
548
|
function ChannelInstance(name) {
|
|
572
549
|
return (target, propertyKey) => {
|
|
573
550
|
const { build } = manageChannelInstance(target);
|
|
@@ -589,14 +566,13 @@ function EndpointInstance() {
|
|
|
589
566
|
exports.EndpointInstance = EndpointInstance;
|
|
590
567
|
const Channel = (path = '*') => createClassDecorator(channelClassKey, path);
|
|
591
568
|
exports.Channel = Channel;
|
|
592
|
-
const
|
|
593
|
-
const
|
|
569
|
+
const setEndpoint = (path = '*') => createClassDecorator(endpointClassKey, path);
|
|
570
|
+
const setChannels = (channels) => createClassDecorator(channelsClassKey, channels);
|
|
594
571
|
const getChannels = (target) => {
|
|
595
572
|
var _a;
|
|
596
573
|
return (_a = getClassMetadata(channelsClassKey, target)) !== null && _a !== void 0 ? _a : [];
|
|
597
574
|
};
|
|
598
|
-
|
|
599
|
-
const Endpoint = (metadata) => (0, common_1.applyDecorators)(SetChannels(metadata.channels), SetEndpoint(metadata.path));
|
|
575
|
+
const Endpoint = (metadata) => (0, common_1.applyDecorators)(setChannels(metadata.channels), setEndpoint(metadata.path));
|
|
600
576
|
exports.Endpoint = Endpoint;
|
|
601
577
|
class PondSocketService {
|
|
602
578
|
constructor(moduleRef, adapterHost, endpoints) {
|
|
@@ -623,7 +599,7 @@ class PondSocketService {
|
|
|
623
599
|
const { get } = manageConnectionHandlers(instance);
|
|
624
600
|
const [handler] = get();
|
|
625
601
|
if (handler) {
|
|
626
|
-
yield handler.value(instance, request, response);
|
|
602
|
+
yield handler.value(instance, this.moduleRef, request, response);
|
|
627
603
|
}
|
|
628
604
|
else {
|
|
629
605
|
response.accept();
|
|
@@ -644,7 +620,7 @@ class PondSocketService {
|
|
|
644
620
|
const { get } = manageJoinHandlers(instance);
|
|
645
621
|
const [handler] = get();
|
|
646
622
|
if (handler) {
|
|
647
|
-
yield handler.value(instance, request, response);
|
|
623
|
+
yield handler.value(instance, this.moduleRef, request, response);
|
|
648
624
|
}
|
|
649
625
|
else {
|
|
650
626
|
response.accept();
|
|
@@ -655,13 +631,13 @@ class PondSocketService {
|
|
|
655
631
|
const { set } = manageChannelInstance(instance);
|
|
656
632
|
getEventHandlers().forEach((handler) => {
|
|
657
633
|
channelInstance.onEvent(handler.path, (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
658
|
-
yield handler.value(instance, request, response);
|
|
634
|
+
yield handler.value(instance, this.moduleRef, request, response);
|
|
659
635
|
}));
|
|
660
636
|
});
|
|
661
637
|
const [leaveHandler] = getLeaveHandlers();
|
|
662
638
|
if (leaveHandler) {
|
|
663
639
|
channelInstance.onLeave((event) => __awaiter(this, void 0, void 0, function* () {
|
|
664
|
-
yield leaveHandler.value(instance, event);
|
|
640
|
+
yield leaveHandler.value(instance, this.moduleRef, event);
|
|
665
641
|
}));
|
|
666
642
|
}
|
|
667
643
|
set(channelInstance);
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server as HTTPServer, IncomingHttpHeaders } from 'http';
|
|
2
2
|
|
|
3
|
-
import { ModuleMetadata, DynamicModule } from '@nestjs/common';
|
|
3
|
+
import type { ModuleMetadata, DynamicModule } from '@nestjs/common';
|
|
4
4
|
import type { Express } from 'express';
|
|
5
5
|
import { WebSocketServer } from 'ws';
|
|
6
6
|
|
|
@@ -87,12 +87,36 @@ interface LeaveEvent {
|
|
|
87
87
|
|
|
88
88
|
type LeaveCallback = (event: LeaveEvent) => void;
|
|
89
89
|
|
|
90
|
+
interface NestRequest {
|
|
91
|
+
connection?: IncomingConnection<string>;
|
|
92
|
+
joinRequest?: JoinRequest<string>;
|
|
93
|
+
eventRequest?: EventRequest<string>;
|
|
94
|
+
leveeEvent?: LeaveEvent;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface NestResponse {
|
|
98
|
+
connection?: ConnectionResponse;
|
|
99
|
+
joinResponse?: JoinResponse;
|
|
100
|
+
eventResponse?: EventResponse;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type ParamDecoratorCallback<Input> = (data: Input, request: NestRequest, response: NestResponse) => unknown;
|
|
104
|
+
|
|
90
105
|
interface UserData {
|
|
91
106
|
assigns: PondAssigns;
|
|
92
107
|
presence: PondPresence;
|
|
93
108
|
id: string;
|
|
94
109
|
}
|
|
95
110
|
|
|
111
|
+
export interface CanActivate {
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @desc Whether the client can continue with the request
|
|
115
|
+
* @param request - the request to check
|
|
116
|
+
*/
|
|
117
|
+
canActivate(request: NestRequest): boolean | Promise<boolean>;
|
|
118
|
+
}
|
|
119
|
+
|
|
96
120
|
export enum ChannelState {
|
|
97
121
|
IDLE = 'IDLE',
|
|
98
122
|
JOINING = 'JOINING',
|
|
@@ -750,6 +774,19 @@ declare function GetConnectionHeaders(): ParameterDecorator;
|
|
|
750
774
|
*/
|
|
751
775
|
declare function GetConnectionQuery(): ParameterDecorator;
|
|
752
776
|
|
|
777
|
+
/**
|
|
778
|
+
* @desc The Decorator for retrieving the LeaveEvent in a handler
|
|
779
|
+
* @returns {LeaveEvent}
|
|
780
|
+
*/
|
|
781
|
+
declare function GetLeaveEvent(): ParameterDecorator;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* @desc Function to create a param decorator
|
|
785
|
+
* @param callback - The callback to call when the decorator is used
|
|
786
|
+
* @returns {ReturnType<callback>}
|
|
787
|
+
*/
|
|
788
|
+
declare function createParamDecorator<Input> (callback: ParamDecoratorCallback<Input>): ParameterDecorator;
|
|
789
|
+
|
|
753
790
|
/**
|
|
754
791
|
* @desc Marks a method as a handler for JoinRequest events. Throwing an error will reject the request with the error message.
|
|
755
792
|
*/
|
|
@@ -789,18 +826,18 @@ declare function ChannelInstance(name?: string): PropertyDecorator;
|
|
|
789
826
|
*/
|
|
790
827
|
declare function EndpointInstance (): PropertyDecorator;
|
|
791
828
|
|
|
792
|
-
/**
|
|
793
|
-
* Decorator to mark a class as having multiple channels.
|
|
794
|
-
* @param channels - The array of channels.
|
|
795
|
-
*/
|
|
796
|
-
declare function Channels(channels: Constructor<NonNullable<unknown>>[]): ClassDecorator;
|
|
797
|
-
|
|
798
829
|
/**
|
|
799
830
|
* Decorator to mark a class as an endpoint.
|
|
800
831
|
* @param metadata - The metadata for the endpoint.
|
|
801
832
|
*/
|
|
802
833
|
declare function DEndpoint(metadata: EndpointMetadata): ClassDecorator;
|
|
803
834
|
|
|
835
|
+
/**
|
|
836
|
+
* Decorator to add a guard to a class or method.
|
|
837
|
+
* @param guards - The guards to add.
|
|
838
|
+
*/
|
|
839
|
+
declare function PondGuards (...guards: Constructor<CanActivate>[]): ClassDecorator | MethodDecorator;
|
|
840
|
+
|
|
804
841
|
declare class PondSocketModule {
|
|
805
842
|
/**
|
|
806
843
|
* @desc Creates a new PondSocketModule
|