smartuniverse/ts/smartuniverse.classes.universeconnectionmanager.ts

49 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-04-30 17:16:03 +00:00
import * as plugins from './smartuniverse.plugins';
2019-06-06 20:22:45 +00:00
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
2019-04-30 17:16:03 +00:00
/**
* manages connections to a universe
*/
export class UniverseConnectionManager {
2019-06-06 20:22:45 +00:00
public connectionMap = new plugins.lik.Objectmap<UniverseConnection>();
2019-04-30 17:16:03 +00:00
2019-06-07 09:49:10 +00:00
public async addConnection(universeConnectionArg: UniverseConnection) {
let universeConnection = universeConnectionArg;
universeConnection = await this.deduplicateUniverseConnection(universeConnection);
2019-06-10 15:46:06 +00:00
universeConnection = await this.authenticateAuthenticationRequests(universeConnection);
2019-06-07 09:49:10 +00:00
}
/**
* deduplicates UniverseConnections
*/
2019-06-10 15:46:06 +00:00
public async deduplicateUniverseConnection (universeConnectionArg: UniverseConnection): Promise<UniverseConnection> {
let connectionToReturn: UniverseConnection;
this.connectionMap.forEach(async existingConnection => {
if (existingConnection.socketConnection = universeConnectionArg.socketConnection) {
connectionToReturn = await this.mergeUniverseConnections(existingConnection, universeConnectionArg);
}
});
if (!connectionToReturn) {
connectionToReturn = universeConnectionArg;
}
return connectionToReturn;
2019-06-07 09:49:10 +00:00
}
/**
* authenticate AuthenticationRequests
*/
2019-06-10 15:46:06 +00:00
public authenticateAuthenticationRequests(universeConnectionArg): Promise<UniverseConnection> {
// TODO: authenticate connections
return universeConnectionArg;
}
2019-06-07 09:49:10 +00:00
2019-06-10 15:46:06 +00:00
/**
* merges two UniverseConnections
*/
public mergeUniverseConnections (connectionArg1: UniverseConnection, connectionArg2: UniverseConnection) {
// TODO: merge connections
return connectionArg1;
2019-06-07 09:49:10 +00:00
}
2019-06-06 21:23:37 +00:00
}