@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.
- package/.emerge-vis-output/fast-element/emerge-file_result_dependency_graph.graphml +126 -127
- package/.emerge-vis-output/fast-element/emerge-filesystem_graph.graphml +122 -123
- package/.emerge-vis-output/fast-element/emerge-statistics-and-metrics.json +1 -1
- package/.emerge-vis-output/fast-element/emerge-statistics-metrics.txt +43 -44
- package/.emerge-vis-output/fast-element/html/resources/js/emerge_data.js +9 -9
- package/.emerge-vis-output/fast-foundation/emerge-file_result_dependency_graph.graphml +1351 -1339
- package/.emerge-vis-output/fast-foundation/emerge-filesystem_graph.graphml +1314 -1299
- package/.emerge-vis-output/fast-foundation/emerge-statistics-and-metrics.json +1 -1
- package/.emerge-vis-output/fast-foundation/emerge-statistics-metrics.txt +1024 -1016
- package/.emerge-vis-output/fast-foundation/html/resources/js/emerge_data.js +9 -9
- package/.emerge-vis-output/rws-client/emerge-file_result_dependency_graph.graphml +61 -61
- package/.emerge-vis-output/rws-client/emerge-filesystem_graph.graphml +34 -34
- package/.emerge-vis-output/rws-client/emerge-statistics-and-metrics.json +1 -1
- package/.emerge-vis-output/rws-client/emerge-statistics-metrics.txt +623 -623
- package/.emerge-vis-output/rws-client/html/emerge.html +0 -0
- package/.emerge-vis-output/rws-client/html/jsconfig.json +0 -0
- package/.emerge-vis-output/rws-client/html/resources/css/custom.css +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_common.js +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_data.js +9 -9
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_git.js +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_graph.js +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_heatmap.js +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_hull.js +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_main.js +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_search.js +0 -0
- package/.emerge-vis-output/rws-client/html/resources/js/emerge_ui.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-grid.rtl.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-reboot.rtl.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap-utilities.rtl.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.min.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/css/bootstrap.rtl.min.css.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.js.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.bundle.min.js.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.js.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.esm.min.js.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.js.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/bootstrap/js/bootstrap.min.js.map +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/d3/d3.v7.8.4.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/d3/d3.v7.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/dark-mode-switch/css/dark-mode.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/dark-mode-switch/js/dark-mode-switch.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/daterangepicker/daterangepicker.css +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/daterangepicker/daterangepicker.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/daterangepicker/moment.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/jquery/jquery-3.6.0.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/popper/popper.min.js +0 -0
- package/.emerge-vis-output/rws-client/html/vendors/simpleheat/simpleheat.js +0 -0
- package/PLUGINS.MD +188 -0
- package/README.md +6 -1
- package/_tools.js +30 -24
- package/cfg/tsconfigSetup.js +9 -1
- package/docs/assets/main.js +4 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +7 -5
- package/docs/classes/ApiServiceInstance.html +26 -26
- package/docs/classes/ConfigServiceInstance.html +22 -21
- package/docs/classes/DOMServiceInstance.html +18 -18
- package/docs/classes/NotifyServiceInstance.html +16 -16
- package/docs/classes/RWSClientInstance.html +46 -0
- package/docs/classes/RWSPlugin.html +14 -0
- package/docs/classes/RWSService.html +11 -11
- package/docs/classes/RWSViewComponent.html +893 -705
- package/docs/classes/ServiceWorkerServiceInstance.html +14 -14
- package/docs/classes/UtilsServiceInstance.html +14 -14
- package/docs/functions/ApiService.html +1 -1
- package/docs/functions/ConfigService.html +1 -1
- package/docs/functions/DOMService.html +1 -1
- package/docs/functions/NotifyService.html +1 -1
- package/docs/functions/RWSClient.html +1 -0
- package/docs/functions/RWSContainer.html +1 -1
- package/docs/functions/RWSIgnore.html +1 -1
- package/docs/functions/RWSInject.html +1 -1
- package/docs/functions/RWSView.html +1 -1
- package/docs/functions/ServiceWorkerService.html +1 -1
- package/docs/functions/UtilsService.html +1 -1
- package/docs/functions/attr.html +6 -6
- package/docs/functions/declareRWSComponents.html +1 -1
- package/docs/functions/ngAttr.html +1 -1
- package/docs/functions/observable.html +4 -4
- package/docs/functions/provideRWSDesignSystem.html +1 -1
- package/docs/functions/sanitizedAttr.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +3 -2
- package/docs/interfaces/HTMLAttributes.html +1 -1
- package/docs/interfaces/HTMLTag.html +4 -4
- package/docs/interfaces/IRWSConfig.html +21 -20
- package/docs/interfaces/IRWSDecoratorOptions.html +6 -6
- package/docs/interfaces/IRWSHttpRoute.html +3 -3
- package/docs/interfaces/IRWSPrefixedHTTProutes.html +3 -3
- package/docs/interfaces/IRWSUser.html +6 -6
- package/docs/modules.html +46 -53
- package/docs/types/DOMOutputType.html +1 -1
- package/docs/types/DefaultRWSPluginOptionsType.html +1 -0
- package/docs/types/HTMLTagTransformerType.html +1 -1
- package/docs/types/IRWSAssetShowOptions.html +1 -1
- package/docs/types/IRWSBackendRoute.html +1 -1
- package/docs/types/NotifyLogType.html +1 -1
- package/docs/types/NotifyUiType.html +1 -1
- package/docs/types/RWSNotify.html +1 -1
- package/docs/types/RWSPluginEntry.html +1 -0
- package/docs/types/TagsProcessorType.html +1 -1
- package/package.json +1 -1
- package/rws.webpack.config.js +25 -21
- package/src/client/components.ts +16 -4
- package/src/client/config.ts +38 -7
- package/src/client.ts +12 -17
- package/src/components/_component.ts +1 -3
- package/src/components/_decorator.ts +21 -3
- package/src/components/index.ts +1 -3
- package/src/components/loader/component.ts +1 -1
- package/src/index.ts +12 -26
- package/src/interfaces/IRWSConfig.ts +6 -1
- package/src/interfaces/RWSWindow.ts +5 -2
- package/src/plugins/_builder.js +32 -0
- package/src/plugins/_plugin.ts +63 -0
- package/src/services/ConfigService.ts +9 -1
- package/src/services/ServiceWorkerService.ts +1 -1
- package/tsconfig.json +3 -0
- package/webpack/loaders/rws_fast_ts_loader.js +80 -53
- package/docs/assets/icons.js +0 -15
- package/docs/assets/icons.svg +0 -1
- package/docs/classes/RWSRouter.html +0 -10
- package/docs/classes/RoutingServiceInstance.html +0 -18
- package/docs/classes/WSServiceInstance.html +0 -38
- package/docs/functions/RoutingService.html +0 -1
- package/docs/functions/WSService.html +0 -1
- package/docs/functions/realtimeWebSuiteClientPackage.html +0 -1
- package/docs/functions/renderRouteComponent.html +0 -1
- package/docs/interfaces/IRoutingEvent.html +0 -3
- package/docs/types/IRWSFrontRoutes.html +0 -1
- package/docs/types/IRWSRouteResult.html +0 -1
- package/docs/types/IRWSWebsocketStatus.html +0 -1
- package/docs/types/RouteReturn.html +0 -1
- package/docs/variables/_ROUTING_EVENT_NAME.html +0 -1
- package/package.webpack.config.js +0 -17
- package/src/components/router/component.ts +0 -79
- package/src/components/router/template.html +0 -1
- package/src/routing/_router.ts +0 -61
- package/src/routing/index.ts +0 -7
- package/src/run.ts +0 -33
- package/src/services/RoutingService.ts +0 -47
- package/src/services/WSService.ts +0 -226
- package/src/services/_ws_handlers/ConnectionHandler.ts +0 -52
- package/src/services/_ws_handlers/EventHandler.ts +0 -28
- package/src/services/_ws_handlers/MessageHandler.ts +0 -49
- 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
|