fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-01 16:54:36 +02:00
parent 9c1504ef02
commit ef61ea9ad7

View File

@ -10,6 +10,7 @@ import { UniverseConnection } from './smartuniverse.classes.universeconnection';
export interface ISmartUniverseConstructorOptions { export interface ISmartUniverseConstructorOptions {
messageExpiryInMilliseconds: number; messageExpiryInMilliseconds: number;
externalServer?: plugins.smartexpress.Server;
} }
/** /**
@ -68,6 +69,7 @@ export class Universe {
*/ */
public async start(portArg: number) { public async start(portArg: number) {
// lets create the base smartexpress server // lets create the base smartexpress server
if (!this.options.externalServer) {
this.smartexpressServer = new plugins.smartexpress.Server({ this.smartexpressServer = new plugins.smartexpress.Server({
cors: true, cors: true,
defaultAnswer: async () => { defaultAnswer: async () => {
@ -76,6 +78,9 @@ export class Universe {
forceSsl: false, forceSsl: false,
port: portArg port: portArg
}); });
} else {
this.smartexpressServer = this.options.externalServer;
}
// add websocket upgrade // add websocket upgrade
this.smartsocket = new plugins.smartsocket.Smartsocket({}); this.smartsocket = new plugins.smartsocket.Smartsocket({});
@ -148,7 +153,9 @@ export class Universe {
// add smartsocket to the running smartexpress app // add smartsocket to the running smartexpress app
this.smartsocket.setExternalServer('smartexpress', this.smartexpressServer as any); this.smartsocket.setExternalServer('smartexpress', this.smartexpressServer as any);
// start everything // start everything
if (!this.options.externalServer) {
await this.smartexpressServer.start(); await this.smartexpressServer.start();
}
await this.smartsocket.start(); await this.smartsocket.start();
plugins.smartlog.defaultLogger.log('success', 'started universe'); plugins.smartlog.defaultLogger.log('success', 'started universe');
} }
@ -158,6 +165,8 @@ export class Universe {
*/ */
public async stopServer() { public async stopServer() {
await this.smartsocket.stop(); await this.smartsocket.stop();
if (!this.options.externalServer) {
await this.smartexpressServer.stop(); await this.smartexpressServer.stop();
} }
} }
}