fix(structure): update to latest standards
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as plugins from './smartsocket.plugins';
|
||||
import * as helpers from './smartsocket.helpers';
|
||||
|
||||
import { Objectmap } from 'lik';
|
||||
import { Objectmap } from '@pushrocks/lik';
|
||||
|
||||
// import classes
|
||||
import { Smartsocket } from './smartsocket.classes.smartsocket';
|
||||
@@ -68,7 +68,8 @@ export class SocketConnection {
|
||||
// standard behaviour that is always true
|
||||
allSocketConnections.add(this);
|
||||
this.socket.on('disconnect', () => {
|
||||
plugins.beautylog.info(
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`SocketConnection with >alias ${this.alias} on >side ${this.side} disconnected`
|
||||
);
|
||||
this.socket.disconnect();
|
||||
@@ -82,9 +83,12 @@ export class SocketConnection {
|
||||
* authenticate the socket
|
||||
*/
|
||||
authenticate() {
|
||||
let done = plugins.smartq.defer();
|
||||
let done = plugins.smartpromise.defer();
|
||||
this.socket.on('dataAuth', (dataArg: ISocketConnectionAuthenticationObject) => {
|
||||
plugins.beautylog.log('received authentication data. now hashing and comparing...');
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
'received authentication data. now hashing and comparing...'
|
||||
);
|
||||
this.socket.removeListener('dataAuth', () => {});
|
||||
if (helpers.checkPasswordForRole(dataArg, this.smartsocketHost)) {
|
||||
// TODO: authenticate password
|
||||
@@ -92,7 +96,8 @@ export class SocketConnection {
|
||||
this.authenticated = true;
|
||||
this.role = helpers.getSocketRoleByName(dataArg.role, this.smartsocketHost);
|
||||
this.socket.emit('authenticated');
|
||||
plugins.beautylog.ok(
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'ok',
|
||||
`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`
|
||||
);
|
||||
done.resolve(this);
|
||||
@@ -112,18 +117,18 @@ export class SocketConnection {
|
||||
* listen to function requests
|
||||
*/
|
||||
listenToFunctionRequests() {
|
||||
let done = plugins.smartq.defer();
|
||||
let done = plugins.smartpromise.defer();
|
||||
if (this.authenticated) {
|
||||
this.socket.on('function', (dataArg: ISocketRequestDataObject) => {
|
||||
// check if requested function is available to the socket's scope
|
||||
plugins.beautylog.log('function request received');
|
||||
plugins.smartlog.defaultLogger.log('info', 'function request received');
|
||||
let referencedFunction: SocketFunction = this.role.allowedFunctions.find(
|
||||
socketFunctionArg => {
|
||||
return socketFunctionArg.name === dataArg.funcCallData.funcName;
|
||||
}
|
||||
);
|
||||
if (referencedFunction !== undefined) {
|
||||
plugins.beautylog.ok!('function in access scope');
|
||||
plugins.smartlog.defaultLogger.log('ok', 'function in access scope');
|
||||
let localSocketRequest = new SocketRequest({
|
||||
side: 'responding',
|
||||
originSocketConnection: this,
|
||||
@@ -132,19 +137,28 @@ export class SocketConnection {
|
||||
});
|
||||
localSocketRequest.createResponse(); // takes care of creating response and sending it back
|
||||
} else {
|
||||
plugins.beautylog.warn('function not existent or out of access scope');
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'warn',
|
||||
'function not existent or out of access scope'
|
||||
);
|
||||
}
|
||||
});
|
||||
this.socket.on('functionResponse', (dataArg: ISocketRequestDataObject) => {
|
||||
plugins.beautylog.info(`received response for request with id ${dataArg.shortId}`);
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`received response for request with id ${dataArg.shortId}`
|
||||
);
|
||||
let targetSocketRequest = helpers.getSocketRequestById(dataArg.shortId);
|
||||
targetSocketRequest.handleResponse(dataArg);
|
||||
});
|
||||
plugins.beautylog.log(`now listening to function requests for ${this.alias}`);
|
||||
plugins.smartlog.defaultLogger.log(
|
||||
'info',
|
||||
`now listening to function requests for ${this.alias}`
|
||||
);
|
||||
done.resolve(this);
|
||||
} else {
|
||||
let errMessage: 'socket needs to be authenticated first';
|
||||
plugins.beautylog.error(errMessage);
|
||||
plugins.smartlog.defaultLogger.log('error', errMessage);
|
||||
done.reject(errMessage);
|
||||
}
|
||||
return done.promise;
|
||||
|
||||
Reference in New Issue
Block a user