improve event list / event details
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ const liveRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||
{ websocket: true },
|
||||
controller.wsVisitors
|
||||
);
|
||||
fastify.get('/events/:projectId', { websocket: true }, controller.wsEvents);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user