add-fetch-eventsource
This commit is contained in:
parent
42d69593f8
commit
767147c4d1
|
@ -46,6 +46,7 @@
|
|||
"@graphql-tools/url-loader": "7.17.18",
|
||||
"@graphql-typed-document-node/core": "3.2.0",
|
||||
"@hocuspocus/provider": "2.0.6",
|
||||
"@microsoft/fetch-event-source": "^2.0.1",
|
||||
"@nanostores/router": "0.8.3",
|
||||
"@nanostores/solid": "0.3.2",
|
||||
"@popperjs/core": "2.11.8",
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import type { Accessor, JSX } from 'solid-js'
|
||||
import { createContext, createSignal, useContext } from 'solid-js'
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source'
|
||||
import type { Chat, Message, MutationCreateMessageArgs } from '../graphql/types.gen'
|
||||
import { inboxClient } from '../utils/apiClient'
|
||||
|
||||
import { getToken } from '../graphql/privateGraphQLClient'
|
||||
import { loadMessages } from '../stores/inbox'
|
||||
|
||||
type InboxContextType = {
|
||||
|
@ -26,7 +27,17 @@ export function useInbox() {
|
|||
export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||
const [chats, setChats] = createSignal<Chat[]>([])
|
||||
const [messages, setMessages] = createSignal<Message[]>([])
|
||||
const eventSource = new EventSource('https://testapi.discours.io/connect')
|
||||
const eventSource = new fetchEventSource('https://testapi.discours.io/connect', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': getToken()
|
||||
},
|
||||
body: JSON.stringify({
|
||||
foo: 'bar'
|
||||
}),
|
||||
// signal: signal, TODO: sometimes need to call /disconnect
|
||||
})
|
||||
// TODO: call /disconnect some time
|
||||
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
||||
eventSource.onmessage = function (event) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user