Compare commits

..

4 Commits

Author SHA1 Message Date
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
11 changed files with 40 additions and 34 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.77",
"version": "1.0.79",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.77",
"version": "1.0.79",
"private": false,
"description": "messaging service for your micro services",
"main": "dist/index.js",

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 = await 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

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

@ -53,23 +53,23 @@ 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 async subscribe(observingFunctionArg?: (messageArg: ClientUniverseMessage) => void) {
// lets make sure the channel is connected
if (this.status === 'unsubscribed') {
const response = await this.clientUniverseRef.smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
'subscribeChannel',
{
name: this.name,
passphrase: this.passphrase
}
);
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);
if (observingFunctionArg) {
return this.subject.subscribe(messageArg => {
observingFunctionArg(messageArg);
},error => console.log);
}
}
public async emitMessageLocally(messageArg: ClientUniverseMessage) {

View File

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

View File

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

View File

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

View File

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