jp.ms.common.modules 1.0.41 → 1.0.42

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.
Files changed (189) hide show
  1. package/dist/modules/anti-freeze-system/anti-freeze-system.module.d.ts +3 -1
  2. package/dist/modules/anti-freeze-system/anti-freeze-system.module.js +8 -4
  3. package/dist/modules/anti-freeze-system/anti-freeze-system.module.js.map +1 -1
  4. package/dist/modules/anti-freeze-system/anti-freeze-system.service.d.ts +6 -2
  5. package/dist/modules/anti-freeze-system/anti-freeze-system.service.js +37 -10
  6. package/dist/modules/anti-freeze-system/anti-freeze-system.service.js.map +1 -1
  7. package/dist/modules/base-achievements/base-achievements.module.js +2 -2
  8. package/dist/modules/base-achievements/base-achievements.module.js.map +1 -1
  9. package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.d.ts +1 -0
  10. package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.js +5 -0
  11. package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.js.map +1 -0
  12. package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.d.ts +13 -0
  13. package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.js +3 -0
  14. package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.js.map +1 -0
  15. package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.d.ts +15 -0
  16. package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.js +77 -0
  17. package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.js.map +1 -0
  18. package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.d.ts +19 -0
  19. package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.js +83 -0
  20. package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.js.map +1 -0
  21. package/dist/modules/event-bus/events-bus.module.js +3 -0
  22. package/dist/modules/event-bus/events-bus.module.js.map +1 -1
  23. package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.d.ts +10 -0
  24. package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.js +26 -0
  25. package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.js.map +1 -0
  26. package/dist/modules/event-bus/index.d.ts +1 -0
  27. package/dist/modules/event-bus/index.js +3 -1
  28. package/dist/modules/event-bus/index.js.map +1 -1
  29. package/dist/modules/events/events.gateway.d.ts +6 -1
  30. package/dist/modules/events/events.gateway.js +15 -3
  31. package/dist/modules/events/events.gateway.js.map +1 -1
  32. package/dist/modules/index.d.ts +1 -0
  33. package/dist/modules/index.js +3 -1
  34. package/dist/modules/index.js.map +1 -1
  35. package/dist/modules/main/main.module.js +1 -1
  36. package/dist/modules/main/main.module.js.map +1 -1
  37. package/dist/modules/many-tables-tournament/many-tables-tournament.module.js +1 -1
  38. package/dist/modules/many-tables-tournament/many-tables-tournament.module.js.map +1 -1
  39. package/dist/modules/one-table-tournament/one-table-tournament.module.js +1 -1
  40. package/dist/modules/one-table-tournament/one-table-tournament.module.js.map +1 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +57 -57
  43. package/src/dto/app-screen/app-screen-app-bar.dto.ts +36 -36
  44. package/src/dto/app-screen/app-screen-dialog.dto.ts +64 -64
  45. package/src/dto/app-screen/app-screen-field-list-item.dto.ts +42 -42
  46. package/src/dto/app-screen/app-screen-field.dto.ts +59 -59
  47. package/src/dto/app-screen/app-screen-section-button.dto.ts +60 -60
  48. package/src/dto/app-screen/app-screen-section-buttons.dto.ts +14 -14
  49. package/src/dto/app-screen/app-screen-section-image.dto.ts +33 -33
  50. package/src/dto/app-screen/app-screen-section-list-item.dto.ts +105 -105
  51. package/src/dto/app-screen/app-screen-section-req.dto.ts +33 -33
  52. package/src/dto/app-screen/app-screen-section.dto.ts +76 -76
  53. package/src/dto/app-screen/app-screen.dto.ts +50 -50
  54. package/src/dto/app-screen/base-app-screen.dto.ts +16 -16
  55. package/src/dto/app-screen/index.ts +10 -10
  56. package/src/dto/app-table/bids-panel-item.dto.ts +33 -33
  57. package/src/dto/app-table/bids-panel.dto.ts +32 -32
  58. package/src/dto/app-table/card.dto.ts +54 -54
  59. package/src/dto/app-table/cards-deck.dto.ts +22 -22
  60. package/src/dto/app-table/cards-pair-slots-item.dto.ts +45 -45
  61. package/src/dto/app-table/cards-pair-slots.dto.ts +13 -13
  62. package/src/dto/app-table/cards-panel.dto.ts +48 -48
  63. package/src/dto/app-table/cards-player.dto.ts +14 -14
  64. package/src/dto/app-table/cards-slots-item.dto.ts +40 -40
  65. package/src/dto/app-table/cards-slots.dto.ts +13 -13
  66. package/src/dto/app-table/index.ts +15 -15
  67. package/src/dto/app-table/moves-panel-button.dto.ts +24 -24
  68. package/src/dto/app-table/moves-panel.dto.ts +23 -23
  69. package/src/dto/app-table/player.dto.ts +69 -69
  70. package/src/dto/app-table/summary-item.dto.ts +51 -51
  71. package/src/dto/app-table/summary.dto.ts +13 -13
  72. package/src/dto/common/find-free-table.dto.ts +3 -3
  73. package/src/dto/common/index.ts +2 -2
  74. package/src/dto/common/join-tournament.dto.ts +33 -33
  75. package/src/dto/common/log.dto.ts +9 -9
  76. package/src/dto/common/many-tables-tournament-create.dto.ts +125 -125
  77. package/src/dto/common/many-tables-tournament-update.dto.ts +3 -3
  78. package/src/dto/common/player-check-state.dto.ts +33 -33
  79. package/src/dto/common/player-connected.dto.ts +58 -58
  80. package/src/dto/games/fool/fool-player.dto.ts +3 -3
  81. package/src/dto/games/fool/fool-table.dto.ts +81 -81
  82. package/src/dto/games/index.ts +2 -2
  83. package/src/dto/games/poker/poker-player.dto.ts +3 -3
  84. package/src/dto/games/poker/poker-table.dto.ts +81 -81
  85. package/src/dto/index.ts +4 -4
  86. package/src/exception/error-code.enum.ts +4 -4
  87. package/src/exception/global-exception-filter.ts +53 -53
  88. package/src/exception/http-exception-wth-snackbar.ts +27 -27
  89. package/src/exception/index.ts +4 -4
  90. package/src/exception/not-enough-money-for-purchase.exception.ts +14 -14
  91. package/src/exception/not-found-free-room-for-fast-game.exception.ts +14 -14
  92. package/src/index.ts +4 -4
  93. package/src/modules/anti-freeze-system/anti-freeze-system.constants.ts +1 -1
  94. package/src/modules/anti-freeze-system/anti-freeze-system.interfaces.ts +20 -20
  95. package/src/modules/anti-freeze-system/anti-freeze-system.module.ts +59 -55
  96. package/src/modules/anti-freeze-system/anti-freeze-system.service.ts +136 -105
  97. package/src/modules/anti-freeze-system/index.ts +1 -1
  98. package/src/modules/base-achievements/base-achievements.module.ts +324 -322
  99. package/src/modules/base-achievements/index.ts +1 -1
  100. package/src/modules/confirmation-message-manager/confirmation-message-manager.constants.ts +3 -0
  101. package/src/modules/confirmation-message-manager/confirmation-message-manager.interfaces.ts +20 -0
  102. package/src/modules/confirmation-message-manager/confirmation-message-manager.module.ts +77 -0
  103. package/src/modules/confirmation-message-manager/confirmation-message-manager.service.ts +91 -0
  104. package/src/modules/event-bus/events-bus.app.subscribe.service.ts +20 -20
  105. package/src/modules/event-bus/events-bus.main-tables.subscribe.service.ts +34 -34
  106. package/src/modules/event-bus/events-bus.many-tables-tournament.subscribe.service.ts +6 -6
  107. package/src/modules/event-bus/events-bus.module.ts +26 -23
  108. package/src/modules/event-bus/events-bus.one-table-tournament.subscribe.service.ts +6 -6
  109. package/src/modules/event-bus/events-bus.player-ws-message.subscribe.service.ts +30 -0
  110. package/src/modules/event-bus/events-bus.tournament.subscribe.service.ts +18 -18
  111. package/src/modules/event-bus/index.ts +6 -5
  112. package/src/modules/events/events.constants.ts +1 -1
  113. package/src/modules/events/events.gateway.ts +82 -70
  114. package/src/modules/events/events.interfaces.ts +17 -17
  115. package/src/modules/events/events.module.ts +32 -32
  116. package/src/modules/events/index.ts +1 -1
  117. package/src/modules/index.ts +28 -27
  118. package/src/modules/logger/index.ts +2 -2
  119. package/src/modules/logger/jp-logger.module.ts +10 -10
  120. package/src/modules/logger/jp-logger.service.ts +38 -38
  121. package/src/modules/main/index.ts +1 -1
  122. package/src/modules/main/main-tables-list-screen.view.ts +275 -275
  123. package/src/modules/main/main.constants.ts +1 -1
  124. package/src/modules/main/main.controller.ts +72 -72
  125. package/src/modules/main/main.interfaces.ts +17 -17
  126. package/src/modules/main/main.module.ts +73 -73
  127. package/src/modules/main/main.service.ts +183 -183
  128. package/src/modules/many-tables-tournament/index.ts +1 -1
  129. package/src/modules/many-tables-tournament/many-tables-tournament-status-screen.view.ts +143 -143
  130. package/src/modules/many-tables-tournament/many-tables-tournament-tables-list-screen.view.ts +63 -63
  131. package/src/modules/many-tables-tournament/many-tables-tournament.constants.ts +3 -3
  132. package/src/modules/many-tables-tournament/many-tables-tournament.controller.ts +151 -151
  133. package/src/modules/many-tables-tournament/many-tables-tournament.interfaces.ts +20 -20
  134. package/src/modules/many-tables-tournament/many-tables-tournament.module.ts +81 -80
  135. package/src/modules/many-tables-tournament/many-tables-tournament.service.ts +208 -208
  136. package/src/modules/many-tables-tournament-rooms-manager/index.ts +2 -2
  137. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.constants.ts +3 -3
  138. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.interfaces.ts +37 -37
  139. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.module.ts +84 -84
  140. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.ts +331 -331
  141. package/src/modules/menu/index.ts +1 -1
  142. package/src/modules/menu/menu-screen.view.ts +71 -71
  143. package/src/modules/menu/menu.constants.ts +1 -1
  144. package/src/modules/menu/menu.controller.ts +16 -16
  145. package/src/modules/menu/menu.interfaces.ts +17 -17
  146. package/src/modules/menu/menu.module.ts +39 -39
  147. package/src/modules/menu/menu.service.ts +39 -39
  148. package/src/modules/one-table-tournament/index.ts +1 -1
  149. package/src/modules/one-table-tournament/one-table-tournament-status-screen.view.ts +166 -166
  150. package/src/modules/one-table-tournament/one-table-tournament.constants.ts +3 -3
  151. package/src/modules/one-table-tournament/one-table-tournament.controller.ts +104 -104
  152. package/src/modules/one-table-tournament/one-table-tournament.interfaces.ts +20 -20
  153. package/src/modules/one-table-tournament/one-table-tournament.module.ts +80 -76
  154. package/src/modules/one-table-tournament/one-table-tournament.service.ts +146 -146
  155. package/src/modules/one-table-tournament-rooms-manager/index.ts +2 -2
  156. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.constants.ts +3 -3
  157. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.interfaces.ts +31 -31
  158. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.module.ts +66 -66
  159. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.ts +220 -220
  160. package/src/modules/players-manager/index.ts +2 -2
  161. package/src/modules/players-manager/players-manager.module.ts +9 -9
  162. package/src/modules/players-manager/players-manager.service.ts +27 -27
  163. package/src/modules/simple-rooms/index.ts +1 -1
  164. package/src/modules/simple-rooms/simple-rooms.constants.ts +1 -1
  165. package/src/modules/simple-rooms/simple-rooms.controller.ts +63 -63
  166. package/src/modules/simple-rooms/simple-rooms.interfaces.ts +20 -20
  167. package/src/modules/simple-rooms/simple-rooms.module.ts +39 -39
  168. package/src/modules/simple-rooms/simple-rooms.service.ts +95 -95
  169. package/src/modules/simple-rooms-manager/index.ts +2 -2
  170. package/src/modules/simple-rooms-manager/simple-rooms-manager.constants.ts +3 -3
  171. package/src/modules/simple-rooms-manager/simple-rooms-manager.interfaces.ts +26 -26
  172. package/src/modules/simple-rooms-manager/simple-rooms-manager.module.ts +60 -60
  173. package/src/modules/simple-rooms-manager/simple-rooms-manager.service.ts +190 -190
  174. package/src/modules/support/dump.service.ts +11 -11
  175. package/src/modules/support/index.ts +1 -1
  176. package/src/modules/support/metric.service.ts +41 -41
  177. package/src/modules/support/support.constants.ts +1 -1
  178. package/src/modules/support/support.controller.ts +79 -79
  179. package/src/modules/support/support.interfaces.ts +16 -16
  180. package/src/modules/support/support.module.ts +35 -35
  181. package/src/modules/support/support.service.ts +27 -27
  182. package/src/utils/date.ts +7 -7
  183. package/src/utils/game-table-result.ts +129 -129
  184. package/src/views/index.ts +5 -5
  185. package/src/views/many-tables-tournament-conifrm-exit-dialog.view.ts +37 -37
  186. package/src/views/one-table-tournament-conifrm-exit-dialog.view.ts +37 -37
  187. package/src/views/simple-room-conifrm-exit-dialog.view.ts +37 -37
  188. package/src/views/table-summary.view.ts +104 -104
  189. package/src/views/tournament-buy-ticket-dialog.view.ts +34 -34
@@ -0,0 +1,20 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ import { Type } from '@nestjs/common/interfaces/type.interface';
3
+ import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
4
+ import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
5
+
6
+ export interface ConfirmationMessageManagerOptions extends Pick<
7
+ ModuleMetadata,
8
+ 'imports'
9
+ > {
10
+ imports?: Array<
11
+ Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
12
+ >;
13
+ inject?: any[];
14
+ useFactory?: (...args: any[]) => ConfirmationMessageManagerFactoryOptions;
15
+ }
16
+
17
+ export interface ConfirmationMessageManagerFactoryOptions {
18
+ confirmationMessageManagerTime: string;
19
+ confirmationMessageManagerAttemptCount: number;
20
+ }
@@ -0,0 +1,77 @@
1
+ import {
2
+ DynamicModule,
3
+ Global,
4
+ Inject,
5
+ Module,
6
+ Provider,
7
+ } from '@nestjs/common';
8
+ import schedule, { Job } from 'node-schedule';
9
+ import { BaseWsEvent } from 'jp.ms.common.engine';
10
+
11
+ import { JpLoggerService } from '../logger';
12
+ import { EventsBusPlayerWsMessageSubscribeService } from '../event-bus';
13
+
14
+ import { ConfirmationMessageManagerService } from './confirmation-message-manager.service';
15
+ import {
16
+ ConfirmationMessageManagerFactoryOptions,
17
+ ConfirmationMessageManagerOptions,
18
+ } from './confirmation-message-manager.interfaces';
19
+ import { CONFIRMATION_MESSAGE_MANAGER_OPTIONS } from './confirmation-message-manager.constants';
20
+
21
+ @Global()
22
+ @Module({
23
+ providers: [ConfirmationMessageManagerService],
24
+ exports: [ConfirmationMessageManagerService],
25
+ })
26
+ export class ConfirmationMessageManagerModule {
27
+ private confirmationMessageManagerJob: Job;
28
+
29
+ constructor(
30
+ private readonly confirmationMessageManagerService: ConfirmationMessageManagerService,
31
+ private readonly eventsBusPlayerWsMessageSubscribeService: EventsBusPlayerWsMessageSubscribeService,
32
+ @Inject(CONFIRMATION_MESSAGE_MANAGER_OPTIONS)
33
+ private readonly options: ConfirmationMessageManagerFactoryOptions,
34
+ @Inject() private readonly logger: JpLoggerService,
35
+ ) {}
36
+
37
+ static forRootAsync(
38
+ options: ConfirmationMessageManagerOptions,
39
+ ): DynamicModule {
40
+ return {
41
+ module: ConfirmationMessageManagerModule,
42
+ imports: options.imports ?? [],
43
+ providers: [
44
+ {
45
+ provide: CONFIRMATION_MESSAGE_MANAGER_OPTIONS,
46
+ useFactory: options.useFactory,
47
+ inject: options.inject || [],
48
+ } as Provider,
49
+ ],
50
+ };
51
+ }
52
+
53
+ onModuleInit() {
54
+ this.eventsBusPlayerWsMessageSubscribeService.subscribeOnSendMessage(
55
+ (wsEvent: BaseWsEvent) => {
56
+ this.confirmationMessageManagerService.addToQueue(wsEvent);
57
+ },
58
+ );
59
+
60
+ this.eventsBusPlayerWsMessageSubscribeService.subscribeOnGotMessageFromClient(
61
+ (wsEvent: BaseWsEvent) => {
62
+ this.confirmationMessageManagerService.removeFromQueue(wsEvent.key);
63
+ },
64
+ );
65
+
66
+ const confirmationMessageManagerTime =
67
+ this.options.confirmationMessageManagerTime;
68
+
69
+ if (confirmationMessageManagerTime) {
70
+ this.logger.log(`${ConfirmationMessageManagerModule.name}: scheduleJob`);
71
+ this.confirmationMessageManagerJob = schedule.scheduleJob(
72
+ confirmationMessageManagerTime,
73
+ () => this.confirmationMessageManagerService.process(),
74
+ );
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,91 @@
1
+ import { Inject, Injectable } from '@nestjs/common';
2
+ import { BaseWsEvent } from 'jp.ms.common.engine';
3
+
4
+ import { PlayersManagerService } from '../players-manager';
5
+ import { JpLoggerService } from '../logger';
6
+
7
+ import { CONFIRMATION_MESSAGE_MANAGER_OPTIONS } from './confirmation-message-manager.constants';
8
+ import { ConfirmationMessageManagerFactoryOptions } from './confirmation-message-manager.interfaces';
9
+
10
+ interface IGameMessageConfirmationManagerMessage {
11
+ event: BaseWsEvent;
12
+ repeatCount: number;
13
+ }
14
+
15
+ @Injectable()
16
+ export class ConfirmationMessageManagerService {
17
+ private queue: Map<string, IGameMessageConfirmationManagerMessage>;
18
+ private jobId: NodeJS.Timeout | null = null;
19
+
20
+ constructor(
21
+ private readonly playersManagerService: PlayersManagerService,
22
+ @Inject(CONFIRMATION_MESSAGE_MANAGER_OPTIONS)
23
+ private readonly options: ConfirmationMessageManagerFactoryOptions,
24
+ @Inject() private readonly logger: JpLoggerService,
25
+ ) {
26
+ this.queue = new Map<string, IGameMessageConfirmationManagerMessage>();
27
+ }
28
+
29
+ getByKey(key: string) {
30
+ this.queue.get(key);
31
+ }
32
+
33
+ addToQueue(message: BaseWsEvent): void {
34
+ this.logger.log(
35
+ `${ConfirmationMessageManagerService.name}: add to queue ws message key: ${message.key}, type: ${message.type}`,
36
+ );
37
+
38
+ const foundMessage = this.queue.get(message.key);
39
+
40
+ if (foundMessage) {
41
+ foundMessage.repeatCount += 1;
42
+ } else {
43
+ this.queue.set(message.key, {
44
+ event: message,
45
+ repeatCount: 0,
46
+ });
47
+ }
48
+ }
49
+
50
+ removeFromQueue(key: string): void {
51
+ this.logger.log(
52
+ `${ConfirmationMessageManagerService.name}: remove from queue ws message key: ${key}`,
53
+ );
54
+
55
+ this.queue.delete(key);
56
+ }
57
+
58
+ process() {
59
+ this.clearQueue();
60
+ this.repeatSendingMessages();
61
+ }
62
+
63
+ private isExpired(message: IGameMessageConfirmationManagerMessage): boolean {
64
+ return (
65
+ message.repeatCount >= this.options.confirmationMessageManagerAttemptCount
66
+ );
67
+ }
68
+
69
+ private clearQueue(): void {
70
+ for (const [key, message] of this.queue) {
71
+ if (this.isExpired(message)) {
72
+ this.logger.log(
73
+ `${ConfirmationMessageManagerService.name}: clear expired ws message key: ${message.event.key}, type: ${message.event.type}`,
74
+ );
75
+ this.queue.delete(key);
76
+ }
77
+ }
78
+ }
79
+
80
+ private repeatSendingMessages(): void {
81
+ for (const [, message] of this.queue) {
82
+ const foundPlayer = this.playersManagerService.getPlayerById(
83
+ message.event.playerId,
84
+ );
85
+ this.logger.log(
86
+ `${ConfirmationMessageManagerService.name}: repeat ws message key: ${message.event.key}, type: ${message.event.type}, repeatCount: ${message.repeatCount}`,
87
+ );
88
+ foundPlayer?.sendMessage(message.event);
89
+ }
90
+ }
91
+ }
@@ -1,20 +1,20 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { BaseAppEvent } from 'jp.ms.common.engine';
3
- import { Subject } from 'rxjs';
4
-
5
- @Injectable()
6
- export class EventsBusAppSubscribeService {
7
- private readonly appEventSubject: Subject<BaseAppEvent>;
8
-
9
- constructor() {
10
- this.appEventSubject = new Subject<BaseAppEvent>();
11
- }
12
-
13
- pushNewEvent(event: BaseAppEvent) {
14
- this.appEventSubject.next(event);
15
- }
16
-
17
- subscribe(onHandleAppEvent: (event: BaseAppEvent) => void) {
18
- this.appEventSubject.subscribe(onHandleAppEvent);
19
- }
20
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { BaseAppEvent } from 'jp.ms.common.engine';
3
+ import { Subject } from 'rxjs';
4
+
5
+ @Injectable()
6
+ export class EventsBusAppSubscribeService {
7
+ private readonly appEventSubject: Subject<BaseAppEvent>;
8
+
9
+ constructor() {
10
+ this.appEventSubject = new Subject<BaseAppEvent>();
11
+ }
12
+
13
+ pushNewEvent(event: BaseAppEvent) {
14
+ this.appEventSubject.next(event);
15
+ }
16
+
17
+ subscribe(onHandleAppEvent: (event: BaseAppEvent) => void) {
18
+ this.appEventSubject.subscribe(onHandleAppEvent);
19
+ }
20
+ }
@@ -1,34 +1,34 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { GamePlayer, RoomUpdateStateEvent } from 'jp.ms.common.engine';
3
- import { Subject } from 'rxjs';
4
-
5
- @Injectable()
6
- export class EventsBusMainTablesSubscribeService {
7
- private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
8
- private readonly tablesSubscribers: Map<string, GamePlayer>;
9
-
10
- constructor() {
11
- this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
12
- this.tablesSubscribers = new Map();
13
- }
14
-
15
- getTablesSubscribers() {
16
- return Array.from(this.tablesSubscribers.values());
17
- }
18
-
19
- addTablesSubscriber(player: GamePlayer) {
20
- this.tablesSubscribers.set(player.id, player);
21
- }
22
-
23
- removeTablesSubbcriber(player: GamePlayer) {
24
- this.tablesSubscribers.delete(player.id);
25
- }
26
-
27
- pushNewRoomState(event: RoomUpdateStateEvent) {
28
- this.roomStatesSubject.next(event);
29
- }
30
-
31
- subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
32
- this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
33
- }
34
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { GamePlayer, RoomUpdateStateEvent } from 'jp.ms.common.engine';
3
+ import { Subject } from 'rxjs';
4
+
5
+ @Injectable()
6
+ export class EventsBusMainTablesSubscribeService {
7
+ private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
8
+ private readonly tablesSubscribers: Map<string, GamePlayer>;
9
+
10
+ constructor() {
11
+ this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
12
+ this.tablesSubscribers = new Map();
13
+ }
14
+
15
+ getTablesSubscribers() {
16
+ return Array.from(this.tablesSubscribers.values());
17
+ }
18
+
19
+ addTablesSubscriber(player: GamePlayer) {
20
+ this.tablesSubscribers.set(player.id, player);
21
+ }
22
+
23
+ removeTablesSubbcriber(player: GamePlayer) {
24
+ this.tablesSubscribers.delete(player.id);
25
+ }
26
+
27
+ pushNewRoomState(event: RoomUpdateStateEvent) {
28
+ this.roomStatesSubject.next(event);
29
+ }
30
+
31
+ subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
32
+ this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
33
+ }
34
+ }
@@ -1,6 +1,6 @@
1
- import { Injectable } from '@nestjs/common';
2
-
3
- import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
-
5
- @Injectable()
6
- export class EventsBusManyTablesTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
+
5
+ @Injectable()
6
+ export class EventsBusManyTablesTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
@@ -1,23 +1,26 @@
1
- import { Global, Module } from '@nestjs/common';
2
-
3
- import { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
4
- import { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
5
- import { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
6
- import { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
7
-
8
- @Global()
9
- @Module({
10
- providers: [
11
- EventsBusMainTablesSubscribeService,
12
- EventsBusOneTableTournamentSubscribeService,
13
- EventsBusManyTablesTournamentSubscribeService,
14
- EventsBusAppSubscribeService,
15
- ],
16
- exports: [
17
- EventsBusMainTablesSubscribeService,
18
- EventsBusOneTableTournamentSubscribeService,
19
- EventsBusManyTablesTournamentSubscribeService,
20
- EventsBusAppSubscribeService,
21
- ],
22
- })
23
- export class EventsBusModule {}
1
+ import { Global, Module } from '@nestjs/common';
2
+
3
+ import { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
4
+ import { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
5
+ import { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
6
+ import { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
7
+ import { EventsBusPlayerWsMessageSubscribeService } from './events-bus.player-ws-message.subscribe.service';
8
+
9
+ @Global()
10
+ @Module({
11
+ providers: [
12
+ EventsBusMainTablesSubscribeService,
13
+ EventsBusOneTableTournamentSubscribeService,
14
+ EventsBusManyTablesTournamentSubscribeService,
15
+ EventsBusAppSubscribeService,
16
+ EventsBusPlayerWsMessageSubscribeService,
17
+ ],
18
+ exports: [
19
+ EventsBusMainTablesSubscribeService,
20
+ EventsBusOneTableTournamentSubscribeService,
21
+ EventsBusManyTablesTournamentSubscribeService,
22
+ EventsBusAppSubscribeService,
23
+ EventsBusPlayerWsMessageSubscribeService,
24
+ ],
25
+ })
26
+ export class EventsBusModule {}
@@ -1,6 +1,6 @@
1
- import { Injectable } from '@nestjs/common';
2
-
3
- import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
-
5
- @Injectable()
6
- export class EventsBusOneTableTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
+
5
+ @Injectable()
6
+ export class EventsBusOneTableTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
@@ -0,0 +1,30 @@
1
+ import { BaseWsEvent } from 'jp.ms.common.engine';
2
+ import { Subject } from 'rxjs';
3
+
4
+ export class EventsBusPlayerWsMessageSubscribeService {
5
+ private readonly subjectSendMessage: Subject<BaseWsEvent>;
6
+ private readonly subjectGotMessage: Subject<BaseWsEvent>;
7
+
8
+ constructor() {
9
+ this.subjectSendMessage = new Subject<BaseWsEvent>();
10
+ this.subjectGotMessage = new Subject<BaseWsEvent>();
11
+ }
12
+
13
+ pushSendMessage(event: BaseWsEvent) {
14
+ this.subjectSendMessage.next(event);
15
+ }
16
+
17
+ pushGotMessage(event: BaseWsEvent) {
18
+ this.subjectGotMessage.next(event);
19
+ }
20
+
21
+ subscribeOnSendMessage(onHandleWsEvent: (event: BaseWsEvent) => void) {
22
+ this.subjectSendMessage.subscribe(onHandleWsEvent);
23
+ }
24
+
25
+ subscribeOnGotMessageFromClient(
26
+ onHandleWsEvent: (event: BaseWsEvent) => void,
27
+ ) {
28
+ this.subjectGotMessage.subscribe(onHandleWsEvent);
29
+ }
30
+ }
@@ -1,18 +1,18 @@
1
- import { RoomUpdateStateEvent } from 'jp.ms.common.engine';
2
- import { Subject } from 'rxjs';
3
-
4
- export abstract class EventsBusTournamentSubscribeService {
5
- private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
6
-
7
- constructor() {
8
- this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
9
- }
10
-
11
- pushNewRoomState(event: RoomUpdateStateEvent) {
12
- this.roomStatesSubject.next(event);
13
- }
14
-
15
- subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
16
- this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
17
- }
18
- }
1
+ import { RoomUpdateStateEvent } from 'jp.ms.common.engine';
2
+ import { Subject } from 'rxjs';
3
+
4
+ export abstract class EventsBusTournamentSubscribeService {
5
+ private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
6
+
7
+ constructor() {
8
+ this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
9
+ }
10
+
11
+ pushNewRoomState(event: RoomUpdateStateEvent) {
12
+ this.roomStatesSubject.next(event);
13
+ }
14
+
15
+ subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
16
+ this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
17
+ }
18
+ }
@@ -1,5 +1,6 @@
1
- export { EventsBusModule } from './events-bus.module';
2
- export { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
3
- export { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
4
- export { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
5
- export { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
1
+ export { EventsBusModule } from './events-bus.module';
2
+ export { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
3
+ export { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
4
+ export { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
5
+ export { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
6
+ export { EventsBusPlayerWsMessageSubscribeService } from './events-bus.player-ws-message.subscribe.service';
@@ -1 +1 @@
1
- export const EVENTS_OPTIONS = Symbol('EVENTS_OPTIONS');
1
+ export const EVENTS_OPTIONS = Symbol('EVENTS_OPTIONS');
@@ -1,70 +1,82 @@
1
- import {
2
- WebSocketServer,
3
- OnGatewayConnection,
4
- OnGatewayDisconnect,
5
- WebSocketGateway,
6
- } from '@nestjs/websockets';
7
- import { Server, Socket } from 'socket.io';
8
- import { UsersRepository } from 'jp.db.schemas';
9
- import { Inject } from '@nestjs/common';
10
-
11
- import { PlayersManagerService } from '../players-manager/players-manager.service';
12
-
13
- import { EVENTS_OPTIONS } from './events.constants';
14
- import { EventsFactoryOptions } from './events.interfaces';
15
-
16
- @WebSocketGateway({ cors: { origin: '*' } })
17
- export class EventsGateway
18
- implements OnGatewayConnection<Socket>, OnGatewayDisconnect<Socket>
19
- {
20
- @WebSocketServer()
21
- server: Server;
22
-
23
- constructor(
24
- private readonly playersManager: PlayersManagerService,
25
- private readonly usersRepository: UsersRepository,
26
- @Inject(EVENTS_OPTIONS) private readonly options: EventsFactoryOptions,
27
- ) {}
28
-
29
- async handleConnection(client: Socket) {
30
- const playerId = client.handshake.auth.token as string | undefined;
31
-
32
- const player = this.playersManager.getPlayerById(playerId ?? '');
33
- if (player) {
34
- player.connections.addConnection(client);
35
- } else {
36
- const user = await this.usersRepository.findById(playerId ?? '');
37
- if (user) {
38
- const player = this.options.createPlayer({
39
- id: user.userId,
40
- fullName: user.fullName,
41
- avatarUrl: user.avatarUrl,
42
- balance: user.balance,
43
- experience: user.experience,
44
- level: user.level,
45
- language: user.normalizedLang,
46
- });
47
- this.playersManager.addPlayer(player);
48
- player.connections.addConnection(client);
49
- }
50
- }
51
- }
52
-
53
- handleDisconnect(client: Socket): void {
54
- const playerId = client.handshake.auth.token as string | undefined;
55
- const connectedPlayer = this.playersManager.getPlayerById(playerId ?? '');
56
-
57
- if (connectedPlayer) {
58
- connectedPlayer.disconnect();
59
-
60
- if (
61
- !connectedPlayer.isPlayer() &&
62
- !connectedPlayer.isTableQueuer() &&
63
- !connectedPlayer.isRoomQueuer() &&
64
- !connectedPlayer.hasOpenConnection()
65
- ) {
66
- this.playersManager.removePlayer(playerId ?? '');
67
- }
68
- }
69
- }
70
- }
1
+ import {
2
+ WebSocketServer,
3
+ OnGatewayConnection,
4
+ OnGatewayDisconnect,
5
+ WebSocketGateway,
6
+ } from '@nestjs/websockets';
7
+ import { Server, Socket } from 'socket.io';
8
+ import { UsersRepository } from 'jp.db.schemas';
9
+ import { Inject } from '@nestjs/common';
10
+ import { BaseWsEvent } from 'jp.ms.common.engine';
11
+
12
+ import { PlayersManagerService } from '../players-manager/players-manager.service';
13
+ import { EventsBusPlayerWsMessageSubscribeService } from '../event-bus';
14
+
15
+ import { EVENTS_OPTIONS } from './events.constants';
16
+ import { EventsFactoryOptions } from './events.interfaces';
17
+
18
+ @WebSocketGateway({ cors: { origin: '*' } })
19
+ export class EventsGateway
20
+ implements OnGatewayConnection<Socket>, OnGatewayDisconnect<Socket>
21
+ {
22
+ @WebSocketServer()
23
+ server: Server;
24
+
25
+ constructor(
26
+ private readonly playersManager: PlayersManagerService,
27
+ private readonly usersRepository: UsersRepository,
28
+ private readonly eventsBusPlayerWsMessageSubscribeService: EventsBusPlayerWsMessageSubscribeService,
29
+ @Inject(EVENTS_OPTIONS) private readonly options: EventsFactoryOptions,
30
+ ) {}
31
+
32
+ async handleConnection(client: Socket) {
33
+ const playerId = client.handshake.auth.token as string | undefined;
34
+
35
+ const player = this.playersManager.getPlayerById(playerId ?? '');
36
+ if (player) {
37
+ player.connections.addConnection(client);
38
+ } else {
39
+ const user = await this.usersRepository.findById(playerId ?? '');
40
+ if (user) {
41
+ const player = this.options.createPlayer({
42
+ id: user.userId,
43
+ fullName: user.fullName,
44
+ avatarUrl: user.avatarUrl,
45
+ balance: user.balance,
46
+ experience: user.experience,
47
+ level: user.level,
48
+ language: user.normalizedLang,
49
+ onSendWsMessage: this.handleSendWsMessage,
50
+ onGotWsMessageClientResponse: this.handleGotWsMessageClientResponse,
51
+ });
52
+ this.playersManager.addPlayer(player);
53
+ player.connections.addConnection(client);
54
+ }
55
+ }
56
+ }
57
+
58
+ handleDisconnect(client: Socket): void {
59
+ const playerId = client.handshake.auth.token as string | undefined;
60
+ const connectedPlayer = this.playersManager.getPlayerById(playerId ?? '');
61
+
62
+ if (connectedPlayer) {
63
+ connectedPlayer.disconnect();
64
+ if (
65
+ !connectedPlayer.isPlayer() &&
66
+ !connectedPlayer.isTableQueuer() &&
67
+ !connectedPlayer.isRoomQueuer() &&
68
+ !connectedPlayer.hasOpenConnection()
69
+ ) {
70
+ this.playersManager.removePlayer(playerId ?? '');
71
+ }
72
+ }
73
+ }
74
+
75
+ handleSendWsMessage = (wsEvent: BaseWsEvent) => {
76
+ this.eventsBusPlayerWsMessageSubscribeService.pushSendMessage(wsEvent);
77
+ };
78
+
79
+ handleGotWsMessageClientResponse = (wsEvent: BaseWsEvent) => {
80
+ this.eventsBusPlayerWsMessageSubscribeService.pushGotMessage(wsEvent);
81
+ };
82
+ }
@@ -1,17 +1,17 @@
1
- import { GamePlayer, IGamePlayerConfig } from 'jp.ms.common.engine';
2
- import { ModuleMetadata } from '@nestjs/common';
3
- import { Type } from '@nestjs/common/interfaces/type.interface';
4
- import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
5
- import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
6
-
7
- export interface EventsModuleOptions extends Pick<ModuleMetadata, 'imports'> {
8
- imports?: Array<
9
- Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
10
- >;
11
- inject?: any[];
12
- useFactory?: (...args: any[]) => Promise<any> | any;
13
- }
14
-
15
- export interface EventsFactoryOptions {
16
- createPlayer: (config: IGamePlayerConfig) => GamePlayer;
17
- }
1
+ import { GamePlayer, IGamePlayerConfig } from 'jp.ms.common.engine';
2
+ import { ModuleMetadata } from '@nestjs/common';
3
+ import { Type } from '@nestjs/common/interfaces/type.interface';
4
+ import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
5
+ import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
6
+
7
+ export interface EventsModuleOptions extends Pick<ModuleMetadata, 'imports'> {
8
+ imports?: Array<
9
+ Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
10
+ >;
11
+ inject?: any[];
12
+ useFactory?: (...args: any[]) => Promise<any> | any;
13
+ }
14
+
15
+ export interface EventsFactoryOptions {
16
+ createPlayer: (config: IGamePlayerConfig) => GamePlayer;
17
+ }