event-stream-debug

This commit is contained in:
Untone 2023-10-18 13:48:50 +03:00
parent 2b91a729bd
commit 54f114c8c9

View File

@ -95,14 +95,14 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => {
loadNotifications() loadNotifications()
const token = getToken() const token = getToken()
const eventSource = new EventSource(`https://chat.discours.io/connect/${token}`) const eventSource = new EventSource(`https://chat.discours.io/connect/?token=${token}`)
eventSource.onmessage = (event) => { eventSource.onmessage = (event) => {
const n: { kind: string; payload: any } = JSON.parse(event.data) const n: { kind: string; payload: any } = JSON.parse(event.data)
console.log('[context.notifications] Received notification:', n)
if (n.kind === 'new_message') { if (n.kind === 'new_message') {
messageHandler()(n.payload) messageHandler()(n.payload)
} else { } else {
console.log('[context.notifications] Received notification:', n)
storeNotification({ storeNotification({
kind: n.kind, kind: n.kind,
payload: n.payload, payload: n.payload,