@eleven-am/pondsocket 0.1.74 → 0.1.75
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/lobby/lobby.js +4 -1
- package/nest.d.ts +2 -0
- package/nest.js +27 -11
- package/package.json +1 -1
- package/types.d.ts +5 -0
package/lobby/lobby.js
CHANGED
|
@@ -64,7 +64,10 @@ class LobbyEngine {
|
|
|
64
64
|
*/
|
|
65
65
|
broadcast(event, payload, channelName) {
|
|
66
66
|
if (channelName) {
|
|
67
|
-
const channel = this.getChannel(channelName)
|
|
67
|
+
const channel = this.getChannel(channelName);
|
|
68
|
+
if (!channel) {
|
|
69
|
+
throw new Error(`GatewayEngine: Channel ${channelName} does not exist`);
|
|
70
|
+
}
|
|
68
71
|
channel.sendMessage(enums_1.SystemSender.CHANNEL, enums_1.ChannelReceiver.ALL_USERS, enums_1.ServerActions.SYSTEM, event, payload);
|
|
69
72
|
}
|
|
70
73
|
else {
|
package/nest.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OnJoinRequest,
|
|
3
|
+
ChannelInstance,
|
|
3
4
|
DChannel as Channel,
|
|
4
5
|
Channels, Endpoints,
|
|
5
6
|
OnConnectionRequest,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
|
|
18
19
|
export {
|
|
19
20
|
OnJoinRequest,
|
|
21
|
+
ChannelInstance,
|
|
20
22
|
Endpoint, PondSocketModule,
|
|
21
23
|
OnConnectionRequest, OnEvent,
|
|
22
24
|
Channel, Channels, Endpoints,
|
package/nest.js
CHANGED
|
@@ -20,7 +20,7 @@ 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.Endpoints = exports.Endpoint = exports.Channels = exports.Channel = exports.OnConnectionRequest = exports.OnEvent = exports.OnJoinRequest = exports.GetConnectionQuery = exports.GetConnectionHeaders = exports.GetConnectionParams = exports.GetConnectionRequestId = exports.GetConnectionResponse = exports.GetConnectionRequest = exports.GetEventRequest = exports.GetEventResponse = exports.GetEventQuery = exports.GetEventParams = exports.GetEventPayload = exports.GetUserPresence = exports.GetInternalChannel = exports.GetUserData = exports.GetJoinParams = exports.GetJoinResponse = exports.GetJoinRequest = void 0;
|
|
23
|
+
exports.PondSocketModule = exports.Endpoints = exports.Endpoint = exports.Channels = exports.ChannelInstance = exports.Channel = exports.OnConnectionRequest = exports.OnEvent = exports.OnJoinRequest = exports.GetConnectionQuery = exports.GetConnectionHeaders = exports.GetConnectionParams = exports.GetConnectionRequestId = exports.GetConnectionResponse = exports.GetConnectionRequest = exports.GetEventRequest = exports.GetEventResponse = exports.GetEventQuery = exports.GetEventParams = exports.GetEventPayload = exports.GetUserPresence = exports.GetInternalChannel = exports.GetUserData = exports.GetJoinParams = exports.GetJoinResponse = exports.GetJoinRequest = void 0;
|
|
24
24
|
require("reflect-metadata");
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
26
|
const pondSocket_1 = require("./server/pondSocket");
|
|
@@ -409,6 +409,10 @@ function OnConnectionRequest() {
|
|
|
409
409
|
exports.OnConnectionRequest = OnConnectionRequest;
|
|
410
410
|
function Channel(path = '*') {
|
|
411
411
|
return (constructor) => class extends constructor {
|
|
412
|
+
constructor() {
|
|
413
|
+
super(...arguments);
|
|
414
|
+
this._channel = null;
|
|
415
|
+
}
|
|
412
416
|
_setEndpoint(endpoint) {
|
|
413
417
|
const channel = endpoint.createChannel(path, (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
414
418
|
const { get } = manageJoinHandlers(this);
|
|
@@ -427,28 +431,40 @@ function Channel(path = '*') {
|
|
|
427
431
|
yield handler.value(request, response);
|
|
428
432
|
}));
|
|
429
433
|
});
|
|
434
|
+
this._channel = channel;
|
|
430
435
|
}
|
|
431
436
|
};
|
|
432
437
|
}
|
|
433
438
|
exports.Channel = Channel;
|
|
439
|
+
function ChannelInstance() {
|
|
440
|
+
return (target, propertyKey) => {
|
|
441
|
+
Object.defineProperty(target, propertyKey, {
|
|
442
|
+
get() {
|
|
443
|
+
if (!target._channel) {
|
|
444
|
+
throw new Error('Channel not initialized');
|
|
445
|
+
}
|
|
446
|
+
return target._channel;
|
|
447
|
+
},
|
|
448
|
+
set() {
|
|
449
|
+
throw new Error('Channel is read-only');
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
exports.ChannelInstance = ChannelInstance;
|
|
434
455
|
function Channels(channels) {
|
|
435
456
|
return (constructor) => {
|
|
436
457
|
const { set } = manageChannels(constructor.prototype);
|
|
437
458
|
set(channels);
|
|
438
|
-
return
|
|
439
|
-
constructor() {
|
|
440
|
-
super(...arguments);
|
|
441
|
-
this._channels = channels;
|
|
442
|
-
}
|
|
443
|
-
};
|
|
459
|
+
return constructor;
|
|
444
460
|
};
|
|
445
461
|
}
|
|
446
462
|
exports.Channels = Channels;
|
|
447
463
|
function Endpoint(path = '*') {
|
|
448
464
|
return (constructor) => class extends constructor {
|
|
449
465
|
_setSocket(moduleRef, socket) {
|
|
450
|
-
var _a;
|
|
451
466
|
const { get } = manageConnectionHandlers(this);
|
|
467
|
+
const { get: getChannels } = manageChannels(this);
|
|
452
468
|
const [handler] = get();
|
|
453
469
|
const endpoint = socket.createEndpoint(path, (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
454
470
|
if (handler) {
|
|
@@ -458,8 +474,7 @@ function Endpoint(path = '*') {
|
|
|
458
474
|
response.accept();
|
|
459
475
|
}
|
|
460
476
|
}));
|
|
461
|
-
|
|
462
|
-
channels.forEach((channel) => {
|
|
477
|
+
getChannels().forEach((channel) => {
|
|
463
478
|
const chan = moduleRef.get(channel, {
|
|
464
479
|
strict: false,
|
|
465
480
|
});
|
|
@@ -496,9 +511,10 @@ class PondSocketModule {
|
|
|
496
511
|
this.socket = new pondSocket_1.PondSocket(server);
|
|
497
512
|
expressInstance.listen = (...args) => {
|
|
498
513
|
const { get } = manageEndpoints(this);
|
|
499
|
-
get().
|
|
514
|
+
get().map((endpoint) => {
|
|
500
515
|
const instance = this.moduleRef.get(endpoint, { strict: false });
|
|
501
516
|
instance._setSocket(this.moduleRef, this.socket);
|
|
517
|
+
return instance;
|
|
502
518
|
});
|
|
503
519
|
this.socket.listen(...args);
|
|
504
520
|
};
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -746,6 +746,11 @@ declare function OnConnectionRequest(): MethodDecorator;
|
|
|
746
746
|
*/
|
|
747
747
|
declare function DChannel(path?: string): ClassDecorator;
|
|
748
748
|
|
|
749
|
+
/**
|
|
750
|
+
* Decorator to retrieve the channel instance as a read-only property in a class.
|
|
751
|
+
*/
|
|
752
|
+
declare function ChannelInstance(): PropertyDecorator;
|
|
753
|
+
|
|
749
754
|
/**
|
|
750
755
|
* Decorator to mark a class as having multiple channels.
|
|
751
756
|
* @param channels - The array of channels.
|