Skip to content

Commit

Permalink
fix: check subscription id on incoming events
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Jul 26, 2024
1 parent e00c717 commit 44c66ae
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class WmClient {
events: T,
callback: SubscribeCallback<T[number]>,
): Promise<UnlistenFn> {
const response = await this._sendAndWaitReply<{
const { subscriptionId } = await this._sendAndWaitReply<{
subscriptionId: string;
}>(`sub --events ${events.join(' ')}`);

Expand All @@ -196,7 +196,7 @@ export class WmClient {

const isSubscribedEvent =
serverMessage.messageType === 'event_subscription' &&
events.includes(serverMessage.data?.type!);
serverMessage.subscriptionId === subscriptionId;

if (isSubscribedEvent) {
callback(serverMessage.data as WmEventData<T[number]>);
Expand All @@ -207,7 +207,7 @@ export class WmClient {
unlisten();

await this._sendAndWaitReply<{ subscriptionId: string }>(
`unsub --id ${response.subscriptionId}`,
`unsub --id ${subscriptionId}`,
);
};
}
Expand Down

0 comments on commit 44c66ae

Please sign in to comment.