From ff7cdc908c3fe33d52e23f080749c126f06f5f37 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 10 Sep 2019 19:36:10 +0200 Subject: [PATCH] fix(core): update --- package-lock.json | 6 ++-- package.json | 1 + test/test.ts | 2 +- ts/index.ts | 4 +++ ts/smartuniverse.classes.clientuniverse.ts | 2 +- ...tuniverse.classes.clientuniversechannel.ts | 23 +++++++------- ts/smartuniverse.classes.reactionrequest.ts | 23 +++++++++++++- ts/smartuniverse.classes.reactionresponse.ts | 30 +++++++++++++++++-- ts/smartuniverse.classes.universechannel.ts | 9 ++++-- ts/smartuniverse.plugins.ts | 7 +++++ 10 files changed, 85 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index cb0a851..c454c9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1243,7 +1243,7 @@ }, "esutils": { "version": "2.0.3", - "resolved": "https://verdaccio.lossless.one/esutils/-/esutils-2.0.3.tgz", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, @@ -1949,7 +1949,7 @@ }, "minimist": { "version": "0.0.8", - "resolved": "https://verdaccio.lossless.one/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true }, @@ -2364,7 +2364,7 @@ }, "resolve": { "version": "1.12.0", - "resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.12.0.tgz", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", "dev": true, "requires": { diff --git a/package.json b/package.json index 1f2a335..daa5425 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "rxjs": "*" }, "dependencies": { + "@apiglobal/typedrequest-interfaces": "^1.0.7", "@pushrocks/lik": "^3.0.11", "@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartexpress": "^3.0.40", diff --git a/test/test.ts b/test/test.ts index 2de06ff..9209c94 100644 --- a/test/test.ts +++ b/test/test.ts @@ -76,7 +76,7 @@ tap.test('should receive a message correctly', async (tools) => { const done = tools.defer(); const testChannel = testClientUniverse.getChannel(testChannelData.channelName); const testChannel2 = testClientUniverse2.getChannel(testChannelData.channelName); - const subscription = await testChannel2.subscribe(messageArg => { + const subscription = testChannel2.subscribe(messageArg => { console.log('Yay##########'); done.resolve(); }); diff --git a/ts/index.ts b/ts/index.ts index 037c4f1..9bb27f7 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -9,4 +9,8 @@ export * from './smartuniverse.classes.universecache'; export * from './smartuniverse.classes.universechannel'; export * from './smartuniverse.classes.universemessage'; +// Reaction Response +export * from './smartuniverse.classes.reactionrequest'; +export * from './smartuniverse.classes.reactionresponse'; + export * from './interfaces'; diff --git a/ts/smartuniverse.classes.clientuniverse.ts b/ts/smartuniverse.classes.clientuniverse.ts index 38f2d3d..d60d9a9 100644 --- a/ts/smartuniverse.classes.clientuniverse.ts +++ b/ts/smartuniverse.classes.clientuniverse.ts @@ -147,7 +147,7 @@ export class ClientUniverse { await this.smartsocketClient.connect(); plugins.smartlog.defaultLogger.log('info', 'universe client connected successfully'); await this.clientUniverseCache.channelMap.forEach(async clientUniverseChannelArg => { - await clientUniverseChannelArg.subscribe(); + await clientUniverseChannelArg.populateSubscriptionToServer(); }); } } diff --git a/ts/smartuniverse.classes.clientuniversechannel.ts b/ts/smartuniverse.classes.clientuniversechannel.ts index 9b71182..7add763 100644 --- a/ts/smartuniverse.classes.clientuniversechannel.ts +++ b/ts/smartuniverse.classes.clientuniversechannel.ts @@ -53,7 +53,17 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel { * subscribes to a channel * tells the universe about this instances interest into a channel */ - public async subscribe(observingFunctionArg?: (messageArg: ClientUniverseMessage) => void) { + public subscribe(observingFunctionArg: (messageArg: ClientUniverseMessage) => void) { + + return this.subject.subscribe( + messageArg => { + observingFunctionArg(messageArg); + }, + error => console.log(error) + ); + } + + public async populateSubscriptionToServer() { // lets make sure the channel is connected if (this.status === 'unsubscribed') { const response = await this.clientUniverseRef.smartsocketClient.serverCall< @@ -64,23 +74,12 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel { }); this.status = response.subscriptionStatus; } - - if (observingFunctionArg) { - return this.subject.subscribe(messageArg => { - observingFunctionArg(messageArg); - },error => console.log); - } } public async emitMessageLocally(messageArg: ClientUniverseMessage) { this.subject.next(messageArg); } - public askForReaction(reactionRequest: ReactionRequest): ReactionResponse { - const reactionResponse = new ReactionResponse(); - return reactionResponse; - } - /** * sends a message towards the server * @param messageArg diff --git a/ts/smartuniverse.classes.reactionrequest.ts b/ts/smartuniverse.classes.reactionrequest.ts index 9e7187f..28487c4 100644 --- a/ts/smartuniverse.classes.reactionrequest.ts +++ b/ts/smartuniverse.classes.reactionrequest.ts @@ -1,3 +1,24 @@ import * as plugins from './smartuniverse.plugins'; -export class ReactionRequest {} +export interface IReactionRequestConstructorOptions { + method: T['method']; +} + +export interface ICombinatorPayload { + /** + * needed for tying responses to requests + */ + id: string; + typedRequestPayload: T; + +} + +export class ReactionRequest { + public method: T['method']; + + constructor(optionsArg: IReactionRequestConstructorOptions) { + this.method = optionsArg.method; + } + + public fireRequest(channelArg) {} +} diff --git a/ts/smartuniverse.classes.reactionresponse.ts b/ts/smartuniverse.classes.reactionresponse.ts index 02154b4..d82e985 100644 --- a/ts/smartuniverse.classes.reactionresponse.ts +++ b/ts/smartuniverse.classes.reactionresponse.ts @@ -1,5 +1,31 @@ import * as plugins from './smartuniverse.plugins'; -export class ReactionResponse { - +import { ICombinatorPayload } from './smartuniverse.classes.reactionrequest'; +import { UniverseChannel } from './smartuniverse.classes.universechannel'; +import { ClientUniverseChannel } from './smartuniverse.classes.clientuniversechannel'; +import { UniverseMessage } from './smartuniverse.classes.universemessage'; +import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage'; + +export interface IReactionResponseConstructorOptions { + method: T['method']; + channels: Array; +} + + +export class ReactionResponse { + public method: T['method']; + public channels = new plugins.lik.Objectmap(); + + constructor(optionsArg: IReactionResponseConstructorOptions) { + this.channels.addArray(optionsArg.channels); + for (const channel of this.channels.getArray()) { + channel.subscribe(messageArg => { + this.processMessageForReaction(messageArg); + }); + } + } + + private processMessageForReaction(messageArg: UniverseMessage | ClientUniverseMessage) { + + } } diff --git a/ts/smartuniverse.classes.universechannel.ts b/ts/smartuniverse.classes.universechannel.ts index 43c7993..6e43caf 100644 --- a/ts/smartuniverse.classes.universechannel.ts +++ b/ts/smartuniverse.classes.universechannel.ts @@ -143,8 +143,13 @@ export class UniverseChannel { } // functions to interact with a channel locally - public async subscribe(observer: plugins.smartrx.rxjs.Observer) { - return this.subject.subscribe(observer); + public subscribe(observingFunctionArg: (messageArg: UniverseMessage) => void) { + return this.subject.subscribe( + messageArg => { + observingFunctionArg(messageArg); + }, + error => console.log(error) + ); } /** diff --git a/ts/smartuniverse.plugins.ts b/ts/smartuniverse.plugins.ts index 1d24080..5e62475 100644 --- a/ts/smartuniverse.plugins.ts +++ b/ts/smartuniverse.plugins.ts @@ -3,6 +3,13 @@ import * as path from 'path'; export { path }; +// apiglobal scope +import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces'; + +export { + typedrequestInterfaces +}; + // pushrocks scope import * as lik from '@pushrocks/lik'; import * as smarthash from '@pushrocks/smarthash';