fix(core): prepare for release
This commit is contained in:
parent
a17834a8f0
commit
5a4dceb75d
@ -17,8 +17,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"lik": "^2.0.5",
|
||||
"nodehash": "^1.0.4",
|
||||
"rxjs": "^5.5.8",
|
||||
"smartcli": "^2.0.12",
|
||||
"smartdelay": "^1.0.4",
|
||||
"smartexpress": "^1.0.21",
|
||||
"smartfile": "^4.2.28",
|
||||
"smartq": "^1.1.8",
|
||||
|
@ -1,20 +0,0 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Objectmap } from 'lik';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
|
||||
export class UniverseManager {
|
||||
public channelStore = new Objectmap<UniverseChannel>();
|
||||
|
||||
/**
|
||||
* register a new member
|
||||
*/
|
||||
public async registerMember() {}
|
||||
|
||||
/**
|
||||
* register a new channel within the universe
|
||||
* @param channelName the name of the channel
|
||||
* @param authSecret the secret against which to verify members of the channel
|
||||
*/
|
||||
public async registerChannel(channelName: string, authSecret: string) {}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { Handler, Route, Server } from 'smartexpress';
|
||||
|
||||
import { UniverseManager } from './smartuniverse.classes.manager';
|
||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||
import { UniverseStore } from './smartuniverse.classes.universestore';
|
||||
@ -20,6 +18,8 @@ export interface IServerGetMessagesRequestBody {
|
||||
}
|
||||
|
||||
export interface IServerPutMessageRequestBody {
|
||||
channel: string;
|
||||
passphrase: string;
|
||||
message: string;
|
||||
payload: any;
|
||||
}
|
||||
@ -27,7 +27,6 @@ export interface IServerPutMessageRequestBody {
|
||||
export class Universe {
|
||||
// subinstances
|
||||
public universeStore: UniverseStore;
|
||||
public universeManager: UniverseManager;
|
||||
|
||||
// options
|
||||
private options: ISmartUniverseConstructorOptions;
|
||||
@ -50,7 +49,6 @@ export class Universe {
|
||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
this.universeStore = new UniverseStore(this.options.messageExpiryInMilliseconds);
|
||||
this.universeManager = new UniverseManager();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,8 +65,13 @@ export class Universe {
|
||||
// message handling
|
||||
// adds messages
|
||||
const addMessageHandler = new Handler('PUT', request => {
|
||||
const requestBody = request.body;
|
||||
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
||||
const requestBody: IServerPutMessageRequestBody = request.body;
|
||||
const message = new UniverseMessage(
|
||||
requestBody.message,
|
||||
requestBody.payload,
|
||||
|
||||
)
|
||||
this.universeStore.addMessage(message);
|
||||
console.log(requestBody);
|
||||
return true;
|
||||
});
|
||||
|
@ -11,25 +11,36 @@ export class UniverseChannel {
|
||||
*/
|
||||
public static channelStore = new Objectmap();
|
||||
|
||||
/**
|
||||
* the credentials for the channel
|
||||
*/
|
||||
private credentials: {
|
||||
user: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* creates new channels
|
||||
* @param channelArg the name of the topic
|
||||
* @param secretArg the secret thats used for a certain topic.
|
||||
* @param passphraseArg the secret thats used for a certain topic.
|
||||
*/
|
||||
public static createChannel = (channelArg: string, secretArg: string) => {
|
||||
public static createChannel = (channelNameArg: string, passphraseArg: string) => {
|
||||
const newChannel = new UniverseChannel(channelNameArg, passphraseArg);
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* the name of the channel
|
||||
*/
|
||||
public name: string;
|
||||
|
||||
/**
|
||||
* the passphrase for the channel
|
||||
*/
|
||||
public passphrase: string;
|
||||
|
||||
constructor(channelNameArg: string, passphraseArg: string) {
|
||||
this.name = channelNameArg;
|
||||
this.passphrase = passphraseArg;
|
||||
UniverseChannel.channelStore.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* authenticates a client on the server side
|
||||
*/
|
||||
async authenticateClient() {}
|
||||
public async authenticateClient(passphraseArg: string): boolean {
|
||||
return passphraseArg === this.passphrase;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ export class UniverseMessage {
|
||||
* the universe store the message is attached to
|
||||
*/
|
||||
public universeStore: UniverseStore;
|
||||
/**
|
||||
* enables unprotected grouping of messages for efficiency purposes.
|
||||
*/
|
||||
public universeChannel: string;
|
||||
|
||||
/**
|
||||
* time of creation
|
||||
@ -26,30 +30,37 @@ export class UniverseMessage {
|
||||
public timestamp: TimeStamp;
|
||||
|
||||
/**
|
||||
* enables unprotected grouping of messages for efficiency purposes.
|
||||
* the actual message
|
||||
*/
|
||||
public universeChannel: string;
|
||||
public message: string; // the actual message
|
||||
public attachedPayload: any; // any attached payloads. Can be of binary format.
|
||||
public message: string;
|
||||
|
||||
/**
|
||||
* any attached payloads. Can be of binary format.
|
||||
*/
|
||||
public attachedPayload: any;
|
||||
public destructionTimer: Timer; // a timer to take care of message destruction
|
||||
|
||||
/**
|
||||
* the constructor to create a universe message
|
||||
* @param parentUniverseStore
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
* @param selfdestructAfterArg
|
||||
*/
|
||||
constructor(
|
||||
parentUniverseStore: UniverseStore,
|
||||
messageArg: string,
|
||||
attachedPayloadArg: any,
|
||||
selfdestructAfterArg: number
|
||||
attachedPayloadArg: any
|
||||
) {
|
||||
this.universeStore = parentUniverseStore;
|
||||
this.timestamp = new TimeStamp();
|
||||
this.message = messageArg;
|
||||
this.attachedPayload = attachedPayloadArg;
|
||||
this.fallBackDestruction();
|
||||
}
|
||||
|
||||
public setUniverseStore (universeStoreArg: UniverseStore) {
|
||||
this.universeStore = universeStoreArg;
|
||||
}
|
||||
|
||||
public setDestructionTimer (selfdestructAfterArg: number) {
|
||||
if (selfdestructAfterArg) {
|
||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||
this.destructionTimer.start();
|
||||
|
||||
@ -57,5 +68,20 @@ export class UniverseMessage {
|
||||
this.destructionTimer.completed.then(async () => {
|
||||
this.universeStore.messageStore.remove(this);
|
||||
});
|
||||
} else {
|
||||
this.fallBackDestruction();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* prevents memory leaks if channels have no default
|
||||
*/
|
||||
private fallBackDestruction () {
|
||||
plugins.smartdelay.delayFor(1000).then(() => {
|
||||
if (!this.destructionTimer) {
|
||||
this.setDestructionTimer(6000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,8 @@ export class UniverseStore {
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
*/
|
||||
public addMessage(messageArg, attachedPayloadArg) {
|
||||
this.messageStore.add(
|
||||
new UniverseMessage(this, messageArg, attachedPayloadArg, this.destructionTime)
|
||||
);
|
||||
public addMessage(messageArg: UniverseMessage) {
|
||||
this.messageStore.add(messageArg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,8 @@
|
||||
import * as lik from 'lik';
|
||||
import * as nodehash from 'nodehash';
|
||||
import * as path from 'path';
|
||||
import * as smartcli from 'smartcli';
|
||||
import * as smartdelay from 'smartdelay';
|
||||
import * as smartexpress from 'smartexpress';
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smartq from 'smartq';
|
||||
@ -11,8 +13,10 @@ import * as smarttime from 'smarttime';
|
||||
|
||||
export {
|
||||
lik,
|
||||
nodehash,
|
||||
path,
|
||||
smartcli,
|
||||
smartdelay,
|
||||
smartexpress,
|
||||
smartfile,
|
||||
smartq,
|
||||
|
Loading…
x
Reference in New Issue
Block a user