mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-16 20:49:28 +00:00
30 lines
918 B
TypeScript
30 lines
918 B
TypeScript
|
|
export default async (fastify) => {
|
|
fastify.io.use((socket, next) => {
|
|
const { token } = socket.handshake.auth;
|
|
if (token && fastify.jwt.verify(token)) {
|
|
next();
|
|
} else {
|
|
return next(new Error("unauthorized event"));
|
|
}
|
|
});
|
|
fastify.io.on('connection', (socket: any) => {
|
|
const { token } = socket.handshake.auth;
|
|
const { teamId } = fastify.jwt.decode(token);
|
|
socket.join(teamId);
|
|
console.info('Socket connected!', socket.id)
|
|
console.info('Socket joined team!', teamId)
|
|
socket.on('message', (message) => {
|
|
console.log(message)
|
|
})
|
|
socket.on('error', (err) => {
|
|
console.log(err)
|
|
})
|
|
})
|
|
// fastify.io.on("error", (err) => {
|
|
// if (err && err.message === "unauthorized event") {
|
|
// fastify.io.disconnect();
|
|
// }
|
|
// });
|
|
}
|