(
socket: WebSocket,
req: FastifyRequest<{
Params: {
projectId: string;
};
Querystring: {
token?: string;
};
}>
)
| 54 | } |
| 55 | |
| 56 | export async function wsProjectEvents( |
| 57 | socket: WebSocket, |
| 58 | req: FastifyRequest<{ |
| 59 | Params: { |
| 60 | projectId: string; |
| 61 | }; |
| 62 | Querystring: { |
| 63 | token?: string; |
| 64 | }; |
| 65 | }> |
| 66 | ) { |
| 67 | guardSocket(socket, req); |
| 68 | const { params } = req; |
| 69 | |
| 70 | const userId = req.session?.userId; |
| 71 | if (!userId) { |
| 72 | socket.send('No active session'); |
| 73 | socket.close(); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | const access = await getProjectAccess({ |
| 78 | userId, |
| 79 | projectId: params.projectId, |
| 80 | }); |
| 81 | |
| 82 | if (!access) { |
| 83 | socket.send('No access'); |
| 84 | socket.close(); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | const unsubscribe = subscribeToPublishedEvent( |
| 89 | 'events', |
| 90 | 'batch', |
| 91 | ({ projectId, count }) => { |
| 92 | if (projectId === params.projectId) { |
| 93 | socket.send(setSuperJson({ count })); |
| 94 | } |
| 95 | } |
| 96 | ); |
| 97 | |
| 98 | socket.on('close', () => unsubscribe()); |
| 99 | } |
| 100 | |
| 101 | export async function wsProjectNotifications( |
| 102 | socket: WebSocket, |
nothing calls this directly
no test coverage detected