MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / wsVisitors

Function wsVisitors

apps/api/src/controllers/live.controller.ts:20–54  ·  view source on GitHub ↗
(
  socket: WebSocket,
  req: FastifyRequest<{
    Params: {
      projectId: string;
    };
  }>
)

Source from the content-addressed store, hash-verified

18}
19
20export 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
56export async function wsProjectEvents(
57 socket: WebSocket,

Callers

nothing calls this directly

Calls 3

guardSocketFunction · 0.85
sendCountFunction · 0.85

Tested by

no test coverage detected