Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
4761ff31cf | |||
430c3ea13a | |||
6dd3782b0d | |||
06aa721247 | |||
f728c56016 | |||
f512acdfaa | |||
331a098851 | |||
a8053a6e20 | |||
a62f3eb750 | |||
4b53044e8f | |||
2db2c80130 | |||
8b23eaf194 | |||
a03c54001f | |||
7bc404ba21 | |||
ac2a1559b0 | |||
57b37cb327 | |||
8b17e814cc | |||
f4b8cde347 |
@ -26,6 +26,7 @@ mirror:
|
|||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install -g snyk
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
@ -36,21 +37,11 @@ snyk:
|
|||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -62,6 +53,7 @@ testLTS:
|
|||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -117,8 +109,10 @@ pages:
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
@ -128,3 +122,4 @@ pages:
|
|||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
19
license
Normal file
19
license
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2018 Lossless GmbH (hello@lossless.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
@ -1,9 +1,17 @@
|
|||||||
{
|
{
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartuniverse",
|
||||||
|
"shortDescription": "messaging service for micro services",
|
||||||
|
"npmPackagename": "@pushrocks/smartuniverse",
|
||||||
|
"license": "MIT",
|
||||||
|
"projectDomain": "push.rocks"
|
||||||
|
}
|
||||||
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"@gitzone/npmts",
|
|
||||||
"ts-node"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
2983
package-lock.json
generated
2983
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@ -1,36 +1,38 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.23",
|
"version": "1.0.32",
|
||||||
"private": true,
|
"private": false,
|
||||||
"description": "messaging service for your micro services",
|
"description": "messaging service for your micro services",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(ts-node -O '{\"lib\": [ \"es2015\" ]}' test/test.ts)",
|
"test": "(tstest test/)",
|
||||||
"build": "(npmts)",
|
"build": "(tsbuild)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^9.6.18",
|
"@gitzone/tsbuild": "^2.1.8",
|
||||||
"tapbundle": "^2.0.0",
|
"@gitzone/tstest": "^1.0.20",
|
||||||
"ts-node": "^6.0.5",
|
"@pushrocks/tapbundle": "^3.0.9",
|
||||||
"typescript": "^2.8.3"
|
"@types/node": "^11.13.4",
|
||||||
|
"tslint": "^5.15.0",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"rxjs": "*"
|
"rxjs": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lik": "^2.0.5",
|
"@pushrocks/lik": "^3.0.5",
|
||||||
"nodehash": "^1.0.4",
|
"@pushrocks/smartdelay": "^2.0.3",
|
||||||
"smartdelay": "^1.0.4",
|
"@pushrocks/smartexpress": "^3.0.18",
|
||||||
"smartexpress": "^1.0.21",
|
"@pushrocks/smartfile": "^7.0.2",
|
||||||
"smartfile": "^4.2.28",
|
"@pushrocks/smarthash": "^2.0.4",
|
||||||
"smartq": "^1.1.8",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"smartrequest": "^1.0.8",
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
"smartrx": "^1.0.5",
|
"@pushrocks/smartrx": "^2.0.3",
|
||||||
"smartsocket": "^1.1.19",
|
"@pushrocks/smartsocket": "^1.1.27",
|
||||||
"smarttime": "^2.0.0"
|
"@pushrocks/smarttime": "^3.0.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
readme.md
41
readme.md
@ -1,33 +1,32 @@
|
|||||||
# smartuniverse
|
# @pushrocks/smartuniverse
|
||||||
|
messaging service for micro services
|
||||||
|
|
||||||
messaging service for your micro services
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
## Availabililty
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
||||||
[](https://GitLab.com/pushrocks/smartuniverse)
|
|
||||||
[](https://github.com/pushrocks/smartuniverse)
|
|
||||||
[](https://pushrocks.gitlab.io/smartuniverse/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/smartuniverse/commits/master)
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://GitLab.com/pushrocks/smartuniverse/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartuniverse/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartuniverse)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
[](https://snyk.io/test/npm/@pushrocks/smartuniverse)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](http://standardjs.com/)
|
[](https://prettier.io/)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
### What does smartuniverse all about?
|
||||||
|
|
||||||
> licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
Think WhatsApp, but for your microservices architecture. It allows your services to securely talk to each other in private, shielded channels without having to expose anything to the outside world. This allows the use of reactive programming across your entire stack.
|
||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
// tslint:disable-next-line:no-implicit-dependencies
|
||||||
import { expect, tap } from 'tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartuniverse from '../ts/index';
|
import * as smartuniverse from '../ts/index';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
@ -7,4 +7,5 @@ export * from './smartuniverse.classes.universe';
|
|||||||
export * from './smartuniverse.classes.universecache';
|
export * from './smartuniverse.classes.universecache';
|
||||||
export * from './smartuniverse.classes.universechannel';
|
export * from './smartuniverse.classes.universechannel';
|
||||||
export * from './smartuniverse.classes.universemessage';
|
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 {}
|
@ -1,14 +1,14 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
import { Objectmap } from 'lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { Smartsocket, SmartsocketClient } from 'smartsocket';
|
import { Smartsocket, SmartsocketClient } from '@pushrocks/smartsocket';
|
||||||
import * as url from 'url';
|
import * as url from 'url';
|
||||||
|
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ClientUniverseChannel,
|
ClientUniverseChannel,
|
||||||
IServerGetMessagesRequestBody,
|
|
||||||
IServerPutMessageRequestBody,
|
|
||||||
UniverseMessage
|
UniverseMessage
|
||||||
} from './';
|
} from './';
|
||||||
|
|
||||||
@ -32,17 +32,18 @@ export class ClientUniverse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async sendMessage(messageArg, payloadArg) {
|
public async sendMessage(messageArg, payloadArg) {
|
||||||
const requestBody = {
|
const requestBody: interfaces.IUniverseMessage = {
|
||||||
message: messageArg,
|
message: messageArg,
|
||||||
payload: payloadArg
|
payload: payloadArg
|
||||||
};
|
};
|
||||||
|
const requestBodyString = JSON.stringify(requestBody);
|
||||||
// TODO: User websocket connection if available
|
// TODO: User websocket connection if available
|
||||||
await plugins.smartrequest.post(this.options.serverAddress, {
|
const response = await plugins.smartrequest.postJson(`${this.options.serverAddress}/sendmessage` , {
|
||||||
requestBody
|
requestBody: requestBodyString
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getChannel(channelName: string): Promise<ClientUniverseChannel> {
|
public async getChannel(channelName: string, passphrase): Promise<ClientUniverseChannel> {
|
||||||
await this.checkConnection();
|
await this.checkConnection();
|
||||||
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
||||||
this,
|
this,
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
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
|
// STATIC
|
||||||
// ======
|
// ======
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
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
|
// STATIC
|
||||||
// ======
|
// ======
|
||||||
createMessage(messageArg: string, payloadArg: any) {}
|
public static createMessageFromPayload(messageArg: string, payloadArg: any) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// ========
|
// ========
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
// ========
|
// ========
|
||||||
constructor(messageArg, payloadArg) {}
|
constructor(messageArg, payloadArg) {}
|
||||||
|
|
||||||
|
getAsJsonForPayload () {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,17 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
import { Handler, Route, Server } from 'smartexpress';
|
import { Handler, Route, Server } from '@pushrocks/smartexpress';
|
||||||
import { UniverseCache, UniverseChannel, UniverseMessage } from './';
|
import { UniverseCache, UniverseChannel, UniverseMessage } from './';
|
||||||
|
|
||||||
import * as paths from './smartuniverse.paths';
|
import * as paths from './smartuniverse.paths';
|
||||||
|
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
export interface ISmartUniverseConstructorOptions {
|
export interface ISmartUniverseConstructorOptions {
|
||||||
messageExpiryInMilliseconds: number;
|
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
|
* main class that setsup a Universe
|
||||||
@ -35,9 +23,16 @@ export class Universe {
|
|||||||
// options
|
// options
|
||||||
private options: ISmartUniverseConstructorOptions;
|
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 universeVersionStore: string;
|
||||||
private get universeVersion() {
|
|
||||||
|
/**
|
||||||
|
* get the currently running version of smartuniverse
|
||||||
|
*/
|
||||||
|
public get universeVersion() {
|
||||||
if (this.universeVersionStore) {
|
if (this.universeVersionStore) {
|
||||||
return this.universeVersionStore;
|
return this.universeVersionStore;
|
||||||
} else {
|
} else {
|
||||||
@ -47,7 +42,14 @@ export class Universe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the smartexpress server used
|
||||||
|
*/
|
||||||
private smartexpressServer: plugins.smartexpress.Server;
|
private smartexpressServer: plugins.smartexpress.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the smartsocket used
|
||||||
|
*/
|
||||||
private smartsocket: plugins.smartsocket.Smartsocket;
|
private smartsocket: plugins.smartsocket.Smartsocket;
|
||||||
|
|
||||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||||
@ -59,46 +61,61 @@ export class Universe {
|
|||||||
* adds a channel to the Universe
|
* adds a channel to the Universe
|
||||||
*/
|
*/
|
||||||
public async addChannel(nameArg: string, passphraseArg: string) {
|
public async addChannel(nameArg: string, passphraseArg: string) {
|
||||||
const newChannel = new UniverseChannel(this.universeCache, nameArg, passphraseArg);
|
const newChannel = UniverseChannel.createChannel(this.universeCache, nameArg, passphraseArg);
|
||||||
this.universeCache.channelMap.add(newChannel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initiates a server
|
* initiates a server
|
||||||
*/
|
*/
|
||||||
public async initServer(portArg: number | string) {
|
public async initServer(portArg: number | string) {
|
||||||
|
// lets create the base smartexpress server
|
||||||
this.smartexpressServer = new plugins.smartexpress.Server({
|
this.smartexpressServer = new plugins.smartexpress.Server({
|
||||||
cors: true,
|
cors: true,
|
||||||
defaultAnswer: `smartuniverse server ${this.universeVersion}`,
|
defaultAnswer: async () => {
|
||||||
|
return `smartuniverse server ${this.universeVersion}`;
|
||||||
|
},
|
||||||
forceSsl: false,
|
forceSsl: false,
|
||||||
port: portArg
|
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
|
// add websocket upgrade
|
||||||
this.smartsocket = new plugins.smartsocket.Smartsocket({
|
this.smartsocket = new plugins.smartsocket.Smartsocket({
|
||||||
port: 12345 // fix this within smartsocket
|
port: 12345 // fix this within smartsocket
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// add a role for the clients
|
||||||
const ClientRole = new plugins.smartsocket.SocketRole({
|
const ClientRole = new plugins.smartsocket.SocketRole({
|
||||||
name: 'clientuniverse',
|
name: 'clientuniverse',
|
||||||
passwordHash: 'clientuniverse' // authentication happens on another level
|
passwordHash: 'clientuniverse' // authentication happens on another level
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// add the role to smartsocket
|
||||||
this.smartsocket.addSocketRoles([ClientRole]);
|
this.smartsocket.addSocketRoles([ClientRole]);
|
||||||
|
|
||||||
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||||
allowedRoles: [ClientRole],
|
allowedRoles: [ClientRole],
|
||||||
funcName: 'channelSubscription',
|
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);
|
this.smartsocket.setExternalServer('express', this.smartexpressServer as any);
|
||||||
// should work with express as well
|
|
||||||
|
// start the socket
|
||||||
this.smartsocket.start();
|
this.smartsocket.start();
|
||||||
|
|
||||||
|
// start the smartexpress instance
|
||||||
await this.smartexpressServer.start();
|
await this.smartexpressServer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop everything
|
||||||
|
*/
|
||||||
public async stopServer() {
|
public async stopServer() {
|
||||||
await this.smartsocket.stop();
|
await this.smartsocket.stop();
|
||||||
await this.smartexpressServer.stop();
|
await this.smartexpressServer.stop();
|
||||||
|
@ -3,10 +3,11 @@ import * as plugins from './smartuniverse.plugins';
|
|||||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
|
|
||||||
import { Objectmap } from 'lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { Observable, from } from 'rxjs';
|
||||||
import { rxjs } from 'smartrx';
|
import { filter } from 'rxjs/operators';
|
||||||
|
import { rxjs } from '@pushrocks/smartrx';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* universe store handles the creation, storage and retrieval of messages.
|
* universe store handles the creation, storage and retrieval of messages.
|
||||||
@ -38,7 +39,7 @@ export class UniverseCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a message to the UniverseStore
|
* add a message to the UniverseCache
|
||||||
* @param messageArg
|
* @param messageArg
|
||||||
* @param attachedPayloadArg
|
* @param attachedPayloadArg
|
||||||
*/
|
*/
|
||||||
@ -49,13 +50,13 @@ export class UniverseCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a message from the UniverseStore
|
* Read a message from the UniverseCache
|
||||||
*/
|
*/
|
||||||
public readMessagesYoungerThan(unixTimeArg?: number): Observable<UniverseMessage> {
|
public readMessagesYoungerThan(unixTimeArg?: number): Observable<UniverseMessage> {
|
||||||
const messageObservable = rxjs.Observable.from(this.messageMap.getArray()).filter(
|
const messageObservable = from(this.messageMap.getArray()).pipe(
|
||||||
messageArg => {
|
filter(messageArg => {
|
||||||
return messageArg.timestamp.isYoungerThanMilliSeconds(this.destructionTime);
|
return messageArg.timestamp.isYoungerThanMilliSeconds(this.destructionTime);
|
||||||
}
|
})
|
||||||
);
|
);
|
||||||
return messageObservable;
|
return messageObservable;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
import { Objectmap } from 'lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
import { UniverseCache } from './smartuniverse.classes.universecache';
|
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ export class UniverseChannel {
|
|||||||
passphraseArg: string
|
passphraseArg: string
|
||||||
) {
|
) {
|
||||||
const newChannel = new UniverseChannel(universeCacheArg, channelNameArg, passphraseArg);
|
const newChannel = new UniverseChannel(universeCacheArg, channelNameArg, passphraseArg);
|
||||||
|
universeCacheArg.channelMap.add(newChannel);
|
||||||
return newChannel;
|
return newChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
import { Objectmap } from 'lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
|
|
||||||
import { Timer, TimeStamp } from 'smarttime';
|
import { Timer, TimeStamp } from '@pushrocks/smarttime';
|
||||||
import { Universe } from './smartuniverse.classes.universe';
|
import { Universe } from './smartuniverse.classes.universe';
|
||||||
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||||
import { UniverseCache } from './smartuniverse.classes.universecache';
|
import { UniverseCache } from './smartuniverse.classes.universecache';
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
export interface IUniverseChannel {}
|
|
||||||
|
|
||||||
export interface IUniverseMessage {}
|
|
@ -1,23 +1,27 @@
|
|||||||
import * as lik from 'lik';
|
// node native
|
||||||
import * as nodehash from 'nodehash';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as smartdelay from 'smartdelay';
|
|
||||||
import * as smartexpress from 'smartexpress';
|
export { path };
|
||||||
import * as smartfile from 'smartfile';
|
|
||||||
import * as smartq from 'smartq';
|
// pushrocks scope
|
||||||
import * as smartrequest from 'smartrequest';
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as smartrx from 'smartrx';
|
import * as smarthash from '@pushrocks/smarthash';
|
||||||
import * as smartsocket from 'smartsocket';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smarttime from 'smarttime';
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
import * as smartsocket from '@pushrocks/smartsocket';
|
||||||
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
lik,
|
lik,
|
||||||
nodehash,
|
smarthash,
|
||||||
path,
|
|
||||||
smartdelay,
|
smartdelay,
|
||||||
smartexpress,
|
smartexpress,
|
||||||
smartfile,
|
smartfile,
|
||||||
smartq,
|
smartpromise,
|
||||||
smartrx,
|
smartrx,
|
||||||
smartrequest,
|
smartrequest,
|
||||||
smartsocket,
|
smartsocket,
|
||||||
|
23
tslint.json
23
tslint.json
@ -1,12 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
"tslint:latest",
|
|
||||||
"tslint-config-prettier"
|
|
||||||
],
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"semicolon": [
|
"semicolon": [true, "always"],
|
||||||
true,
|
"no-console": false,
|
||||||
"always"
|
"ordered-imports": false,
|
||||||
]
|
"object-literal-sort-keys": false,
|
||||||
}
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user