@rws-framework/client 2.7.2 → 2.8.1

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 (180) hide show
  1. package/.emerge-vis-output/fast-element/emerge-file_result_dependency_graph.graphml +126 -127
  2. package/.emerge-vis-output/fast-element/emerge-filesystem_graph.graphml +122 -123
  3. package/.emerge-vis-output/fast-element/emerge-statistics-and-metrics.json +1 -1
  4. package/.emerge-vis-output/fast-element/emerge-statistics-metrics.txt +43 -44
  5. package/.emerge-vis-output/fast-element/html/resources/js/emerge_data.js +9 -9
  6. package/.emerge-vis-output/fast-foundation/emerge-file_result_dependency_graph.graphml +1351 -1339
  7. package/.emerge-vis-output/fast-foundation/emerge-filesystem_graph.graphml +1314 -1299
  8. package/.emerge-vis-output/fast-foundation/emerge-statistics-and-metrics.json +1 -1
  9. package/.emerge-vis-output/fast-foundation/emerge-statistics-metrics.txt +1024 -1016
  10. package/.emerge-vis-output/fast-foundation/html/resources/js/emerge_data.js +9 -9
  11. package/.emerge-vis-output/rws-client/emerge-file_result_dependency_graph.graphml +61 -61
  12. package/.emerge-vis-output/rws-client/emerge-filesystem_graph.graphml +34 -34
  13. package/.emerge-vis-output/rws-client/emerge-statistics-and-metrics.json +1 -1
  14. package/.emerge-vis-output/rws-client/emerge-statistics-metrics.txt +623 -623
  15. package/.emerge-vis-output/rws-client/html/emerge.html +0 -0
  16. package/.emerge-vis-output/rws-client/html/jsconfig.json +0 -0
  17. package/.emerge-vis-output/rws-client/html/resources/css/custom.css +0 -0
  18. package/.emerge-vis-output/rws-client/html/resources/js/emerge_common.js +0 -0
  19. package/.emerge-vis-output/rws-client/html/resources/js/emerge_data.js +9 -9
  20. package/.emerge-vis-output/rws-client/html/resources/js/emerge_git.js +0 -0
  21. package/.emerge-vis-output/rws-client/html/resources/js/emerge_graph.js +0 -0
  22. package/.emerge-vis-output/rws-client/html/resources/js/emerge_heatmap.js +0 -0
  23. package/.emerge-vis-output/rws-client/html/resources/js/emerge_hull.js +0 -0
  24. package/.emerge-vis-output/rws-client/html/resources/js/emerge_main.js +0 -0
  25. package/.emerge-vis-output/rws-client/html/resources/js/emerge_search.js +0 -0
  26. package/.emerge-vis-output/rws-client/html/resources/js/emerge_ui.js +0 -0
  27. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.css +0 -0
  28. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.css.map +0 -0
  29. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.min.css +0 -0
  30. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.min.css.map +0 -0
  31. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.css +0 -0
  32. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.css.map +0 -0
  33. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.min.css +0 -0
  34. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.min.css.map +0 -0
  35. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.css +0 -0
  36. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.css.map +0 -0
  37. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.min.css +0 -0
  38. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.min.css.map +0 -0
  39. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.css +0 -0
  40. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.css.map +0 -0
  41. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.min.css +0 -0
  42. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.min.css.map +0 -0
  43. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.css +0 -0
  44. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.css.map +0 -0
  45. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.min.css +0 -0
  46. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.min.css.map +0 -0
  47. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.css +0 -0
  48. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.css.map +0 -0
  49. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.min.css +0 -0
  50. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.min.css.map +0 -0
  51. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.css +0 -0
  52. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.css.map +0 -0
  53. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.min.css +0 -0
  54. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.min.css.map +0 -0
  55. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.css +0 -0
  56. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.css.map +0 -0
  57. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.min.css +0 -0
  58. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.min.css.map +0 -0
  59. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.js +0 -0
  60. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.js.map +0 -0
  61. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.min.js +0 -0
  62. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.min.js.map +0 -0
  63. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.js +0 -0
  64. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.js.map +0 -0
  65. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.min.js +0 -0
  66. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.min.js.map +0 -0
  67. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.js +0 -0
  68. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.js.map +0 -0
  69. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.min.js +0 -0
  70. package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.min.js.map +0 -0
  71. package/.emerge-vis-output/rws-client/html/vendors/d3/d3.v7.8.4.min.js +0 -0
  72. package/.emerge-vis-output/rws-client/html/vendors/d3/d3.v7.min.js +0 -0
  73. package/.emerge-vis-output/rws-client/html/vendors/dark-mode-switch/css/dark-mode.css +0 -0
  74. package/.emerge-vis-output/rws-client/html/vendors/dark-mode-switch/js/dark-mode-switch.min.js +0 -0
  75. package/.emerge-vis-output/rws-client/html/vendors/daterangepicker/daterangepicker.css +0 -0
  76. package/.emerge-vis-output/rws-client/html/vendors/daterangepicker/daterangepicker.min.js +0 -0
  77. package/.emerge-vis-output/rws-client/html/vendors/daterangepicker/moment.min.js +0 -0
  78. package/.emerge-vis-output/rws-client/html/vendors/jquery/jquery-3.6.0.min.js +0 -0
  79. package/.emerge-vis-output/rws-client/html/vendors/popper/popper.min.js +0 -0
  80. package/.emerge-vis-output/rws-client/html/vendors/simpleheat/simpleheat.js +0 -0
  81. package/PLUGINS.MD +188 -0
  82. package/README.md +6 -1
  83. package/_tools.js +30 -24
  84. package/cfg/tsconfigSetup.js +9 -1
  85. package/docs/assets/main.js +4 -4
  86. package/docs/assets/navigation.js +1 -1
  87. package/docs/assets/search.js +1 -1
  88. package/docs/assets/style.css +7 -5
  89. package/docs/classes/ApiServiceInstance.html +26 -26
  90. package/docs/classes/ConfigServiceInstance.html +22 -21
  91. package/docs/classes/DOMServiceInstance.html +18 -18
  92. package/docs/classes/NotifyServiceInstance.html +16 -16
  93. package/docs/classes/RWSClientInstance.html +46 -0
  94. package/docs/classes/RWSPlugin.html +14 -0
  95. package/docs/classes/RWSService.html +11 -11
  96. package/docs/classes/RWSViewComponent.html +893 -705
  97. package/docs/classes/ServiceWorkerServiceInstance.html +14 -14
  98. package/docs/classes/UtilsServiceInstance.html +14 -14
  99. package/docs/functions/ApiService.html +1 -1
  100. package/docs/functions/ConfigService.html +1 -1
  101. package/docs/functions/DOMService.html +1 -1
  102. package/docs/functions/NotifyService.html +1 -1
  103. package/docs/functions/RWSClient.html +1 -0
  104. package/docs/functions/RWSContainer.html +1 -1
  105. package/docs/functions/RWSIgnore.html +1 -1
  106. package/docs/functions/RWSInject.html +1 -1
  107. package/docs/functions/RWSView.html +1 -1
  108. package/docs/functions/ServiceWorkerService.html +1 -1
  109. package/docs/functions/UtilsService.html +1 -1
  110. package/docs/functions/attr.html +6 -6
  111. package/docs/functions/declareRWSComponents.html +1 -1
  112. package/docs/functions/ngAttr.html +1 -1
  113. package/docs/functions/observable.html +4 -4
  114. package/docs/functions/provideRWSDesignSystem.html +1 -1
  115. package/docs/functions/sanitizedAttr.html +1 -1
  116. package/docs/hierarchy.html +1 -1
  117. package/docs/index.html +3 -2
  118. package/docs/interfaces/HTMLAttributes.html +1 -1
  119. package/docs/interfaces/HTMLTag.html +4 -4
  120. package/docs/interfaces/IRWSConfig.html +21 -20
  121. package/docs/interfaces/IRWSDecoratorOptions.html +6 -6
  122. package/docs/interfaces/IRWSHttpRoute.html +3 -3
  123. package/docs/interfaces/IRWSPrefixedHTTProutes.html +3 -3
  124. package/docs/interfaces/IRWSUser.html +6 -6
  125. package/docs/modules.html +46 -53
  126. package/docs/types/DOMOutputType.html +1 -1
  127. package/docs/types/DefaultRWSPluginOptionsType.html +1 -0
  128. package/docs/types/HTMLTagTransformerType.html +1 -1
  129. package/docs/types/IRWSAssetShowOptions.html +1 -1
  130. package/docs/types/IRWSBackendRoute.html +1 -1
  131. package/docs/types/NotifyLogType.html +1 -1
  132. package/docs/types/NotifyUiType.html +1 -1
  133. package/docs/types/RWSNotify.html +1 -1
  134. package/docs/types/RWSPluginEntry.html +1 -0
  135. package/docs/types/TagsProcessorType.html +1 -1
  136. package/package.json +1 -1
  137. package/rws.webpack.config.js +25 -21
  138. package/src/client/components.ts +16 -4
  139. package/src/client/config.ts +38 -7
  140. package/src/client.ts +12 -17
  141. package/src/components/_component.ts +1 -3
  142. package/src/components/_decorator.ts +21 -3
  143. package/src/components/index.ts +1 -3
  144. package/src/components/loader/component.ts +1 -1
  145. package/src/index.ts +12 -26
  146. package/src/interfaces/IRWSConfig.ts +6 -1
  147. package/src/interfaces/RWSWindow.ts +5 -2
  148. package/src/plugins/_builder.js +32 -0
  149. package/src/plugins/_plugin.ts +63 -0
  150. package/src/services/ConfigService.ts +9 -1
  151. package/src/services/ServiceWorkerService.ts +1 -1
  152. package/tsconfig.json +3 -0
  153. package/webpack/loaders/rws_fast_ts_loader.js +80 -53
  154. package/docs/assets/icons.js +0 -15
  155. package/docs/assets/icons.svg +0 -1
  156. package/docs/classes/RWSRouter.html +0 -10
  157. package/docs/classes/RoutingServiceInstance.html +0 -18
  158. package/docs/classes/WSServiceInstance.html +0 -38
  159. package/docs/functions/RoutingService.html +0 -1
  160. package/docs/functions/WSService.html +0 -1
  161. package/docs/functions/realtimeWebSuiteClientPackage.html +0 -1
  162. package/docs/functions/renderRouteComponent.html +0 -1
  163. package/docs/interfaces/IRoutingEvent.html +0 -3
  164. package/docs/types/IRWSFrontRoutes.html +0 -1
  165. package/docs/types/IRWSRouteResult.html +0 -1
  166. package/docs/types/IRWSWebsocketStatus.html +0 -1
  167. package/docs/types/RouteReturn.html +0 -1
  168. package/docs/variables/_ROUTING_EVENT_NAME.html +0 -1
  169. package/package.webpack.config.js +0 -17
  170. package/src/components/router/component.ts +0 -79
  171. package/src/components/router/template.html +0 -1
  172. package/src/routing/_router.ts +0 -61
  173. package/src/routing/index.ts +0 -7
  174. package/src/run.ts +0 -33
  175. package/src/services/RoutingService.ts +0 -47
  176. package/src/services/WSService.ts +0 -226
  177. package/src/services/_ws_handlers/ConnectionHandler.ts +0 -52
  178. package/src/services/_ws_handlers/EventHandler.ts +0 -28
  179. package/src/services/_ws_handlers/MessageHandler.ts +0 -49
  180. package/tsdoc.json +0 -0
package/src/run.ts DELETED
@@ -1,33 +0,0 @@
1
- import { ConfigServiceInstance } from './services/ConfigService';
2
- import { NotifyServiceInstance } from './services/NotifyService';
3
- import { WSServiceInstance} from './services/WSService';
4
-
5
- import { RoutingServiceInstance} from './services/RoutingService';
6
-
7
- const main = async (
8
- config: ConfigServiceInstance,
9
- WSService: WSServiceInstance,
10
- NotifyService: NotifyServiceInstance,
11
- RoutingService: RoutingServiceInstance
12
- ): Promise<boolean> => {
13
- if(config.get('backendUrl')){
14
- WSService.on('ws:disconnected', (instance, params) => {
15
- NotifyService.notify(`Your websocket client disconnected from the server. Your ID was <strong>${params.socketId}</strong>`, 'error');
16
- });
17
-
18
- WSService.on('ws:connected', (instance, params) => {
19
- NotifyService.notify('You are connected to websocket. Your ID is: <strong>' + instance.socket().id + '</strong>', 'info');
20
- });
21
-
22
- WSService.on('ws:reconnect', (instance, params) => {
23
- console.info('WS RECONNECTION ' + (params.reconnects + 1));
24
- NotifyService.notify('Your websocket client has tried to reconnect to server. Attempt #' + (params.reconnects+1), 'warning');
25
- });
26
-
27
- WSService.init(config.get('wsUrl'), config.get('user'), config.get('transports'));
28
- }
29
-
30
- return true;
31
- };
32
-
33
- export default main;
@@ -1,47 +0,0 @@
1
-
2
- import TheService from './_service';
3
- import Router from 'url-router';
4
- import { RWSRouter, IRWSRouteResult, RouteReturn } from '../routing/_router';
5
- import UtilsService, {UtilsServiceInstance} from './UtilsService';
6
- import { IRWSViewComponent } from '../interfaces/IRWSViewComponent';
7
- import ConfigService, { ConfigServiceInstance } from './ConfigService';
8
-
9
- type IFrontRoutes = Record<string, unknown>;
10
-
11
- class RoutingService extends TheService {
12
- static _DEFAULT: boolean = true;
13
- private router: Router<any>;
14
- private routes: IFrontRoutes;
15
-
16
- constructor(@UtilsService private utilsService: UtilsServiceInstance, @ConfigService private config: ConfigServiceInstance){
17
- super();
18
- }
19
-
20
- public apply(comp: IRWSViewComponent): RWSRouter
21
- {
22
- this.routes = this.config.get('routes');
23
- this.router = new Router(this.routes);
24
-
25
- return new RWSRouter(comp, this.router, this.utilsService);
26
- }
27
-
28
- public routeHandler = <T>(comp: T) => () => {
29
- return comp;
30
- };
31
-
32
- public getRoutes(): IFrontRoutes
33
- {
34
- return this.routes;
35
- }
36
- }
37
-
38
- const renderRouteComponent = <T>(routeName: string, cmp: T, defaultRouteParams: any = {}) => (): [string, T, any] => [routeName, cmp, defaultRouteParams];
39
-
40
- const _ROUTING_EVENT_NAME = 'routing.route.change';
41
- interface IRoutingEvent {
42
- routeName: string,
43
- component: IRWSViewComponent
44
- }
45
-
46
- export default RoutingService.getSingleton();
47
- export { RoutingService as RoutingServiceInstance, IFrontRoutes, RWSRouter, IRWSRouteResult, renderRouteComponent, RouteReturn, _ROUTING_EVENT_NAME, IRoutingEvent};
@@ -1,226 +0,0 @@
1
- import TheService from './_service';
2
- import { io, Socket } from 'socket.io-client';
3
- import ITheUser from '../interfaces/IRWSUser';
4
- import { v4 as uuid } from 'uuid';
5
- import { ping, disconnect as disconnectWs, reconnect as reconnectWs } from './_ws_handlers/ConnectionHandler';
6
- import WSEventHandler from './_ws_handlers/EventHandler';
7
- import WSMessageHandler from './_ws_handlers/MessageHandler';
8
-
9
- type WSEvent = string;
10
- type WSStatus = 'WS_OPEN' | 'WS_CLOSED' | 'WS_CONNECTING';
11
-
12
- // function logClickableLink(text: string, url: string) {
13
- // console.log('[', url, ']:', text);
14
- // }
15
-
16
- // const getCurrentLineNumber = UtilsService.getCurrentLineNumber;
17
-
18
-
19
- const wsLog = async (fakeError: Error, text: any, socketId: string = null, isError: boolean = false): Promise<void> => {
20
- const logit = isError ? console.error : console.log;
21
- logit(`<WS-CLIENT>${socketId ? `(${socketId})` : ''}`, text);
22
- };
23
-
24
- class WSService extends TheService {
25
- static _DEFAULT: boolean = true;
26
- static websocket_instance: Socket;
27
- private _ws: Socket | null = null;
28
-
29
-
30
- private user: ITheUser | null = null;
31
- private url: string | null = null;
32
-
33
- private _status_string: WSStatus = 'WS_CLOSED';
34
-
35
- public _wsId: string | null = null;
36
-
37
-
38
- public _interval: any = null;
39
- public _connecting: boolean = false;
40
- public _shut_down: boolean = false;
41
- public reconnects: number = 0;
42
-
43
- public eventListeners: Map<string, Array<(instance: WSService, params: any) => any>> = new Map();
44
-
45
- public async init(url: string, user?: ITheUser, transports: string[] = null): Promise<WSService> {
46
- this._connecting = true;
47
- wsLog(new Error(), 'Connecting to: ' + url);
48
- this.url = url;
49
- this.user = user;
50
-
51
- const headers = this.user?.jwt_token ? {
52
- Authorization: 'Bearer ' + this.user?.jwt_token,
53
- } : {};
54
-
55
- if(!WSService.websocket_instance){
56
- console.log('WSSERVICE', headers);
57
- const tokenString = headers.Authorization ? `?token=${this.user.jwt_token}` : '' ;
58
- WSService.websocket_instance = io(this.url + tokenString, {
59
- auth: user?.jwt_token ? { token: user.jwt_token} : {},
60
- transports: transports || null
61
- });
62
- }
63
- //, transports: ['websocket']
64
- this._ws = WSService.websocket_instance;
65
-
66
-
67
-
68
- if (this.user?.mongoId) {
69
- this._wsId = this.user.mongoId;
70
- }else{
71
- this._wsId = uuid();
72
- }
73
-
74
- let socketId: string = null;
75
-
76
- this._ws.on('connect', () => {
77
- socketId = this.socket().id;
78
-
79
- wsLog(new Error(), 'Socket connected with ID: ' + socketId, socketId);
80
-
81
- this._connecting = false;
82
- this._ws.connected = true;
83
-
84
- this.executeEventListener('ws:connected');
85
-
86
- wsLog(new Error(), 'Emitting ping to server', socketId);
87
- ping(this);
88
- });
89
-
90
- this._ws.on('__PONG__', async (data: any) => {
91
- if (data === '__PONG__') {
92
- wsLog(new Error(), 'Recieving valid ping callback from server', socketId);
93
- return;
94
- }
95
- });
96
-
97
- this._ws.on('disconnect', async (e) => {
98
- wsLog(new Error(), 'Disconnected from the server', socketId);
99
- this.executeEventListener('ws:disconnected', { socketId: socketId, error: e });
100
- socketId = null;
101
- });
102
-
103
- this._ws.on('error', async (error: Error) => {
104
- wsLog(error, 'Socket error:', socketId, true);
105
- console.error(error);
106
- this.executeEventListener('ws:error', { socketId: socketId, error: error });
107
-
108
- });
109
-
110
-
111
- // this._interval = setInterval(() => {
112
- // ping(_self);
113
- // }, 3000);
114
-
115
- this.reconnects = 0;
116
-
117
- if (this._ws?.connected) {
118
- this._connecting = false;
119
- }
120
-
121
- this.statusChange();
122
-
123
- return this;
124
- }
125
-
126
- public getStatus(): WSStatus {
127
- return this._status_string;
128
- }
129
-
130
- public isActive(): boolean {
131
- return !this._connecting && this._ws?.connected;
132
- }
133
-
134
- setUser(user: ITheUser): void
135
- {
136
- this.user = user;
137
- }
138
-
139
- public listenForError<T extends Error | any = Error | any>(callback: (data: { error: T }) => void, method: string): void
140
- {
141
- this.socket().on(method, (rawData: string) => {
142
- callback(JSON.parse(rawData));
143
- });
144
- }
145
-
146
- public listenForMessage(callback: (data: any, isJson?: boolean) => void, method?: string): () => void
147
- {
148
- const disableHandler = () => {
149
- this.socket().off(method, callback);
150
- };
151
-
152
- WSMessageHandler.listenForMessage(this, callback, method);
153
-
154
- return disableHandler.bind(this);
155
- }
156
-
157
- async waitForStatus(): Promise<void>
158
- {
159
- return new Promise((resolve, reject) => {
160
- let iteration = 0;
161
- const t = setInterval(() => {
162
- if(iteration > 4){
163
- clearInterval(t);
164
- reject('Websocket did not connect!');
165
- }
166
-
167
- if(this.isActive()){
168
- clearInterval(t);
169
- resolve();
170
- }
171
-
172
- iteration++;
173
- }, 1000);
174
- });
175
- }
176
-
177
- public sendMessage<T>(method: string, msg: T): void {
178
- WSMessageHandler.sendMessage<T>(this, method, msg);
179
- }
180
-
181
- public statusChange(): void {
182
- let status: WSStatus = 'WS_CLOSED';
183
- if (this._connecting) {
184
- status = 'WS_CONNECTING';
185
- } else if (this.isActive()) {
186
- status = 'WS_OPEN';
187
- }
188
-
189
- this.executeEventListener('ws:status_change', { status });
190
- this._status_string = status;
191
- }
192
-
193
- public on(event: WSEvent, callback: (wsInstance: WSService, params: any) => any): void {
194
- WSEventHandler.on(this, event, callback);
195
- }
196
-
197
- public executeEventListener(event: WSEvent, params: any = {}): void {
198
- WSEventHandler.executeEventListener(this, event, params);
199
- }
200
-
201
- public socket(): Socket
202
- {
203
- return this._ws;
204
- }
205
-
206
- public disconnect()
207
- {
208
- disconnectWs(this);
209
- }
210
-
211
- public reconnect()
212
- {
213
- reconnectWs(this);
214
- }
215
-
216
- getUser(): ITheUser {
217
- return this.user;
218
- }
219
-
220
- getUrl(): string {
221
- return this.url;
222
- }
223
- }
224
-
225
- export default WSService.getSingleton();
226
- export { WSService as WSServiceInstance, WSEvent, WSService as WSInstance, WSStatus };
@@ -1,52 +0,0 @@
1
- import { WSInstance } from '../WSService';
2
-
3
-
4
- function ping(instance: WSInstance): void {
5
- instance.socket().emit('__PING__');
6
- // instance._timeout = setTimeout(() => {
7
- // reconnect(instance);
8
- // }, 3000);
9
- }
10
-
11
-
12
- function reconnect(instance: WSInstance): void {
13
- disconnect(instance, true);
14
- const rc = instance.reconnects;
15
- if (rc < 2) {
16
- instance.executeEventListener('ws:reconnect', { reconnects: rc + 1 });
17
- instance._connecting = true;
18
- instance.reconnects++;
19
- setTimeout(() => {
20
- instance.init(instance.getUrl()!, instance.getUser());
21
- instance.reconnects = rc + 1;
22
- }, 1500);
23
-
24
- instance.statusChange();
25
- } else {
26
- disconnect(instance);
27
- }
28
- }
29
- function disconnect(instance: WSInstance, noEvent = false): void {
30
-
31
- if(instance.socket()){
32
- instance.socket().disconnect();
33
- }
34
-
35
- if(!noEvent){
36
- console.log(`{WS}${instance.socket() ? `(${instance.socket().id}):` : ''} Disconnected from WS`);
37
- instance.executeEventListener('ws:disconnected');
38
- }
39
-
40
- clearInterval(instance._interval);
41
-
42
- instance._connecting = false;
43
- instance._shut_down = true;
44
-
45
- instance.statusChange();
46
- }
47
-
48
- export {
49
- ping,
50
- reconnect,
51
- disconnect
52
- };
@@ -1,28 +0,0 @@
1
- import { WSInstance, WSEvent } from '../WSService';
2
-
3
- function on(instance: WSInstance, event: WSEvent, callback: (wsInstance: WSInstance, params: any) => any): void {
4
- let listeners = instance.eventListeners.get(event);
5
- if (!listeners) {
6
- listeners = [];
7
- instance.eventListeners.set(event, listeners);
8
- }
9
- listeners.push(callback);
10
- }
11
-
12
- function executeEventListener(instance: WSInstance, event: WSEvent, params: any = {}): void {
13
- const listeners = instance.eventListeners.get(event);
14
- if (listeners) {
15
- listeners.forEach(callback => {
16
- try {
17
- callback(instance, params);
18
- } catch (e) {
19
- console.error(`Error executing callback for event '${event}':`, e);
20
- }
21
- });
22
- }
23
- }
24
-
25
- export default {
26
- on,
27
- executeEventListener
28
- };
@@ -1,49 +0,0 @@
1
- import { WSInstance } from '../WSService';
2
-
3
- function listenForMessage(instance: WSInstance, callback: (data: any, isJson?: boolean) => void, method?: string): WSInstance {
4
- if (!instance.socket()) {
5
- throw new Error('socket is not active');
6
- }
7
-
8
- instance.socket().on(method || 'message', (data: any) => {
9
- try {
10
- const parsedData = JSON.parse(data);
11
- if (!!method && parsedData.method === method) {
12
- callback(parsedData, true);
13
- instance.executeEventListener('ws:message_received', { message: parsedData });
14
-
15
- } else if (!method) {
16
- callback(parsedData, true);
17
- }
18
- } catch (e) {
19
- console.error(e);
20
-
21
- if (!method) {
22
- callback(data);
23
- }
24
- }
25
- });
26
-
27
- return instance;
28
- }
29
-
30
- function sendMessage<T>(instance: WSInstance, method: string, msg: T): void {
31
- if (!instance.socket()) {
32
- throw new Error('socket is not active');
33
- }
34
-
35
- const the_message = {
36
- user_id: instance.socket().id,
37
- method: method,
38
- msg: msg
39
- };
40
-
41
-
42
- instance.socket().emit(method, JSON.stringify(the_message));
43
- instance.executeEventListener('ws:message_sent', { message: the_message });
44
- }
45
-
46
- export default{
47
- listenForMessage,
48
- sendMessage
49
- };
package/tsdoc.json DELETED
File without changes