Skip to content

Commit

Permalink
feat(alwaysuri): Always push called URI into Callee/Event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
martin31821 committed Nov 26, 2019
1 parent 4491933 commit 84d780c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/generic/Callee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '../logging/Logger';
import { CallHandler, CallResult, IRegistration, LogLevel } from '../types/Connection';

import { InvocationDetails, WampYieldMessage } from '../types/messages/CallMessage';
import { EWampMessageID, WampDict, WampID, WampList } from '../types/messages/MessageTypes';
import { EWampMessageID, WampDict, WampID, WampList, WampURI } from '../types/messages/MessageTypes';
import {
RegisterOptions,
WampRegisteredMessage,
Expand All @@ -21,6 +21,7 @@ class Registration implements IRegistration {
public onUnregistered = new Deferred<void>();
constructor(
private id: WampID,
public readonly uri: WampURI,
public handler: CallHandler<WampList, WampDict, WampList, WampDict>,
private unregister: (reg: Registration) => Promise<void>,
) {
Expand Down Expand Up @@ -191,7 +192,7 @@ export class Callee extends MessageProcessor {
await this.sender(msg);
const registered = await reg;
const regID = registered[2];
const registration = new Registration(regID, handler as any, async id => await this.unregister(id));
const registration = new Registration(regID, uri, handler as any, async id => await this.unregister(id));
this.currentRegistrations.set(regID, registration);
return registration;
}
Expand Down Expand Up @@ -231,6 +232,10 @@ export class Callee extends MessageProcessor {
this.violator('unexpected INVOCATION');
return true;
}
const actualDetails = details || {};
if (!actualDetails.procedure) {
actualDetails.procedure = reg.uri;
}
const call = new Call(
reg.handler, // Call Handler function
args || [], // Args or empty array
Expand Down
11 changes: 9 additions & 2 deletions src/generic/Subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ class MultiSubscription {
public onUnsubscribed: Deferred<void>;
private handlers = new Map<WampID, Subscription>();
private unsubscribed = false;
constructor(public subscriptionID: WampID, private unsubscribe: (sub: MultiSubscription) => Promise<void>) {
constructor(
public subscriptionID: WampID,
public readonly uri: WampURI,
private unsubscribe: (sub: MultiSubscription) => Promise<void>,
) {
this.onUnsubscribed = new Deferred<void>();
this.reinitCatch();
}
Expand Down Expand Up @@ -163,7 +167,7 @@ export class Subscriber extends MessageProcessor {

let subscriptionWrapper = this.currentSubscriptions.get(subId);
if (!subscriptionWrapper) {
subscriptionWrapper = new MultiSubscription(subId, async sub => await this.sendUnsubscribe(sub));
subscriptionWrapper = new MultiSubscription(subId, topic, async sub => await this.sendUnsubscribe(sub));
this.currentSubscriptions.set(subId, subscriptionWrapper);
}
return new Subscription(handler as EventHandler<WampList, WampDict>, requestID, subscriptionWrapper, this.logger);
Expand Down Expand Up @@ -199,6 +203,9 @@ export class Subscriber extends MessageProcessor {
this.logger.log(LogLevel.DEBUG, `Subscription ID: ${subId}, Received Event`);
const details = msg[3];
details.publicationId = msg[2];
if (!details.topic) {
details.topic = subscription.uri;
}
subscription.trigger(msg[4] || [], msg[5] || {}, details);

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/types/messages/CallMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EWampMessageID, WampID, WampURI, WampDict, WampList } from './MessageTypes';
import { EWampMessageID, WampDict, WampID, WampList, WampURI } from './MessageTypes';

export enum ECallRunMode {
PARTITION = 'partition',
Expand Down Expand Up @@ -27,7 +27,7 @@ export type CancelOptions = {
} & WampDict;

export type InvocationDetails = {
procedure?: string;
procedure: string;
receive_progress?: boolean;
caller?: WampID;
caller_authid?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/types/messages/SubscribeMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WampDict, EMatchPolicy, EWampMessageID, WampList, WampID, WampURI } from './MessageTypes';
import { EMatchPolicy, EWampMessageID, WampDict, WampID, WampList, WampURI } from './MessageTypes';

export type SubscribeOptions = {
nkey?: string;
Expand All @@ -10,7 +10,7 @@ export type EventDetails = {
publisher_authid?: string;
publisher_authrole?: string | string[];
trustlevel?: number;
topic?: WampURI;
topic: WampURI;
retained?: boolean;
publicationId?: WampID;
} & WampDict;
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"max-classes-per-file": [true, 3, "exclude-class-expressions"],
"object-literal-sort-keys": false,
"whitespace": [true, "check-branch", "check-decl", "check-operator", "check-module", "check-separator", "check-type", "check-type-operators", "check-preblock"],
"callable-types": false
"callable-types": false,
"max-line-length": [true, 140]
}
}

0 comments on commit 84d780c

Please sign in to comment.