improve event list / event details

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-08 22:55:48 +01:00
parent 8b346f8466
commit 22a37b698d
19 changed files with 834 additions and 790 deletions

View File

@@ -249,6 +249,7 @@ export async function postEvent(
if (duration < 0) {
contextLogger.send('duration is wrong', {
payload,
duration,
});
} else {
// Skip update duration if it's wrong
@@ -270,6 +271,7 @@ export async function postEvent(
} else if (payload.name !== 'screen_view') {
contextLogger.send('no previous job', {
prevEventJob,
payload,
});
}

View File

@@ -78,3 +78,32 @@ export function wsVisitors(
redisSub.off('pmessage', pmessage);
});
}
export function wsEvents(
connection: {
socket: WebSocket;
},
req: FastifyRequest<{
Params: {
projectId: string;
};
}>
) {
const { params } = req;
redisSub.subscribe('event');
const message = (channel: string, message: string) => {
const event = getSafeJson<IServiceCreateEventPayload>(message);
if (event?.projectId === params.projectId) {
connection.socket.send(JSON.stringify(event));
}
};
redisSub.on('message', message);
connection.socket.on('close', () => {
redisSub.unsubscribe('event');
redisSub.off('message', message);
});
}

View File

@@ -17,6 +17,7 @@ const liveRouter: FastifyPluginCallback = (fastify, opts, done) => {
{ websocket: true },
controller.wsVisitors
);
fastify.get('/events/:projectId', { websocket: true }, controller.wsEvents);
done();
});