(
socket: WebSocket,
req: FastifyRequest<{
Params: {
projectId: string;
};
}>
)
| 18 | } |
| 19 | |
| 20 | export function wsVisitors( |
| 21 | socket: WebSocket, |
| 22 | req: FastifyRequest<{ |
| 23 | Params: { |
| 24 | projectId: string; |
| 25 | }; |
| 26 | }> |
| 27 | ) { |
| 28 | guardSocket(socket, req); |
| 29 | const { params } = req; |
| 30 | const sendCount = () => { |
| 31 | eventBuffer |
| 32 | .getActiveVisitorCount(params.projectId) |
| 33 | .then((count) => { |
| 34 | socket.send(String(count)); |
| 35 | }) |
| 36 | .catch(() => { |
| 37 | socket.send('0'); |
| 38 | }); |
| 39 | }; |
| 40 | |
| 41 | const unsubscribe = subscribeToPublishedEvent( |
| 42 | 'events', |
| 43 | 'batch', |
| 44 | ({ projectId }) => { |
| 45 | if (projectId === params.projectId) { |
| 46 | sendCount(); |
| 47 | } |
| 48 | } |
| 49 | ); |
| 50 | |
| 51 | socket.on('close', () => { |
| 52 | unsubscribe(); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | export async function wsProjectEvents( |
| 57 | socket: WebSocket, |
nothing calls this directly
no test coverage detected