fix(core): update

This commit is contained in:
Philipp Kunz 2019-04-24 18:20:31 +02:00
parent d43ad80784
commit af9f590349
8 changed files with 72 additions and 53 deletions

52
package-lock.json generated
View File

@ -363,28 +363,22 @@
} }
}, },
"@pushrocks/smartsocket": { "@pushrocks/smartsocket": {
"version": "1.1.27", "version": "1.1.32",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.27.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.32.tgz",
"integrity": "sha512-rxHWOoGTbDyRi+LQRTFe1kgnlik8uPDjRpz60U49yQU7mexGbeK6HPevgaiQH6wsmorrN64KMWCnwCrPAFQDXA==", "integrity": "sha512-wqc62xt7ollhGnE34076h5Y8ZwNHlK8p14WomXEDOiR6QFiPcF5L3hf2OzJTWPvMycNoa/iWGqkU0Ceo8coj+A==",
"requires": { "requires": {
"@pushrocks/lik": "^3.0.4", "@pushrocks/lik": "^3.0.5",
"@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartexpress": "^3.0.18",
"@pushrocks/smarthash": "^2.0.4", "@pushrocks/smarthash": "^2.0.4",
"@pushrocks/smartlog": "^2.0.16", "@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^3.0.2",
"@types/shortid": "0.0.29", "@types/shortid": "0.0.29",
"@types/socket.io": "^2.1.2", "@types/socket.io": "^2.1.2",
"@types/socket.io-client": "^1.4.32", "@types/socket.io-client": "^1.4.32",
"shortid": "^2.2.14", "shortid": "^2.2.14",
"socket.io": "^2.2.0", "socket.io": "^2.2.0",
"socket.io-client": "^2.2.0" "socket.io-client": "^2.2.0"
},
"dependencies": {
"@pushrocks/smartpromise": {
"version": "2.0.5",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz",
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g=="
}
} }
}, },
"@pushrocks/smarttime": { "@pushrocks/smarttime": {
@ -546,9 +540,9 @@
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==" "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
}, },
"@types/node": { "@types/node": {
"version": "11.13.6", "version": "11.13.7",
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.6.tgz", "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-11.13.7.tgz",
"integrity": "sha512-Xoo/EBzEe8HxTSwaZNLZjaW6M6tA/+GmD3/DZ6uo8qSaolE/9Oarko0oV1fVfrLqOz0tx0nXJB4rdD5c+vixLw==" "integrity": "sha512-suFHr6hcA9mp8vFrZTgrmqW2ZU3mbWsryQtQlY/QvwTISCw7nw/j+bCQPPohqmskhmqa5wLNuMHTTsc+xf1MQg=="
}, },
"@types/range-parser": { "@types/range-parser": {
"version": "1.2.3", "version": "1.2.3",
@ -811,7 +805,7 @@
}, },
"builtin-modules": { "builtin-modules": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", "resolved": "https://verdaccio.lossless.one/builtin-modules/-/builtin-modules-1.1.1.tgz",
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=",
"dev": true "dev": true
}, },
@ -872,7 +866,7 @@
}, },
"chalk": { "chalk": {
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "resolved": "https://verdaccio.lossless.one/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -931,7 +925,7 @@
}, },
"color-convert": { "color-convert": {
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "resolved": "https://verdaccio.lossless.one/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -940,7 +934,7 @@
}, },
"color-name": { "color-name": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "resolved": "https://verdaccio.lossless.one/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true "dev": true
}, },
@ -954,7 +948,7 @@
}, },
"commander": { "commander": {
"version": "2.20.0", "version": "2.20.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", "resolved": "https://verdaccio.lossless.one/commander/-/commander-2.20.0.tgz",
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
"dev": true "dev": true
}, },
@ -1220,7 +1214,7 @@
}, },
"esutils": { "esutils": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", "resolved": "https://verdaccio.lossless.one/esutils/-/esutils-2.0.2.tgz",
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
"dev": true "dev": true
}, },
@ -1507,7 +1501,7 @@
}, },
"has-flag": { "has-flag": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "resolved": "https://verdaccio.lossless.one/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true "dev": true
}, },
@ -1946,7 +1940,7 @@
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "resolved": "https://verdaccio.lossless.one/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -1955,7 +1949,7 @@
"dependencies": { "dependencies": {
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "resolved": "https://verdaccio.lossless.one/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true "dev": true
} }
@ -2145,7 +2139,7 @@
}, },
"path-parse": { "path-parse": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", "resolved": "https://verdaccio.lossless.one/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"dev": true "dev": true
}, },
@ -2315,7 +2309,7 @@
}, },
"resolve": { "resolve": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", "resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.10.0.tgz",
"integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -2727,7 +2721,7 @@
}, },
"tsutils": { "tsutils": {
"version": "2.29.0", "version": "2.29.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", "resolved": "https://verdaccio.lossless.one/tsutils/-/tsutils-2.29.0.tgz",
"integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==",
"dev": true, "dev": true,
"requires": { "requires": {

View File

@ -9,6 +9,7 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"testManual": "(tsrun test/test.ts)",
"build": "(tsbuild)", "build": "(tsbuild)",
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
@ -16,7 +17,7 @@
"@gitzone/tsbuild": "^2.1.8", "@gitzone/tsbuild": "^2.1.8",
"@gitzone/tstest": "^1.0.20", "@gitzone/tstest": "^1.0.20",
"@pushrocks/tapbundle": "^3.0.9", "@pushrocks/tapbundle": "^3.0.9",
"@types/node": "^11.13.6", "@types/node": "^11.13.7",
"tslint": "^5.16.0", "tslint": "^5.16.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
@ -32,7 +33,7 @@
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.15", "@pushrocks/smartrequest": "^1.1.15",
"@pushrocks/smartrx": "^2.0.3", "@pushrocks/smartrx": "^2.0.3",
"@pushrocks/smartsocket": "^1.1.27", "@pushrocks/smartsocket": "^1.1.32",
"@pushrocks/smarttime": "^3.0.7", "@pushrocks/smarttime": "^3.0.7",
"@pushrocks/smartunique": "^3.0.1" "@pushrocks/smartunique": "^3.0.1"
} }

View File

@ -51,6 +51,10 @@ tap.test('should send a message correctly', async () => {
}); });
}); });
tap.test('universe should contain the sent message', async () => {
expect(testUniverse.universeCache.messageMap.getArray()[0].messageText).to.equal('hello');
});
tap.test('should receive a message correctly', async () => {}); tap.test('should receive a message correctly', async () => {});
tap.test('should disconnect the client correctly', async () => { tap.test('should disconnect the client correctly', async () => {

View File

@ -57,19 +57,18 @@ export class ClientUniverse {
} }
public async sendMessage(messageArg: interfaces.IMessageCreator) { public async sendMessage(messageArg: interfaces.IMessageCreator) {
console.log('hello'); await this.checkConnection();
const requestBody: interfaces.IUniverseMessage = { const requestBody: interfaces.IUniverseMessage = {
id: plugins.smartunique.shortId(), id: plugins.smartunique.shortId(),
timestamp: Date.now(), timestamp: Date.now(),
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase, passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
...messageArg ...messageArg
}; };
const requestBodyString = JSON.stringify(requestBody);
// TODO: User websocket connection if available // TODO: User websocket connection if available
const response = await plugins.smartrequest.postJson( const response = await plugins.smartrequest.postJson(
`${this.options.serverAddress}/sendmessage`, `${this.options.serverAddress}/sendmessage`,
{ {
requestBody: requestBodyString requestBody
} }
); );
} }
@ -85,15 +84,17 @@ export class ClientUniverse {
private async checkConnection(): Promise<void> { private async checkConnection(): Promise<void> {
if (!this.socketClient && !this.observableIntake) { if (!this.socketClient && !this.observableIntake) {
const parsedURL = url.parse(this.options.serverAddress); const parsedURL = url.parse(this.options.serverAddress);
this.socketClient = new SmartsocketClient({ const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
alias: process.env.SOCKET_ALIAS || 'someclient', alias: process.env.SOCKET_ALIAS || 'someclient',
password: 'UniverseClient', password: 'UniverseClient',
port: parseInt(parsedURL.port, 10), port: parseInt(parsedURL.port, 10),
role: 'UniverseClient', role: 'UniverseClient',
url: parsedURL.hostname url: parsedURL.protocol + '//' + parsedURL.hostname
}); };
console.log(socketConfig);
this.socketClient = new SmartsocketClient(socketConfig);
this.observableIntake = new plugins.smartrx.ObservableIntake(); this.observableIntake = new plugins.smartrx.ObservableIntake();
this.socketClient.connect(); await this.socketClient.connect();
} }
} }
} }

View File

@ -80,22 +80,21 @@ export class Universe {
this.smartexpressServer.addRoute( this.smartexpressServer.addRoute(
'/sendmessage', '/sendmessage',
new Handler('POST', async (req, res) => { new Handler('POST', async (req, res) => {
const universeMessageInstance = new UniverseMessage(req.body); const universeMessageInstance: UniverseMessage = new UniverseMessage(req.body);
this.universeCache.addMessage(universeMessageInstance); this.universeCache.addMessage(universeMessageInstance);
res.status(200); res.status(200);
res.end(); res.end();
}) })
); );
// add websocket upgrade // add websocket upgrade
this.smartsocket = new plugins.smartsocket.Smartsocket({ this.smartsocket = new plugins.smartsocket.Smartsocket({});
port: 12345 // fix this within smartsocket
});
// add a role for the clients // add a role for the clients
const ClientRole = new plugins.smartsocket.SocketRole({ const ClientRole = new plugins.smartsocket.SocketRole({
name: 'clientuniverse', name: 'UniverseClient',
passwordHash: 'clientuniverse' // authentication happens on another level passwordHash: plugins.smarthash.sha256FromStringSync('UniverseClient') // authentication happens on another level
}); });
// add the role to smartsocket // add the role to smartsocket
@ -105,18 +104,16 @@ export class Universe {
allowedRoles: [ClientRole], allowedRoles: [ClientRole],
funcName: 'channelSubscription', funcName: 'channelSubscription',
funcDef: () => { funcDef: () => {
console.log('a client connected');
} // TODO: implement an action upon connection of clients } // TODO: implement an action upon connection of clients
}); });
// add smartsocket to the running smartexpress app // add smartsocket to the running smartexpress app
this.smartsocket.setExternalServer('express', this.smartexpressServer as any); this.smartsocket.setExternalServer('smartexpress', this.smartexpressServer as any);
// start everything
// start the socket
this.smartsocket.start();
// start the smartexpress instance
await this.smartexpressServer.start(); await this.smartexpressServer.start();
await this.smartsocket.start();
console.log('started universe');
} }
/** /**

View File

@ -52,7 +52,7 @@ export class UniverseCache {
/** /**
* Read a message from the UniverseCache * Read a message from the UniverseCache
*/ */
public readMessagesYoungerThan(unixTimeArg?: number): Observable<UniverseMessage> { public readMessagesYoungerThan(unixTimeArg?: number, channelName?: string): Observable<UniverseMessage> {
const messageObservable = from(this.messageMap.getArray()).pipe( const messageObservable = from(this.messageMap.getArray()).pipe(
filter(messageArg => { filter(messageArg => {
return messageArg.smartTimestamp.isYoungerThanMilliSeconds(this.destructionTime); return messageArg.smartTimestamp.isYoungerThanMilliSeconds(this.destructionTime);

View File

@ -88,5 +88,7 @@ export class UniverseChannel {
); );
} }
public pushToClients(messageArg: UniverseMessage) {} public pushToClients(messageArg: UniverseMessage) {
}
} }

View File

@ -0,0 +1,20 @@
import * as plugins from './smartuniverse.plugins';
import { UniverseChannel } from './smartuniverse.classes.universechannel';
/**
* represents a subscription into a specific topic
*/
export class UniverseConnection {
/**
* the socketClient to ping
*/
socketclient: plugins.smartsocket.SmartsocketClient;
subscribedChannels: UniverseChannel[] = [];
authenticatedChannels: UniverseChannel[] = [];
constructor() {
}
}