fix(core): update

This commit is contained in:
2019-04-08 19:42:23 +02:00
parent 431179f10d
commit c28b25883e
5 changed files with 360 additions and 66 deletions

View File

@ -1,3 +1,60 @@
import * as plugins from './smartipc.plugins';
export let standardExport = 'Hi there! :) This is an exported string';
export interface ISmartIpcConstructorOptions {
type: 'server' | 'client';
/**
* the name of the message string
*/
ipcSpace: string;
}
export interface ISmartIpcHandlerPackage {
keyword: string;
handlerFunc: () => void;
}
export class SmartIpc {
public handlers: ISmartIpcHandlerPackage[] = [];
public options: ISmartIpcConstructorOptions;
constructor(optionsArg: ISmartIpcConstructorOptions) {
this.options = optionsArg;
}
/**
* connect to the channel
*/
public async start() {
switch (this.options.type) {
case 'server':
plugins.nodeIpc.config.id = this.options.ipcSpace;
const done = plugins.smartpromise.defer();
plugins.nodeIpc.serve(() => {
done.resolve();
});
await done.promise;
break;
case 'client':
plugins.nodeIpc.connectTo(this.options.ipcSpace);
default:
throw new Error('type of ipc is not valid. Must be "server" or "client"');
}
}
/**
* should stop the server
*/
public async stop() {
plugins.nodeIpc.server.stop();
}
/**
* regsiters a handler
*/
registerHandler (handlerPackage: ISmartIpcHandlerPackage) {
this.handlers.push(handlerPackage);
}
}

View File

@ -1,4 +1,16 @@
const removeme = {};
// pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrx from '@pushrocks/smartrx';
export {
removeme
}
smartpromise,
smartrx
};
// third party scope
import * as nodeIpc from 'node-ipc';
export {
nodeIpc
};