MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / on

Method on

packages/message/server.ts:263–287  ·  view source on GitHub ↗
(name: string, func: ApiFunction)

Source from the content-addressed store, hash-verified

261 }
262
263 on(name: string, func: ApiFunction) {
264 const fullName = `${this.name}${name}`;
265
266 if (this.middlewares.length === 0) {
267 // 没有中间件,直接注册
268 this.server.on(fullName, func);
269 } else {
270 // 有中间件,需要包装处理函数
271 this.server.on(fullName, async (params: any, con: IGetSender) => {
272 let index = 0;
273
274 const next = async (): Promise<any> => {
275 if (index < this.middlewares.length) {
276 const middleware = this.middlewares[index++];
277 return await middleware(params, con, next);
278 } else {
279 // 所有中间件都执行完毕,执行最终的处理函数
280 return await func(params, con);
281 }
282 };
283
284 return await next();
285 });
286 }
287 }
288}
289
290// 转发消息

Callers 15

subscribeMethod · 0.45
onMessageMethod · 0.45
onConnectMethod · 0.45
onMessageMethod · 0.45
forwardMessageFunction · 0.45
server.test.tsFile · 0.45
utils.test.tsFile · 0.45
addListenerMethod · 0.45
watchLanguageChangeFunction · 0.45
initMethod · 0.45

Calls 1

nextFunction · 0.85

Tested by 5

runAndCaptureFunction · 0.36
autoApprovePermissionsFunction · 0.36
runTestScriptFunction · 0.36
runXhrFunction · 0.36
createMockWSServerFunction · 0.36