-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
27 lines (27 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export default function registerHook(_, { emitter }) {
emitter.onFilter('websocket.register', (registerHandler) => {
registerHandler((_, context) => {
const {
services: { ItemsService },
database: knex, getSchema
} = context;
return {
parseMessage(message) {
if (message.type !== "EXAMPLE") return;
return message;
},
async onMessage(client, message) {
// simply does exactly the same as the GET handler
const service = new ItemsService(message.collection, {
knex, schema: await getSchema(),
accountability: client.accountability
});
const result = await service.readByQuery(message.query);
const msg = { type: 'RESPONSE', data: result };
if (message?.uid) msg.uid = message.uid;
client.socket.send(JSON.stringify(msg));
},
};
});
});
}