Skip to content

Commit

Permalink
fix: resolved this being undefined in plugin bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Mar 24, 2024
1 parent f535bc4 commit 63077c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions packages/common/src/interfaces/plugin.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ export interface HandleMessagePlugin {
* @param ctx The client context
* @param message The incoming message
* @param next The next function to call the next plugin
* @returns The result of the message handling
*/
handleMessage(
ctx: ClientContext,
message: IncomingMessage,
next: () => Promise<HandleMessageResult>,
): Promise<HandleMessageResult> | HandleMessageResult;
): Promise<HandleMessageResult>;
}

/**
Expand All @@ -72,11 +71,10 @@ export interface BroadcastPlugin {
* @param ctx The client context
* @param event The event to broadcast
* @param next The next function to call the next plugin
* @returns void
*/
broadcast(
ctx: ClientContext,
event: Event,
next: () => Promise<void>,
): Promise<void> | void;
): Promise<void>;
}
10 changes: 6 additions & 4 deletions packages/core/src/services/plugin-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ export class PluginManagerService {
return Promise.reject(new Error('next() called multiple times'));
}
index = i;
const fn = plugins[i]?.[funcName];
if (!fn) {
return next(...args);
const plugin = plugins[i];
if (!plugin || !plugin[funcName]) {
return Promise.resolve(next(...args));
}
return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
return Promise.resolve(
plugin[funcName](...args, dispatch.bind(null, i + 1)),
);
}
}

Expand Down

0 comments on commit 63077c5

Please sign in to comment.