fixing io.sockets and starter to wait for the dispatcher to be ready

This commit is contained in:
martin 2020-11-11 18:24:21 +01:00
parent e93e50c43c
commit 2591e2cbfb
3 changed files with 18 additions and 7 deletions

View File

@ -42,7 +42,7 @@ const main = async function () {
'event': [],
'amqp': ['localhost'],
'io-server': [7000],
'io-client': ['localhost:7000']
'io-client': ['http://localhost:7000']
}
let opts: {
@ -126,9 +126,6 @@ const main = async function () {
await dispatcher.ready.waitFor(value => value);
const sleep = promisify(setTimeout);
await sleep(1000);
// Try to load the Modules.
try {
await loadPackages(getPackageLoader(dispatcher), args.file)

View File

@ -7,16 +7,18 @@
*/
import { connect, Socket } from 'socket.io-client';
import { getCentralNopeLogger } from "../logger/getLogger";
import { getCentralNopeLogger, getNopeLogger } from "../logger/getLogger";
import { NopeObservable } from '../observables/nopeObservable';
import { IAvailableInstanceGeneratorsMsg, IAvailableServicesMsg, IAvailableTopicsMsg, ICommunicationInterface, IExternalEventMsg, IRequestTaskMsg, IResponseTaskMsg, ITaskCancelationMsg } from "../types/nope/nopeCommunication.interface";
import { INopeObservable } from '../types/nope/nopeObservable.interface';
import { Logger } from "winston";
export class IoSocketClient implements ICommunicationInterface {
connected: INopeObservable<boolean>;
protected _emitter: typeof Socket;
protected _logger: Logger;
constructor(public uri: string) {
const _this = this;
@ -24,15 +26,25 @@ export class IoSocketClient implements ICommunicationInterface {
this.connected = new NopeObservable();
this.connected.setContent(false);
// Make shure we use the http before connecting.
this.uri = this.uri.startsWith('http://') ? this.uri : 'http://' + this.uri;
// Create a Logger
this._logger = getNopeLogger('io-socket-client');
this._logger.info('connecting to: ' + uri);
this._emitter = connect(uri);
this._emitter.on('connect', (...args) => {
// Element is connected
_this._logger.info('connected');
_this.connected.setContent(true);
});
this._emitter.on('disconnect', () => {
// Connection Lost.
_this._logger.error('Connection lost!');
_this.connected.setContent(false);
})
});
}
async onTaskCancelation(cb: (msg: ITaskCancelationMsg) => void) {

View File

@ -41,7 +41,8 @@ export class IoSocketSeverEventEmitter {
this.connected = new NopeObservable();
this.connected.setContent(false);
this._logger = getNopeLogger('io-socket');
this._logger = getNopeLogger('io-socket-server');
this._logger.info('waiting for connection. Listening on port: ' + port.toString());
this._socket.listen(port);
@ -60,6 +61,7 @@ export class IoSocketSeverEventEmitter {
if (_this._sockets.size === 0){
_this.connected.setContent(false);
_this._logger.warn('All Connections lost');
}
});