fix(core): update

This commit is contained in:
2019-09-01 17:04:25 +02:00
parent e8f09c1b7a
commit 52db86c929
11 changed files with 60 additions and 28 deletions

View File

@@ -5,7 +5,7 @@ export interface IMessageCreator {
}
/**
*
*
*/
export interface IUniverseMessage extends IMessageCreator {
id: string;

View File

@@ -40,7 +40,11 @@ export class ClientUniverse {
}
// lets create the channel
const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(
this,
channelNameArg,
passphraseArg
);
return clientUniverseChannel;
}
@@ -61,9 +65,11 @@ export class ClientUniverse {
* @param messageArg
*/
public removeChannel(channelNameArg, notifyServer = true) {
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemove(channelItemArg => {
return channelItemArg.name === channelNameArg;
});
const clientUniverseChannel = this.clientUniverseCache.channelMap.findOneAndRemove(
channelItemArg => {
return channelItemArg.name === channelNameArg;
}
);
}
public async start() {
@@ -112,7 +118,9 @@ export class ClientUniverse {
allowedRoles: [],
funcDef: async (messageDescriptorArg: interfaces.IUniverseMessage) => {
plugins.smartlog.defaultLogger.log('info', 'Got message from server');
this.observableIntake.push(ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg));
this.observableIntake.push(
ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg)
);
}
});

View File

@@ -54,7 +54,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
name: this.name,
passphrase: this.passphrase
};
await this.clientUniverseRef.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
await this.clientUniverseRef.smartsocketClient.serverCall(
serverCallActionName,
serverCallActionPayload
);
}
/**
@@ -72,6 +75,9 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
payload: messageArg.payload,
payloadStringType: messageArg.payloadStringType
};
await this.clientUniverseRef.smartsocketClient.serverCall('processMessage', universeMessageToSend);
await this.clientUniverseRef.smartsocketClient.serverCall(
'processMessage',
universeMessageToSend
);
}
}

View File

@@ -126,14 +126,23 @@ export class Universe {
socketConnectionArg
);
if (universeConnection) {
plugins.smartlog.defaultLogger.log('ok', 'found UniverseConnection for socket for incoming message');
plugins.smartlog.defaultLogger.log(
'ok',
'found UniverseConnection for socket for incoming message'
);
} else {
plugins.smartlog.defaultLogger.log('warn', 'found no Authorized channel for incoming message');
plugins.smartlog.defaultLogger.log(
'warn',
'found no Authorized channel for incoming message'
);
return {
error: 'You need to authenticate for a channel'
};
}
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(socketConnectionArg, dataArg);
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(
socketConnectionArg,
dataArg
);
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
this.universeCache,
unauthenticatedMessage

View File

@@ -121,7 +121,8 @@ export class UniverseChannel {
}
});
for (const universeConnection of universeConnectionsWithChannelAccess) {
const smartsocket = universeConnection.socketConnection.smartsocketRef as plugins.smartsocket.Smartsocket;
const smartsocket = universeConnection.socketConnection
.smartsocketRef as plugins.smartsocket.Smartsocket;
const universeMessageToSend: interfaces.IUniverseMessage = {
id: messageArg.id,
timestamp: messageArg.timestamp,
@@ -131,7 +132,11 @@ export class UniverseChannel {
payload: messageArg.payload,
payloadStringType: messageArg.payloadStringType
};
smartsocket.clientCall('processMessage', universeMessageToSend, universeConnection.socketConnection);
smartsocket.clientCall(
'processMessage',
universeMessageToSend,
universeConnection.socketConnection
);
}
}
}

View File

@@ -58,7 +58,10 @@ export class UniverseConnection {
universeConnectionArg: UniverseConnection
): Promise<UniverseConnection> {
for (const authenticationRequest of universeConnectionArg.authenticationRequests) {
const universeChannelToAuthenticateAgainst = UniverseChannel.getUniverseChannelByName(universeRef, authenticationRequest.name);
const universeChannelToAuthenticateAgainst = UniverseChannel.getUniverseChannelByName(
universeRef,
authenticationRequest.name
);
if (universeChannelToAuthenticateAgainst.passphrase === authenticationRequest.passphrase) {
universeConnectionArg.authenticatedChannels.push(universeChannelToAuthenticateAgainst);
}

View File

@@ -14,7 +14,10 @@ import { SocketConnection } from '@pushrocks/smartsocket';
* acts as a container to save message states like authentication status
*/
export class UniverseMessage implements interfaces.IUniverseMessage {
public static createMessageFromPayload(socketConnectionArg: SocketConnection, dataArg: interfaces.IUniverseMessage) {
public static createMessageFromPayload(
socketConnectionArg: SocketConnection,
dataArg: interfaces.IUniverseMessage
) {
const universeMessageInstance = new UniverseMessage(dataArg);
universeMessageInstance.socketConnection = socketConnectionArg;
return universeMessageInstance;
@@ -69,9 +72,7 @@ export class UniverseMessage implements interfaces.IUniverseMessage {
this.universeCache = universeCacheArg;
}
public setTargetChannel() {
}
public setTargetChannel() {}
public setDestructionTimer(selfdestructAfterArg: number) {
if (selfdestructAfterArg) {