move to typescript predominance
This commit is contained in:
4
ts/smartuniverse.classes.channelbridge.ts
Normal file
4
ts/smartuniverse.classes.channelbridge.ts
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* This file contains logic to bridge certain messages into another channel
|
||||
*/
|
||||
export class ChannelBridge {}
|
@ -1,7 +1,20 @@
|
||||
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) {}
|
||||
}
|
||||
|
@ -3,8 +3,10 @@ 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';
|
||||
|
||||
import * as paths from './smartuniverse.paths';
|
||||
|
||||
export interface ISmartUniverseConstructorOptions {
|
||||
@ -60,16 +62,7 @@ export class Universe {
|
||||
port: portArg
|
||||
});
|
||||
|
||||
this.smartsocket = new plugins.smartsocket.Smartsocket({
|
||||
port: 12345 // fix this within smartsocket
|
||||
});
|
||||
|
||||
this.smartsocket.setExternalServer(
|
||||
'express',
|
||||
this.smartexpressServer as any); // should work with express as well
|
||||
this.smartsocket.start();
|
||||
|
||||
// route handling
|
||||
// message handling
|
||||
// adds messages
|
||||
const addMessageHandler = new Handler('PUT', request => {
|
||||
const requestBody = request.body;
|
||||
@ -80,14 +73,31 @@ export class Universe {
|
||||
|
||||
// gets messages
|
||||
const readMessageHandler = new Handler('GET', request => {
|
||||
const done = plugins.smartq.defer<UniverseMessage[]>();
|
||||
const requestBody = request.body;
|
||||
this.universeStore.readMessagesYoungerThan(requestBody.since);
|
||||
const messageObservable = this.universeStore.readMessagesYoungerThan(requestBody.since);
|
||||
messageObservable.toArray().subscribe(universeMessageArrayArg => {
|
||||
done.resolve(universeMessageArrayArg);
|
||||
});
|
||||
return done.promise;
|
||||
});
|
||||
|
||||
// create new Route for messages
|
||||
const messageRoute = new Route(this.smartexpressServer, 'message');
|
||||
messageRoute.addHandler(addMessageHandler);
|
||||
messageRoute.addHandler(readMessageHandler);
|
||||
|
||||
const leaderElectionRoute = new Route(this.smartexpressServer, 'leadelection');
|
||||
// TODO: implement Handlers for leader election
|
||||
|
||||
// add websocket upgrade
|
||||
this.smartsocket = new plugins.smartsocket.Smartsocket({
|
||||
port: 12345 // fix this within smartsocket
|
||||
});
|
||||
|
||||
this.smartsocket.setExternalServer('express', this.smartexpressServer as any); // should work with express as well
|
||||
this.smartsocket.start();
|
||||
|
||||
await this.smartexpressServer.start();
|
||||
}
|
||||
|
||||
|
17
ts/smartuniverse.classes.universechannel.ts
Normal file
17
ts/smartuniverse.classes.universechannel.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
/**
|
||||
* enables a set of apps to talk within their own limited borders.
|
||||
*/
|
||||
export class UniverseChannel {
|
||||
topic: string;
|
||||
credentials: {
|
||||
user: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* authenticates a client on the server side
|
||||
*/
|
||||
async authenticateClient() {}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { Smartsocket, SmartsocketClient } from 'smartsocket';
|
||||
import * as url from 'url';
|
||||
@ -15,6 +14,10 @@ export interface IClientOptions {
|
||||
serverAddress: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* this class is for client side only!!!
|
||||
* allows connecting to a universe server
|
||||
*/
|
||||
export class UniverseClient {
|
||||
public options;
|
||||
private socketClient: plugins.smartsocket.SmartsocketClient;
|
||||
@ -29,11 +32,12 @@ export class UniverseClient {
|
||||
message: messageArg,
|
||||
payload: payloadArg
|
||||
};
|
||||
// TODO: User websocket connection if available
|
||||
await plugins.smartrequest.post(this.options.serverAddress, {
|
||||
requestBody
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public getMessageObservable() {
|
||||
if (!this.socketClient && !this.observableIntake) {
|
||||
const parsedURL = url.parse(this.options.serverAddress);
|
||||
@ -42,7 +46,7 @@ export class UniverseClient {
|
||||
password: 'UniverseClient',
|
||||
port: parseInt(parsedURL.port, 10),
|
||||
role: 'UniverseClient',
|
||||
url: parsedURL.hostname,
|
||||
url: parsedURL.hostname
|
||||
});
|
||||
this.observableIntake = new plugins.smartrx.ObservableIntake();
|
||||
this.socketClient.connect();
|
||||
@ -50,7 +54,7 @@ export class UniverseClient {
|
||||
return this.observableIntake.observable;
|
||||
}
|
||||
|
||||
public close () {
|
||||
public close() {
|
||||
this.socketClient.disconnect();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ import * as plugins from './smartuniverse.plugins';
|
||||
import { Timer, TimeStamp } from 'smarttime';
|
||||
import { UniverseStore } from './smartuniverse.classes.universestore';
|
||||
|
||||
/**
|
||||
* represents a message within a universe
|
||||
*/
|
||||
export class UniverseMessage {
|
||||
/**
|
||||
* public and unique id
|
||||
|
@ -3,6 +3,7 @@ import * as path from 'path';
|
||||
import * as smartcli from 'smartcli';
|
||||
import * as smartexpress from 'smartexpress';
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smartq from 'smartq';
|
||||
import * as smartrequest from 'smartrequest';
|
||||
import * as smartrx from 'smartrx';
|
||||
import * as smartsocket from 'smartsocket';
|
||||
@ -14,6 +15,7 @@ export {
|
||||
smartcli,
|
||||
smartexpress,
|
||||
smartfile,
|
||||
smartq,
|
||||
smartrx,
|
||||
smartrequest,
|
||||
smartsocket,
|
||||
|
Reference in New Issue
Block a user