Compare commits

..

12 Commits

Author SHA1 Message Date
5dab36382f 1.0.75 2019-09-10 09:56:33 +02:00
02a32eb8c7 fix(core): update 2019-09-10 09:56:32 +02:00
b258979b5a 1.0.74 2019-09-10 01:39:39 +02:00
166e29bbf6 fix(core): update 2019-09-10 01:39:38 +02:00
870f37d403 1.0.73 2019-09-10 01:19:10 +02:00
64c4b91678 fix(core): update 2019-09-10 01:19:10 +02:00
f3e13292d8 1.0.72 2019-09-10 00:39:18 +02:00
7e1c405cb1 fix(core): update 2019-09-10 00:39:18 +02:00
d1b4672eff 1.0.71 2019-09-10 00:29:08 +02:00
0dd9fee52b fix(core): update 2019-09-10 00:29:08 +02:00
37e1ee7970 1.0.70 2019-09-01 21:34:01 +02:00
bd0bb3acf5 fix(core): update 2019-09-01 21:34:01 +02:00
15 changed files with 210 additions and 117 deletions

89
package-lock.json generated
View File

@ -1,9 +1,14 @@
{ {
"name": "@pushrocks/smartuniverse", "name": "@pushrocks/smartuniverse",
"version": "1.0.69", "version": "1.0.75",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@apiglobal/typedrequest-interfaces": {
"version": "1.0.7",
"resolved": "https://verdaccio.lossless.one/@apiglobal%2ftypedrequest-interfaces/-/typedrequest-interfaces-1.0.7.tgz",
"integrity": "sha512-yPl0UcLFMwSQL7bK52wVjkgvadC+x2YS3+7T15V1A1dXNxa96yd4WX1fqcKqwnBrvYexq/8FaxWGi98tZ0oNwg=="
},
"@babel/code-frame": { "@babel/code-frame": {
"version": "7.5.5", "version": "7.5.5",
"resolved": "https://verdaccio.lossless.one/@babel%2fcode-frame/-/code-frame-7.5.5.tgz", "resolved": "https://verdaccio.lossless.one/@babel%2fcode-frame/-/code-frame-7.5.5.tgz",
@ -290,9 +295,9 @@
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ==" "integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
}, },
"@pushrocks/smartrequest": { "@pushrocks/smartrequest": {
"version": "1.1.23", "version": "1.1.27",
"resolved": "https://registry.npmjs.org/@pushrocks/smartrequest/-/smartrequest-1.1.23.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrequest/-/smartrequest-1.1.27.tgz",
"integrity": "sha512-Hws3YfzIE0b/E3aTkSugLskKWBq7e8HDXEN+RlRyTFONxW/XONKJFTw4mp3jk+puWpYGDoOTcP+Ua4jd19z9pA==", "integrity": "sha512-GJO6duKBro2oILtXduVQwxA50AzjHZbKP0P32OoiM+B1ftoQFf4D8zSs/SCljNKXUqS8SZ9IMQVlKLfRC4nu+A==",
"requires": { "requires": {
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"@types/form-data": "^2.2.1", "@types/form-data": "^2.2.1",
@ -300,20 +305,23 @@
} }
}, },
"@pushrocks/smartrx": { "@pushrocks/smartrx": {
"version": "2.0.3", "version": "2.0.5",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrx/-/smartrx-2.0.3.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrx/-/smartrx-2.0.5.tgz",
"integrity": "sha512-OWxagu+CBdPaq76AIg91hJyrNhDTlEpesj01ooWCeVIaLY3G7yvFkqHsEKNOwPUG1LzCWmjq1l1dHQx9p2vJ9A==", "integrity": "sha512-BOlIJmnCO8pxqu9f18D9UV5rIsyrmKeK/mWNMiAe/NH2OTeRPNLpgmhZBkXSKNVD8tSsD8aazs4BcACgYOg1FQ==",
"requires": { "requires": {
"@pushrocks/lik": "^3.0.2", "@pushrocks/lik": "^3.0.11",
"@pushrocks/smartevent": "^2.0.3", "@pushrocks/smartevent": "^2.0.3",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^3.0.2",
"rxjs": "^6.3.3" "rxjs": "^6.5.3"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": { "rxjs": {
"version": "2.0.5", "version": "6.5.3",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz", "resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.5.3.tgz",
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==" "integrity": "sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA==",
"requires": {
"tslib": "^1.9.0"
}
} }
} }
}, },
@ -331,10 +339,11 @@
} }
}, },
"@pushrocks/smartsocket": { "@pushrocks/smartsocket": {
"version": "1.1.46", "version": "1.1.49",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.46.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.49.tgz",
"integrity": "sha512-MaUjOhd/v/YACRf+JLlaXJB8efiUncmy46f1RF9sHnBgkWH8Pq55WY+sa5rFd+1Tk+rVy2VRI22tmc0r4pqwJA==", "integrity": "sha512-jDcqVU9/cXTkLBY2N3epPUBKtRRkFINzK//CRxmBcuZx/k0s5oeNM1tOI7aiP5p5arrybU/YksSQil1QKz24Gg==",
"requires": { "requires": {
"@apiglobal/typedrequest-interfaces": "^1.0.7",
"@pushrocks/lik": "^3.0.11", "@pushrocks/lik": "^3.0.11",
"@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartexpress": "^3.0.40", "@pushrocks/smartexpress": "^3.0.40",
@ -344,9 +353,24 @@
"@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.15",
"socket.io": "^2.2.0", "socket.io": "^2.2.0",
"socket.io-client": "^2.2.0" "socket.io-client": "^2.2.0"
},
"dependencies": {
"nanoid": {
"version": "2.1.0",
"resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.0.tgz",
"integrity": "sha512-g5WwS+p6Cm+zQhO2YOpRbQThZVnNb7DDq74h8YDCLfAGynrEOrbx2E16dc8ciENiP1va5sqaAruqn2sN+xpkWg=="
},
"shortid": {
"version": "2.2.15",
"resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.15.tgz",
"integrity": "sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==",
"requires": {
"nanoid": "^2.1.0"
}
}
} }
}, },
"@pushrocks/smarttime": { "@pushrocks/smarttime": {
@ -515,9 +539,9 @@
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==" "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
}, },
"@types/node": { "@types/node": {
"version": "12.7.3", "version": "12.7.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.3.tgz", "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.7.4.tgz",
"integrity": "sha512-3SiLAIBkDWDg6vFo0+5YJyHPWU9uwu40Qe+v+0MH8wRKYBimHvvAOyk3EzMrD/TrIlLYfXrqDqrg913PynrMJQ==" "integrity": "sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ=="
}, },
"@types/range-parser": { "@types/range-parser": {
"version": "1.2.3", "version": "1.2.3",
@ -1219,7 +1243,7 @@
}, },
"esutils": { "esutils": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "resolved": "https://verdaccio.lossless.one/esutils/-/esutils-2.0.3.tgz",
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true "dev": true
}, },
@ -1925,7 +1949,7 @@
}, },
"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
}, },
@ -2340,7 +2364,7 @@
}, },
"resolve": { "resolve": {
"version": "1.12.0", "version": "1.12.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", "resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.12.0.tgz",
"integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -2361,6 +2385,7 @@
"version": "6.4.0", "version": "6.4.0",
"resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.4.0.tgz", "resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.4.0.tgz",
"integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==", "integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==",
"dev": true,
"requires": { "requires": {
"tslib": "^1.9.0" "tslib": "^1.9.0"
} }
@ -2748,16 +2773,16 @@
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
}, },
"tslint": { "tslint": {
"version": "5.19.0", "version": "5.20.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.19.0.tgz", "resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
"integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==", "integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.0.0", "@babel/code-frame": "^7.0.0",
"builtin-modules": "^1.1.1", "builtin-modules": "^1.1.1",
"chalk": "^2.3.0", "chalk": "^2.3.0",
"commander": "^2.12.1", "commander": "^2.12.1",
"diff": "^3.2.0", "diff": "^4.0.1",
"glob": "^7.1.1", "glob": "^7.1.1",
"js-yaml": "^3.13.1", "js-yaml": "^3.13.1",
"minimatch": "^3.0.4", "minimatch": "^3.0.4",
@ -2766,14 +2791,6 @@
"semver": "^5.3.0", "semver": "^5.3.0",
"tslib": "^1.8.0", "tslib": "^1.8.0",
"tsutils": "^2.29.0" "tsutils": "^2.29.0"
},
"dependencies": {
"diff": {
"version": "3.5.0",
"resolved": "https://verdaccio.lossless.one/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
"dev": true
}
} }
}, },
"tslint-config-prettier": { "tslint-config-prettier": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartuniverse", "name": "@pushrocks/smartuniverse",
"version": "1.0.69", "version": "1.0.75",
"private": false, "private": false,
"description": "messaging service for your micro services", "description": "messaging service for your micro services",
"main": "dist/index.js", "main": "dist/index.js",
@ -17,8 +17,8 @@
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.3", "@types/node": "^12.7.4",
"tslint": "^5.19.0", "tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"peerDependencies": { "peerDependencies": {
@ -32,9 +32,9 @@
"@pushrocks/smarthash": "^2.0.6", "@pushrocks/smarthash": "^2.0.6",
"@pushrocks/smartlog": "^2.0.19", "@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.23", "@pushrocks/smartrequest": "^1.1.27",
"@pushrocks/smartrx": "^2.0.3", "@pushrocks/smartrx": "^2.0.5",
"@pushrocks/smartsocket": "^1.1.46", "@pushrocks/smartsocket": "^1.1.49",
"@pushrocks/smarttime": "^3.0.12", "@pushrocks/smarttime": "^3.0.12",
"@pushrocks/smartunique": "^3.0.1" "@pushrocks/smartunique": "^3.0.1"
}, },

View File

@ -74,7 +74,7 @@ tap.test('a second client should be able to subscibe', async () => {
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 () => {
testClientUniverse.stop(); await testClientUniverse.stop();
}); });
tap.test('should end the server correctly', async tools => { tap.test('should end the server correctly', async tools => {

View File

@ -1,4 +1,5 @@
export * from './http.interfaces'; export * from './http.interfaces';
export * from './socketfunctionrequests';
export * from './universechannel.interfaces'; export * from './universechannel.interfaces';
export * from './universemessage.interfaces'; export * from './universemessage.interfaces';
export * from './universeactions.interfaces'; export * from './universeactions.interfaces';

View File

@ -0,0 +1,20 @@
import * as interfaces from './index';
export interface ISocketRequest_SubscribeChannel {
method: 'subscribeChannel';
request: {
name: string;
passphrase: string;
};
response: {
subscriptionStatus: 'subscribed' | 'unsubscribed'
};
}
export interface ISocketRequest_ProcessMessage {
method: 'processMessage';
request: interfaces.IUniverseMessage;
response: {
messageStatus: 'ok' | 'channel not found'
};
}

View File

@ -4,13 +4,6 @@ export type IServerCallActions =
| 'channelUnsubscribe' | 'channelUnsubscribe'
| 'terminateConnection'; | 'terminateConnection';
/**
* the interface for a subscription
*/
export interface IServerCallSubscribeActionPayload {
name: string;
passphrase: string;
}
export interface IServerUnsubscribeActionPayload { export interface IServerUnsubscribeActionPayload {
name: string; name: string;

View File

@ -5,7 +5,7 @@ export interface IMessageCreator {
} }
/** /**
* * A universe
*/ */
export interface IUniverseMessage extends IMessageCreator { export interface IUniverseMessage extends IMessageCreator {
id: string; id: string;

View File

@ -76,8 +76,8 @@ export class ClientUniverse {
await this.checkConnection(); await this.checkConnection();
} }
public stop() { public async stop() {
this.smartsocketClient.disconnect(); await this.smartsocketClient.disconnect();
} }
/** /**
@ -88,7 +88,7 @@ export class ClientUniverse {
if (!this.smartsocketClient && !this.observableIntake) { if (!this.smartsocketClient && !this.observableIntake) {
const parsedURL = url.parse(this.options.serverAddress); const parsedURL = url.parse(this.options.serverAddress);
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = { const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
alias: process.env.SOCKET_ALIAS || 'someclient', alias: 'universeclient',
password: 'UniverseClient', password: 'UniverseClient',
port: parseInt(parsedURL.port, 10), port: parseInt(parsedURL.port, 10),
role: 'UniverseClient', role: 'UniverseClient',
@ -113,14 +113,30 @@ export class ClientUniverse {
/** /**
* handles message reception * handles message reception
*/ */
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction({ const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction<
interfaces.ISocketRequest_ProcessMessage
>({
funcName: 'processMessage', funcName: 'processMessage',
allowedRoles: [], allowedRoles: [],
funcDef: async (messageDescriptorArg: interfaces.IUniverseMessage) => { funcDef: async messageDescriptorArg => {
plugins.smartlog.defaultLogger.log('info', 'Got message from server'); plugins.smartlog.defaultLogger.log('info', 'Got message from server');
this.observableIntake.push( const clientUniverseMessage = ClientUniverseMessage.createMessageFromMessageDescriptor(
ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg) messageDescriptorArg
); );
this.observableIntake.push(clientUniverseMessage);
// lets find the corresponding channel
const targetChannel = this.getChannel(clientUniverseMessage.targetChannelName);
if (targetChannel) {
await targetChannel.emitMessageLocally(clientUniverseMessage);
return {
messageStatus: 'ok'
};
} else {
return {
messageStatus: 'channel not found'
};
}
} }
}); });

View File

@ -2,6 +2,9 @@ import * as plugins from './smartuniverse.plugins';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
import { ClientUniverse } from './'; import { ClientUniverse } from './';
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
import { ReactionRequest } from './smartuniverse.classes.reactionrequest';
import { ReactionResponse } from './smartuniverse.classes.reactionresponse';
export class ClientUniverseChannel implements interfaces.IUniverseChannel { export class ClientUniverseChannel implements interfaces.IUniverseChannel {
// ====== // ======
@ -34,6 +37,8 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
// properties // properties
public name: string; public name: string;
public passphrase: string; public passphrase: string;
public status: 'subscribed' | 'unsubscribed' = 'unsubscribed';
private subject = new plugins.smartrx.rxjs.Subject<ClientUniverseMessage>();
// refs // refs
public clientUniverseRef: ClientUniverse; public clientUniverseRef: ClientUniverse;
@ -48,16 +53,32 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
* subscribes to a channel * subscribes to a channel
* tells the universe about this instances interest into a channel * tells the universe about this instances interest into a channel
*/ */
public async subscribe() { public async subscribe(observerArg?: plugins.smartrx.rxjs.Observer<any>) {
const serverCallActionName: interfaces.IServerCallActions = 'channelSubscription'; // lets make sure the channel is connected
const serverCallActionPayload: interfaces.IServerCallSubscribeActionPayload = { if (this.status === 'unsubscribed') {
name: this.name, const response = await this.clientUniverseRef.smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
passphrase: this.passphrase 'subscribeChannel',
}; {
await this.clientUniverseRef.smartsocketClient.serverCall( name: this.name,
serverCallActionName, passphrase: this.passphrase
serverCallActionPayload }
); );
this.status = response.subscriptionStatus;
}
if (observerArg) {
return this.subject.subscribe(observerArg);
}
}
public async emitMessageLocally(messageArg: ClientUniverseMessage) {
this.subject.next(messageArg);
}
public askForReaction(reactionRequest: ReactionRequest): ReactionResponse {
const reactionResponse = new ReactionResponse();
return reactionResponse;
} }
/** /**

View File

@ -0,0 +1,5 @@
import * as plugins from './smartuniverse.plugins';
export class ReactionRequest {
}

View File

@ -0,0 +1,3 @@
import * as plugins from './smartuniverse.plugins';
export class ReactionResponse {}

View File

@ -95,24 +95,21 @@ export class Universe {
// add the role to smartsocket // add the role to smartsocket
this.smartsocket.addSocketRoles([ClientRole]); this.smartsocket.addSocketRoles([ClientRole]);
const socketFunctionSubscription = new plugins.smartsocket.SocketFunction({ const socketFunctionSubscription = new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_SubscribeChannel>({
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
funcName: 'channelSubscription', funcName: 'subscribeChannel',
funcDef: async ( funcDef: async (
dataArg: interfaces.IServerCallSubscribeActionPayload, dataArg,
socketConnectionArg socketConnectionArg
) => { ) => {
// run in "this context" of this class const universeConnection = new UniverseConnection({
await (async () => { socketConnection: socketConnectionArg,
const universeConnection = new UniverseConnection({ authenticationRequests: [dataArg]
socketConnection: socketConnectionArg, });
authenticationRequests: [dataArg] await UniverseConnection.addConnectionToCache(this, universeConnection);
}); return {
await UniverseConnection.addConnectionToCache(this, universeConnection); subscriptionStatus: 'subscribed'
return { };
'subscription status': 'success'
};
})();
} }
}); });
@ -120,39 +117,36 @@ export class Universe {
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
funcName: 'processMessage', funcName: 'processMessage',
funcDef: async (dataArg: interfaces.IUniverseMessage, socketConnectionArg) => { funcDef: async (dataArg: interfaces.IUniverseMessage, socketConnectionArg) => {
// run in "this" context of this class const universeConnection = UniverseConnection.findUniverseConnectionBySocketConnection(
await (async () => { this.universeCache,
const universeConnection = UniverseConnection.findUniverseConnectionBySocketConnection( socketConnectionArg
this.universeCache, );
socketConnectionArg if (universeConnection) {
plugins.smartlog.defaultLogger.log(
'ok',
'found UniverseConnection for socket for incoming message'
); );
if (universeConnection) { } else {
plugins.smartlog.defaultLogger.log( plugins.smartlog.defaultLogger.log(
'ok', 'warn',
'found UniverseConnection for socket for incoming message' 'found no Authorized channel for incoming message'
);
} else {
plugins.smartlog.defaultLogger.log(
'warn',
'found no Authorized channel for incoming message'
);
return {
error: 'You need to authenticate for a channel'
};
}
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(
socketConnectionArg,
dataArg
); );
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel( return {
this.universeCache, error: 'You need to authenticate for a channel'
unauthenticatedMessage };
); }
if (foundChannel && unauthenticatedMessage.authenticated) { const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(
const authenticatedMessage = unauthenticatedMessage; socketConnectionArg,
await this.universeCache.addMessage(authenticatedMessage); dataArg
} );
})(); const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
this.universeCache,
unauthenticatedMessage
);
if (foundChannel && unauthenticatedMessage.authenticated) {
const authenticatedMessage = unauthenticatedMessage;
await this.universeCache.addMessage(authenticatedMessage);
}
} }
}); });

View File

@ -59,7 +59,7 @@ export class UniverseCache {
UniverseChannel.authorizeAMessageForAChannel(this, messageArg); UniverseChannel.authorizeAMessageForAChannel(this, messageArg);
this.messageMap.add(messageArg); this.messageMap.add(messageArg);
messageArg.universeChannelList.forEach(universeChannel => { messageArg.universeChannelList.forEach(universeChannel => {
universeChannel.pushToClients(messageArg); universeChannel.push(messageArg);
}); });
} }

View File

@ -85,6 +85,7 @@ export class UniverseChannel {
*/ */
public name: string; public name: string;
public universeRef: Universe; public universeRef: Universe;
private subject = new plugins.smartrx.rxjs.Subject<UniverseMessage>();
/** /**
* the passphrase for the channel * the passphrase for the channel
@ -113,7 +114,8 @@ export class UniverseChannel {
* pushes a message to clients * pushes a message to clients
* @param messageArg * @param messageArg
*/ */
public async pushToClients(messageArg: UniverseMessage) { public async push(messageArg: UniverseMessage) {
this.subject.next(messageArg);
const universeConnectionsWithChannelAccess: UniverseConnection[] = []; const universeConnectionsWithChannelAccess: UniverseConnection[] = [];
this.universeRef.universeCache.connectionMap.forEach(async socketConnection => { this.universeRef.universeCache.connectionMap.forEach(async socketConnection => {
if (socketConnection.authenticatedChannels.includes(this)) { if (socketConnection.authenticatedChannels.includes(this)) {
@ -139,4 +141,25 @@ export class UniverseChannel {
); );
} }
} }
// functions to interact with a channel locally
public async subscribe(observer: plugins.smartrx.rxjs.Observer<any>) {
return this.subject.subscribe(observer);
}
/**
* sends a message to the channel
*/
public async sendMessage(messageDescriptor: interfaces.IMessageCreator) {
const messageToSend = new UniverseMessage({
id: plugins.smartunique.shortId(),
messageText: messageDescriptor.messageText,
payload: messageDescriptor.payload,
payloadStringType: messageDescriptor.payloadStringType,
targetChannelName: this.name,
passphrase: this.passphrase,
timestamp: Date.now()
});
this.push(messageToSend);
}
} }

View File

@ -98,7 +98,7 @@ export class UniverseConnection {
* the socketClient to ping * the socketClient to ping
*/ */
public socketConnection: plugins.smartsocket.SocketConnection; public socketConnection: plugins.smartsocket.SocketConnection;
public authenticationRequests: interfaces.IServerCallSubscribeActionPayload[] = []; public authenticationRequests: Array<interfaces.ISocketRequest_SubscribeChannel['request']> = [];
public subscribedChannels: UniverseChannel[] = []; public subscribedChannels: UniverseChannel[] = [];
public authenticatedChannels: UniverseChannel[] = []; public authenticatedChannels: UniverseChannel[] = [];
public failedToJoinChannels: UniverseChannel[] = []; public failedToJoinChannels: UniverseChannel[] = [];
@ -113,7 +113,7 @@ export class UniverseConnection {
constructor(optionsArg: { constructor(optionsArg: {
socketConnection: plugins.smartsocket.SocketConnection; socketConnection: plugins.smartsocket.SocketConnection;
authenticationRequests: interfaces.IServerCallSubscribeActionPayload[]; authenticationRequests: Array<interfaces.ISocketRequest_SubscribeChannel['request']>;
}) { }) {
this.authenticationRequests = optionsArg.authenticationRequests; this.authenticationRequests = optionsArg.authenticationRequests;
this.socketConnection = optionsArg.socketConnection; this.socketConnection = optionsArg.socketConnection;