Skip to content

Commit

Permalink
feat: trigger onConnect()
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Mar 13, 2023
1 parent 0aba784 commit d2293d7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createEventSource(
options: EventSourceOptions,
{getStream, getTextDecoderStream}: EnvAbstractions
): EventSourceClient {
const {onMessage, onDisconnect = noop} = options
const {onMessage, onConnect = noop, onDisconnect = noop} = options
const {fetch, url, initialLastEventId} = validate(options)
const requestHeaders = {...options.headers} // Prevent using modified object later
const parser = createParser(onParsedMessage)
Expand Down Expand Up @@ -95,6 +95,8 @@ export function createEventSource(
}

async function onFetchResponse(response: FetchLikeResponse) {
onConnect()

const {body, redirected, status} = response
if (!body) {
throw new Error('Missing response body')
Expand Down

0 comments on commit d2293d7

Please sign in to comment.