fix(core): update
This commit is contained in:
parent
f512acdfaa
commit
f728c56016
@ -7,4 +7,5 @@ export * from './smartuniverse.classes.universe';
|
||||
export * from './smartuniverse.classes.universecache';
|
||||
export * from './smartuniverse.classes.universechannel';
|
||||
export * from './smartuniverse.classes.universemessage';
|
||||
export * from './smartuniverse.interfaces';
|
||||
|
||||
export * from './interfaces';
|
||||
|
15
ts/interfaces/http.interfaces.ts
Normal file
15
ts/interfaces/http.interfaces.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export interface IServerGetMessagesRequestBody {
|
||||
channel: string;
|
||||
topic?: string;
|
||||
youngerThan: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* the interface for a standard request
|
||||
*/
|
||||
export interface IServerPutMessageRequestBody {
|
||||
channel: string;
|
||||
passphrase: string;
|
||||
message: string;
|
||||
payload: any;
|
||||
}
|
3
ts/interfaces/index.ts
Normal file
3
ts/interfaces/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './http.interfaces';
|
||||
export * from './universechannel.interfaces';
|
||||
export * from './universemessage.interfaces';
|
1
ts/interfaces/universechannel.interfaces.ts
Normal file
1
ts/interfaces/universechannel.interfaces.ts
Normal file
@ -0,0 +1 @@
|
||||
export interface IUniverseChannel {}
|
1
ts/interfaces/universemessage.interfaces.ts
Normal file
1
ts/interfaces/universemessage.interfaces.ts
Normal file
@ -0,0 +1 @@
|
||||
export interface IUniverseMessage {}
|
@ -5,10 +5,10 @@ import { Observable } from 'rxjs';
|
||||
import { Smartsocket, SmartsocketClient } from '@pushrocks/smartsocket';
|
||||
import * as url from 'url';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
import {
|
||||
ClientUniverseChannel,
|
||||
IServerGetMessagesRequestBody,
|
||||
IServerPutMessageRequestBody,
|
||||
UniverseMessage
|
||||
} from './';
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
import { ClientUniverse, IUniverseChannel } from './';
|
||||
import { ClientUniverse } from './';
|
||||
|
||||
export class ClientUniverseChannel implements IUniverseChannel {
|
||||
export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
|
@ -1,15 +1,21 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
import { IUniverseMessage } from './';
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
export class ClientUniverseMessage implements IUniverseMessage {
|
||||
export class ClientUniverseMessage implements interfaces.IUniverseMessage {
|
||||
// ======
|
||||
// STATIC
|
||||
// ======
|
||||
createMessage(messageArg: string, payloadArg: any) {}
|
||||
public static createMessageFromPayload(messageArg: string, payloadArg: any) {
|
||||
|
||||
};
|
||||
|
||||
// ========
|
||||
// INSTANCE
|
||||
// ========
|
||||
constructor(messageArg, payloadArg) {}
|
||||
|
||||
getAsJsonForPayload () {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,25 +5,13 @@ import { UniverseCache, UniverseChannel, UniverseMessage } from './';
|
||||
|
||||
import * as paths from './smartuniverse.paths';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
|
||||
export interface ISmartUniverseConstructorOptions {
|
||||
messageExpiryInMilliseconds: number;
|
||||
}
|
||||
|
||||
export interface IServerGetMessagesRequestBody {
|
||||
channel: string;
|
||||
topic?: string;
|
||||
youngerThan: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* the interface for a standard request
|
||||
*/
|
||||
export interface IServerPutMessageRequestBody {
|
||||
channel: string;
|
||||
passphrase: string;
|
||||
message: string;
|
||||
payload: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* main class that setsup a Universe
|
||||
@ -35,9 +23,16 @@ export class Universe {
|
||||
// options
|
||||
private options: ISmartUniverseConstructorOptions;
|
||||
|
||||
// Store version handling
|
||||
/**
|
||||
* stores the version of the universe server running
|
||||
* this is done since the version is exposed through the api and multiple fs actions are avoided this way.
|
||||
*/
|
||||
private universeVersionStore: string;
|
||||
private get universeVersion() {
|
||||
|
||||
/**
|
||||
* get the currently running version of smartuniverse
|
||||
*/
|
||||
public get universeVersion() {
|
||||
if (this.universeVersionStore) {
|
||||
return this.universeVersionStore;
|
||||
} else {
|
||||
@ -47,7 +42,14 @@ export class Universe {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the smartexpress server used
|
||||
*/
|
||||
private smartexpressServer: plugins.smartexpress.Server;
|
||||
|
||||
/**
|
||||
* the smartsocket used
|
||||
*/
|
||||
private smartsocket: plugins.smartsocket.Smartsocket;
|
||||
|
||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||
@ -59,14 +61,14 @@ export class Universe {
|
||||
* adds a channel to the Universe
|
||||
*/
|
||||
public async addChannel(nameArg: string, passphraseArg: string) {
|
||||
const newChannel = new UniverseChannel(this.universeCache, nameArg, passphraseArg);
|
||||
this.universeCache.channelMap.add(newChannel);
|
||||
const newChannel = UniverseChannel.createChannel(this.universeCache, nameArg, passphraseArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* initiates a server
|
||||
*/
|
||||
public async initServer(portArg: number | string) {
|
||||
// lets create the base smartexpress server
|
||||
this.smartexpressServer = new plugins.smartexpress.Server({
|
||||
cors: true,
|
||||
defaultAnswer: async () => {
|
||||
@ -76,31 +78,44 @@ export class Universe {
|
||||
port: portArg
|
||||
});
|
||||
|
||||
// lets create the http request route
|
||||
this.smartexpressServer.addRoute('/sendmessage', new Handler('POST', async (req, res) => {
|
||||
this.universeCache.addMessage(req.body);
|
||||
}));
|
||||
|
||||
// add websocket upgrade
|
||||
this.smartsocket = new plugins.smartsocket.Smartsocket({
|
||||
port: 12345 // fix this within smartsocket
|
||||
});
|
||||
|
||||
// add a role for the clients
|
||||
const ClientRole = new plugins.smartsocket.SocketRole({
|
||||
name: 'clientuniverse',
|
||||
passwordHash: 'clientuniverse' // authentication happens on another level
|
||||
});
|
||||
|
||||
// add the role to smartsocket
|
||||
this.smartsocket.addSocketRoles([ClientRole]);
|
||||
|
||||
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||
allowedRoles: [ClientRole],
|
||||
funcName: 'channelSubscription',
|
||||
funcDef: () => {}
|
||||
funcDef: () => {} // TODO: implement an action upon connection of clients
|
||||
});
|
||||
|
||||
// add smartsocket to the running smartexpress app
|
||||
this.smartsocket.setExternalServer('express', this.smartexpressServer as any);
|
||||
// should work with express as well
|
||||
|
||||
// start the socket
|
||||
this.smartsocket.start();
|
||||
|
||||
// start the smartexpress instance
|
||||
await this.smartexpressServer.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* stop everything
|
||||
*/
|
||||
public async stopServer() {
|
||||
await this.smartsocket.stop();
|
||||
await this.smartexpressServer.stop();
|
||||
|
@ -39,7 +39,7 @@ export class UniverseCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* add a message to the UniverseStore
|
||||
* add a message to the UniverseCache
|
||||
* @param messageArg
|
||||
* @param attachedPayloadArg
|
||||
*/
|
||||
@ -50,7 +50,7 @@ export class UniverseCache {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a message from the UniverseStore
|
||||
* Read a message from the UniverseCache
|
||||
*/
|
||||
public readMessagesYoungerThan(unixTimeArg?: number): Observable<UniverseMessage> {
|
||||
const messageObservable = from(this.messageMap.getArray()).pipe(
|
||||
|
@ -23,6 +23,7 @@ export class UniverseChannel {
|
||||
passphraseArg: string
|
||||
) {
|
||||
const newChannel = new UniverseChannel(universeCacheArg, channelNameArg, passphraseArg);
|
||||
universeCacheArg.channelMap.add(newChannel);
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
export interface IUniverseChannel {}
|
||||
|
||||
export interface IUniverseMessage {}
|
Loading…
x
Reference in New Issue
Block a user