fix(core): update
This commit is contained in:
parent
03fbab5265
commit
e12b128619
@ -14,7 +14,11 @@ export interface ICombinatorPayload<T extends plugins.typedrequestInterfaces.ITy
|
|||||||
* needed for tying responses to requests
|
* needed for tying responses to requests
|
||||||
*/
|
*/
|
||||||
id: string;
|
id: string;
|
||||||
typedRequestPayload: T;
|
typedRequestPayload: {
|
||||||
|
method: T['method'],
|
||||||
|
request : T['request'],
|
||||||
|
response: T['response']
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
|
@ -6,26 +6,54 @@ import { ClientUniverseChannel } from './smartuniverse.classes.clientuniversecha
|
|||||||
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
|
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
|
||||||
|
|
||||||
export interface IReactionResponseConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
export type TReactionResponseFuncDef<T extends plugins.typedrequestInterfaces.ITypedRequest> = (dataArg: T['request']) => Promise<T['response']>;
|
||||||
|
|
||||||
|
export interface IReactionResponseConstructorOptions<
|
||||||
|
T extends plugins.typedrequestInterfaces.ITypedRequest
|
||||||
|
> {
|
||||||
method: T['method'];
|
method: T['method'];
|
||||||
channels: Array<UniverseChannel | ClientUniverseChannel>;
|
channels: Array<UniverseChannel | ClientUniverseChannel>;
|
||||||
|
funcDef: TReactionResponseFuncDef<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
public method: T['method'];
|
public method: T['method'];
|
||||||
public channels = new plugins.lik.Objectmap<UniverseChannel | ClientUniverseChannel>();
|
public channels = new plugins.lik.Objectmap<UniverseChannel | ClientUniverseChannel>();
|
||||||
|
public funcDef: TReactionResponseFuncDef<T>;
|
||||||
|
|
||||||
constructor(optionsArg: IReactionResponseConstructorOptions<T>) {
|
constructor(optionsArg: IReactionResponseConstructorOptions<T>) {
|
||||||
|
this.method = optionsArg.method;
|
||||||
this.channels.addArray(optionsArg.channels);
|
this.channels.addArray(optionsArg.channels);
|
||||||
|
this.funcDef = optionsArg.funcDef;
|
||||||
for (const channel of this.channels.getArray()) {
|
for (const channel of this.channels.getArray()) {
|
||||||
channel.subscribe(messageArg => {
|
channel.subscribe(messageArg => {
|
||||||
this.processMessageForReaction(messageArg);
|
this.processMessageForReaction(channel, messageArg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private processMessageForReaction(messageArg: UniverseMessage<ICombinatorPayload<T>> | ClientUniverseMessage<ICombinatorPayload<T>>) {
|
private async processMessageForReaction(
|
||||||
|
channelArg: UniverseChannel | ClientUniverseChannel,
|
||||||
|
messageArg:
|
||||||
|
| UniverseMessage<ICombinatorPayload<T>>
|
||||||
|
| ClientUniverseMessage<ICombinatorPayload<T>>
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
messageArg.messageText === 'reactionRequest' &&
|
||||||
|
messageArg.payload.typedRequestPayload.method === this.method
|
||||||
|
) {
|
||||||
|
const response: T['response'] = await this.funcDef(messageArg.payload.typedRequestPayload.request);
|
||||||
|
const payload: ICombinatorPayload<T> = {
|
||||||
|
...messageArg.payload,
|
||||||
|
typedRequestPayload: {
|
||||||
|
...messageArg.payload.typedRequestPayload,
|
||||||
|
response
|
||||||
|
}
|
||||||
|
};
|
||||||
|
channelArg.sendMessage({
|
||||||
|
messageText: 'reactionResponse',
|
||||||
|
payload
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user