Compare commits

..

8 Commits

Author SHA1 Message Date
c2052f16a8 1.0.80 2019-09-10 19:36:11 +02:00
ff7cdc908c fix(core): update 2019-09-10 19:36:10 +02:00
f3d41b8719 1.0.79 2019-09-10 18:03:47 +02:00
f9f0fc45e2 fix(core): update 2019-09-10 18:03:46 +02:00
da6b7724b8 1.0.78 2019-09-10 10:55:11 +02:00
be7ca29e4b fix(core): update 2019-09-10 10:55:10 +02:00
f401d78c4b 1.0.77 2019-09-10 10:51:18 +02:00
6ceec0201f fix(core): update 2019-09-10 10:51:18 +02:00
14 changed files with 116 additions and 47 deletions

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.76",
"version": "1.0.80",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -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": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.76",
"version": "1.0.80",
"private": false,
"description": "messaging service for your micro services",
"main": "dist/index.js",
@ -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",

View File

@ -69,9 +69,22 @@ tap.test('a second client should be able to subscibe', async () => {
});
testClientUniverse2.addChannel(testChannelData.channelName, testChannelData.channelPass);
await testClientUniverse2.start();
});
tap.test('should receive a message correctly', async () => {});
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 = testChannel2.subscribe(messageArg => {
console.log('Yay##########');
done.resolve();
});
await testChannel.sendMessage({
messageText: 'hellothere'
});
await done.promise;
});
tap.test('should disconnect the client correctly', async () => {
await testClientUniverse.stop();

View File

@ -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';

View File

@ -7,7 +7,7 @@ export interface ISocketRequest_SubscribeChannel {
passphrase: string;
};
response: {
subscriptionStatus: 'subscribed' | 'unsubscribed'
subscriptionStatus: 'subscribed' | 'unsubscribed';
};
}
@ -15,6 +15,6 @@ export interface ISocketRequest_ProcessMessage {
method: 'processMessage';
request: interfaces.IUniverseMessage;
response: {
messageStatus: 'ok' | 'channel not found'
messageStatus: 'ok' | 'channel not found';
};
}

View File

@ -1,10 +1,3 @@
export type IServerCallActions =
| 'channelSubscription'
| 'processMessage'
| 'channelUnsubscribe'
| 'terminateConnection';
export interface IServerUnsubscribeActionPayload {
name: string;
}

View File

@ -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();
});
}
}

View File

@ -53,34 +53,33 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
* subscribes to a channel
* tells the universe about this instances interest into a channel
*/
public async subscribe(observerArg?: plugins.smartrx.rxjs.Observer<any>) {
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<interfaces.ISocketRequest_SubscribeChannel>(
'subscribeChannel',
{
const response = await this.clientUniverseRef.smartsocketClient.serverCall<
interfaces.ISocketRequest_SubscribeChannel
>('subscribeChannel', {
name: this.name,
passphrase: this.passphrase
}
);
});
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;
}
/**
* sends a message towards the server
* @param messageArg

View File

@ -1,5 +1,24 @@
import * as plugins from './smartuniverse.plugins';
export class ReactionRequest {
export interface IReactionRequestConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
method: T['method'];
}
export interface ICombinatorPayload<T extends plugins.typedrequestInterfaces.ITypedRequest> {
/**
* needed for tying responses to requests
*/
id: string;
typedRequestPayload: T;
}
export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequest> {
public method: T['method'];
constructor(optionsArg: IReactionRequestConstructorOptions<T>) {
this.method = optionsArg.method;
}
public fireRequest(channelArg) {}
}

View File

@ -1,3 +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<T extends plugins.typedrequestInterfaces.ITypedRequest> {
method: T['method'];
channels: Array<UniverseChannel | ClientUniverseChannel>;
}
export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedRequest> {
public method: T['method'];
public channels = new plugins.lik.Objectmap<UniverseChannel | ClientUniverseChannel>();
constructor(optionsArg: IReactionResponseConstructorOptions<T>) {
this.channels.addArray(optionsArg.channels);
for (const channel of this.channels.getArray()) {
channel.subscribe(messageArg => {
this.processMessageForReaction(messageArg);
});
}
}
private processMessageForReaction(messageArg: UniverseMessage | ClientUniverseMessage) {
}
}

View File

@ -72,7 +72,7 @@ export class Universe {
return this.universeCache.channelMap.find(channelArg => {
return channelArg.name === channelNameArg;
});
};
}
/**
* initiates a server
@ -105,13 +105,12 @@ export class Universe {
// add the role to smartsocket
this.smartsocket.addSocketRoles([ClientRole]);
const socketFunctionSubscription = new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_SubscribeChannel>({
const socketFunctionSubscription = new plugins.smartsocket.SocketFunction<
interfaces.ISocketRequest_SubscribeChannel
>({
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
funcName: 'subscribeChannel',
funcDef: async (
dataArg,
socketConnectionArg
) => {
funcDef: async (dataArg, socketConnectionArg) => {
const universeConnection = new UniverseConnection({
socketConnection: socketConnectionArg,
authenticationRequests: [dataArg]

View File

@ -117,7 +117,7 @@ export class UniverseChannel {
public async push(messageArg: UniverseMessage) {
this.subject.next(messageArg);
const universeConnectionsWithChannelAccess: UniverseConnection[] = [];
this.universeRef.universeCache.connectionMap.forEach(async socketConnection => {
await this.universeRef.universeCache.connectionMap.forEach(async socketConnection => {
if (socketConnection.authenticatedChannels.includes(this)) {
universeConnectionsWithChannelAccess.push(socketConnection);
}
@ -143,8 +143,13 @@ export class UniverseChannel {
}
// functions to interact with a channel locally
public async subscribe(observer: plugins.smartrx.rxjs.Observer<any>) {
return this.subject.subscribe(observer);
public subscribe(observingFunctionArg: (messageArg: UniverseMessage) => void) {
return this.subject.subscribe(
messageArg => {
observingFunctionArg(messageArg);
},
error => console.log(error)
);
}
/**

View File

@ -26,6 +26,7 @@ export class UniverseConnection {
universeConnection
);
universeRef.universeCache.connectionMap.add(universeConnection);
console.log('hi')
}
/**

View File

@ -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';