mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 02:24:17 +00:00
added experimentation with events
This commit is contained in:
parent
92943f8203
commit
b94e18fdd0
21
server/src/classes/rtengineng/event.js
Normal file
21
server/src/classes/rtengineng/event.js
Normal file
@ -0,0 +1,21 @@
|
||||
export default class WSEvent {
|
||||
constructor(fn, middlewares = []) {
|
||||
this.fn = fn
|
||||
this.middlewares = middlewares
|
||||
}
|
||||
|
||||
execute = async (socket, body) => {
|
||||
try {
|
||||
// execute middlewares
|
||||
for await (const middleware of this.middlewares) {
|
||||
await middleware(socket, body)
|
||||
}
|
||||
|
||||
await this.fn(socket, body)
|
||||
} catch (error) {
|
||||
await this.onError(socket, body, error)
|
||||
}
|
||||
}
|
||||
|
||||
onError = async (socket, body, error) => {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user