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

Function wsProjectEvents

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

Source from the content-addressed store, hash-verified

54}
55
56export 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
101export async function wsProjectNotifications(
102 socket: WebSocket,

Callers

nothing calls this directly

Calls 5

setSuperJsonFunction · 0.90
guardSocketFunction · 0.85
closeMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected