2022-08-10 10:09:02 -05:00
|
|
|
export const hooks = {
|
|
|
|
/**
|
|
|
|
* Modify Socket.io client configuration.
|
|
|
|
*
|
|
|
|
* See: https://socket.io/docs/v4/client-options/
|
|
|
|
*/
|
|
|
|
'@flecks/socket.client': () => ({
|
|
|
|
timeout: Infinity,
|
|
|
|
}),
|
2024-01-27 09:16:47 -06:00
|
|
|
|
2022-08-10 10:09:02 -05:00
|
|
|
/**
|
|
|
|
* Define server-side intercom channels.
|
|
|
|
*/
|
|
|
|
'@flecks/socket.intercom': (req) => ({
|
|
|
|
// This would have been called like:
|
2024-01-06 16:20:05 -06:00
|
|
|
// `const result = await req.intercom('@my/fleck.key', payload)`.
|
2022-08-10 10:09:02 -05:00
|
|
|
// `result` will be an `n`-length array, where `n` is the number of server instances. Each
|
|
|
|
// element in the array will be the result of `someServiceSpecificInformation()` running
|
|
|
|
// against that server instance.
|
2024-01-06 16:20:05 -06:00
|
|
|
'@my/fleck.key': async (payload, server) => {
|
2022-08-10 10:09:02 -05:00
|
|
|
return someServiceSpecificInformation();
|
2022-03-07 00:21:16 -06:00
|
|
|
},
|
2022-08-10 10:09:02 -05:00
|
|
|
}),
|
2024-01-27 09:16:47 -06:00
|
|
|
|
2022-08-10 10:09:02 -05:00
|
|
|
/**
|
|
|
|
* Define socket packets.
|
|
|
|
*
|
|
|
|
* In the example below, your fleck would have a `packets` subdirectory, and each
|
|
|
|
* decorator would be defined in its own file.
|
|
|
|
* See: https://github.com/cha0s/flecks/tree/master/packages/redux/src/packets
|
|
|
|
*
|
|
|
|
* See: https://github.com/cha0s/flecks/tree/master/packages/socket/src/packet/packet.js
|
|
|
|
* See: https://github.com/cha0s/flecks/tree/master/packages/socket/src/packet/redirect.js
|
|
|
|
*/
|
|
|
|
'@flecks/socket.packets': Flecks.provide(require.context('./packets', false, /\.js$/)),
|
2024-01-27 09:16:47 -06:00
|
|
|
|
2022-08-10 10:09:02 -05:00
|
|
|
/**
|
|
|
|
* Decorate database models.
|
|
|
|
*
|
|
|
|
* In the example below, your fleck would have a `packets/decorators` subdirectory, and each
|
|
|
|
* decorator would be defined in its own file.
|
|
|
|
* @param {constructor} Packet The packet to decorate.
|
|
|
|
*/
|
|
|
|
'@flecks/socket.packets.decorate': (
|
|
|
|
Flecks.decorate(require.context('./packets/decorators', false, /\.js$/))
|
|
|
|
),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify Socket.io server configuration.
|
|
|
|
*
|
|
|
|
* See: https://socket.io/docs/v4/server-options/
|
|
|
|
*/
|
|
|
|
'@flecks/socket.server': () => ({
|
|
|
|
pingTimeout: Infinity,
|
|
|
|
}),
|
2024-01-27 09:16:47 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do something with a connecting socket.
|
|
|
|
*
|
|
|
|
* @param {[ServerSocket](https://github.com/cha0s/flecks/blob/master/packages/socket/src/server/socket.js)} socket The connecting socket.
|
|
|
|
*/
|
|
|
|
'@flecks/socket/server.connect': (socket) => {
|
|
|
|
socket.on('disconnect', () => {
|
|
|
|
// ...
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Socket.IO instance.
|
|
|
|
*
|
|
|
|
* See: https://socket.io/docs/v4/server-instance/
|
|
|
|
* @param {SocketIo} io The Socket.IO server instance.
|
|
|
|
*/
|
|
|
|
'@flecks/socket/server.io': (io) => {
|
|
|
|
io.engine.on("headers", (headers, req) => {
|
|
|
|
headers["test"] = "789";
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2022-08-10 10:09:02 -05:00
|
|
|
/**
|
|
|
|
* Define middleware to run when a socket connection is established.
|
|
|
|
*/
|
|
|
|
'@flecks/socket/server.request.socket': () => (socket, next) => {
|
|
|
|
// Express-style route middleware...
|
|
|
|
next();
|
2022-03-07 00:21:16 -06:00
|
|
|
},
|
2024-01-27 09:16:47 -06:00
|
|
|
|
2022-03-07 00:21:16 -06:00
|
|
|
};
|
|
|
|
|