fix(core): update
This commit is contained in:
@ -4,7 +4,5 @@ import * as plugins from './smartuniverse.plugins';
|
||||
* broadcasts an event to multiple channels
|
||||
*/
|
||||
export class BroadcastEvent<T> {
|
||||
fire() {
|
||||
|
||||
}
|
||||
};
|
||||
fire() {}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
export class BroadcastSUbscription {
|
||||
|
||||
}
|
||||
export class BroadcastSUbscription {}
|
||||
|
@ -98,7 +98,7 @@ export class ClientUniverse {
|
||||
this.smartsocketClient = new SmartsocketClient(socketConfig);
|
||||
|
||||
this.smartsocketClient.eventSubject.subscribe(async eventArg => {
|
||||
switch(eventArg) {
|
||||
switch (eventArg) {
|
||||
case 'disconnected':
|
||||
this.disconnect('upstreamEvent');
|
||||
}
|
||||
@ -165,7 +165,10 @@ export class ClientUniverse {
|
||||
}
|
||||
}
|
||||
|
||||
public async disconnect(reason: 'upstreamEvent' | 'triggered' = 'triggered', tryReconnect = false) {
|
||||
public async disconnect(
|
||||
reason: 'upstreamEvent' | 'triggered' = 'triggered',
|
||||
tryReconnect = false
|
||||
) {
|
||||
if (reason === 'triggered') {
|
||||
const smartsocketToDisconnect = this.smartsocketClient;
|
||||
this.smartsocketClient = null; // making sure the upstreamEvent does not interfere
|
||||
|
@ -54,7 +54,6 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
||||
* tells the universe about this instances interest into a channel
|
||||
*/
|
||||
public subscribe(observingFunctionArg: (messageArg: ClientUniverseMessage<any>) => void) {
|
||||
|
||||
return this.subject.subscribe(
|
||||
messageArg => {
|
||||
observingFunctionArg(messageArg);
|
||||
|
@ -5,7 +5,9 @@ import { ReactionResult } from './smartuniverse.classes.reactionresult';
|
||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
|
||||
|
||||
export interface IReactionRequestConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||
export interface IReactionRequestConstructorOptions<
|
||||
T extends plugins.typedrequestInterfaces.ITypedRequest
|
||||
> {
|
||||
method: T['method'];
|
||||
}
|
||||
|
||||
@ -15,9 +17,9 @@ export interface ICombinatorPayload<T extends plugins.typedrequestInterfaces.ITy
|
||||
*/
|
||||
id: string;
|
||||
typedRequestPayload: {
|
||||
method: T['method'],
|
||||
request : T['request'],
|
||||
response: T['response']
|
||||
method: T['method'];
|
||||
request: T['request'];
|
||||
response: T['response'];
|
||||
};
|
||||
}
|
||||
|
||||
@ -28,20 +30,35 @@ export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequ
|
||||
this.method = optionsArg.method;
|
||||
}
|
||||
|
||||
public async fire(channelsArg: Array<UniverseChannel | ClientUniverseChannel>, requestDataArg: T['request'], timeoutMillisArg=5000) {
|
||||
public async fire(
|
||||
channelsArg: Array<UniverseChannel | ClientUniverseChannel>,
|
||||
requestDataArg: T['request'],
|
||||
timeoutMillisArg = 5000
|
||||
) {
|
||||
const subscriptionMap = new plugins.lik.Objectmap<plugins.smartrx.rxjs.Subscription>();
|
||||
const reactionResult = new ReactionResult<T>();
|
||||
const requestId = plugins.smartunique.shortId();
|
||||
for (const channel of channelsArg) {
|
||||
subscriptionMap.add(channel.subscribe((messageArg: UniverseMessage<ICombinatorPayload<T>> | ClientUniverseMessage<ICombinatorPayload<T>>) => {
|
||||
if (messageArg.messageText === 'reactionResponse' && messageArg.payload.typedRequestPayload.method === this.method) {
|
||||
const payload: ICombinatorPayload<T> = messageArg.payload;
|
||||
if (payload.id !== requestId) {
|
||||
return;
|
||||
subscriptionMap.add(
|
||||
channel.subscribe(
|
||||
(
|
||||
messageArg:
|
||||
| UniverseMessage<ICombinatorPayload<T>>
|
||||
| ClientUniverseMessage<ICombinatorPayload<T>>
|
||||
) => {
|
||||
if (
|
||||
messageArg.messageText === 'reactionResponse' &&
|
||||
messageArg.payload.typedRequestPayload.method === this.method
|
||||
) {
|
||||
const payload: ICombinatorPayload<T> = messageArg.payload;
|
||||
if (payload.id !== requestId) {
|
||||
return;
|
||||
}
|
||||
reactionResult.pushReactionResponse(payload.typedRequestPayload.response);
|
||||
}
|
||||
}
|
||||
reactionResult.pushReactionResponse(payload.typedRequestPayload.response);
|
||||
}
|
||||
}));
|
||||
)
|
||||
);
|
||||
const payload: ICombinatorPayload<T> = {
|
||||
id: requestId,
|
||||
typedRequestPayload: {
|
||||
|
@ -6,7 +6,9 @@ import { ClientUniverseChannel } from './smartuniverse.classes.clientuniversecha
|
||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
|
||||
|
||||
export type TReactionResponseFuncDef<T extends plugins.typedrequestInterfaces.ITypedRequest> = (dataArg: T['request']) => Promise<T['response']>;
|
||||
export type TReactionResponseFuncDef<T extends plugins.typedrequestInterfaces.ITypedRequest> = (
|
||||
dataArg: T['request']
|
||||
) => Promise<T['response']>;
|
||||
|
||||
export interface IReactionResponseConstructorOptions<
|
||||
T extends plugins.typedrequestInterfaces.ITypedRequest
|
||||
@ -42,7 +44,9 @@ export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedReq
|
||||
messageArg.messageText === 'reactionRequest' &&
|
||||
messageArg.payload.typedRequestPayload.method === this.method
|
||||
) {
|
||||
const response: T['response'] = await this.funcDef(messageArg.payload.typedRequestPayload.request);
|
||||
const response: T['response'] = await this.funcDef(
|
||||
messageArg.payload.typedRequestPayload.request
|
||||
);
|
||||
const payload: ICombinatorPayload<T> = {
|
||||
...messageArg.payload,
|
||||
typedRequestPayload: {
|
||||
@ -52,7 +56,7 @@ export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedReq
|
||||
};
|
||||
channelArg.sendMessage({
|
||||
messageText: 'reactionResponse',
|
||||
payload
|
||||
payload
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
|
||||
private endResult: Array<T['response']> = [];
|
||||
private completeDeferred = plugins.smartpromise.defer<Array<T['response']>>();
|
||||
|
||||
constructor () {
|
||||
constructor() {
|
||||
this.resultSubscribe(responseArg => {
|
||||
this.endResult.push(responseArg);
|
||||
});
|
||||
@ -42,7 +42,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
|
||||
public async pushReactionResponse(responseArg: T['response']) {
|
||||
this.resultReplaySubject.next(responseArg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* completes the ReactionResult
|
||||
*/
|
||||
|
@ -78,12 +78,14 @@ export class UniverseMessage<T> implements interfaces.IUniverseMessage {
|
||||
this.destructionTimer = new Timer(selfdestructAfterArg);
|
||||
this.destructionTimer.start();
|
||||
// set up self destruction by removing this from the parent messageCache
|
||||
this.destructionTimer.completed.then(async () => {
|
||||
this.universeCache.messageMap.remove(this);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
console.log(this);
|
||||
});
|
||||
this.destructionTimer.completed
|
||||
.then(async () => {
|
||||
this.universeCache.messageMap.remove(this);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
console.log(this);
|
||||
});
|
||||
} else {
|
||||
plugins.smartdelay.delayFor(1000).then(() => {
|
||||
if (!this.destructionTimer) {
|
||||
|
@ -6,9 +6,7 @@ export { path };
|
||||
// apiglobal scope
|
||||
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||
|
||||
export {
|
||||
typedrequestInterfaces
|
||||
};
|
||||
export { typedrequestInterfaces };
|
||||
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
|
Reference in New Issue
Block a user