fix(core): update

This commit is contained in:
2020-09-24 18:03:01 +00:00
parent 424d9cca91
commit 1fbc76ef30
34 changed files with 10256 additions and 1074 deletions
+12 -12
View File
@@ -5,7 +5,7 @@ import { SocketConnection } from './smartsocket.classes.socketconnection';
import { ISocketFunctionCallDataRequest, SocketFunction } from './smartsocket.classes.socketfunction';
import { ISocketRequestDataObject, SocketRequest } from './smartsocket.classes.socketrequest';
import { SocketRole } from './smartsocket.classes.socketrole';
import { defaultLogger } from '@pushrocks/smartlog';
import { logger } from './smartsocket.logging';
/**
* interface for class SmartsocketClient
@@ -37,9 +37,9 @@ export class SmartsocketClient {
public eventSubject = new plugins.smartrx.rxjs.Subject<interfaces.TConnectionStatus>();
public eventStatus: interfaces.TConnectionStatus = 'new';
public socketFunctions = new plugins.lik.Objectmap<SocketFunction<any>>();
public socketRequests = new plugins.lik.Objectmap<SocketRequest<any>>();
public socketRoles = new plugins.lik.Objectmap<SocketRole>();
public socketFunctions = new plugins.lik.ObjectMap<SocketFunction<any>>();
public socketRequests = new plugins.lik.ObjectMap<SocketRequest<any>>();
public socketRoles = new plugins.lik.ObjectMap<SocketRole>();
constructor(optionsArg: ISmartsocketClientOptions) {
this.alias = optionsArg.alias;
@@ -62,7 +62,7 @@ export class SmartsocketClient {
*/
public connect() {
const done = plugins.smartpromise.defer();
plugins.smartlog.defaultLogger.log('info', 'trying to connect...');
logger.log('info', 'trying to connect...');
const socketUrl = `${this.serverUrl}:${this.serverPort}`;
this.socketConnection = new SocketConnection({
alias: this.alias,
@@ -79,19 +79,19 @@ export class SmartsocketClient {
const timer = new plugins.smarttime.Timer(5000);
timer.start();
timer.completed.then(() => {
defaultLogger.log('warn', 'connection to server timed out.');
logger.log('warn', 'connection to server timed out.');
this.disconnect();
});
// authentication flow
this.socketConnection.socket.on('requestAuth', (requestAuthPayload: interfaces.IRequestAuthPayload) => {
timer.reset();
plugins.smartlog.defaultLogger.log('info', 'server requested authentication');
logger.log('info', 'server requested authentication');
// lets register the authenticated event
this.socketConnection.socket.on('authenticated', () => {
this.remoteShortId = requestAuthPayload.serverShortId;
plugins.smartlog.defaultLogger.log('info', 'client is authenticated');
logger.log('info', 'client is authenticated');
this.socketConnection.authenticated = true;
this.socketConnection.listenToFunctionRequests();
done.resolve();
@@ -99,7 +99,7 @@ export class SmartsocketClient {
// lets register the forbidden event
this.socketConnection.socket.on('forbidden', async () => {
defaultLogger.log('warn', `disconnecting due to being forbidden to use the ressource`);
logger.log('warn', `disconnecting due to being forbidden to use the ressource`);
await this.disconnect();
});
@@ -136,11 +136,11 @@ export class SmartsocketClient {
*/
public async disconnect() {
if (this.socketConnection) {
this.socketConnection.disconnect();
await this.socketConnection.disconnect();
this.socketConnection = undefined;
plugins.smartlog.defaultLogger.log('ok', 'disconnected!');
logger.log('ok', 'disconnected!');
}
defaultLogger.log('warn', `disconnected from server ${this.remoteShortId}`);
logger.log('warn', `disconnected from server ${this.remoteShortId}`);
this.remoteShortId = null;
this.updateStatus('disconnected');