Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sse / EventSource #164

Open
magicdawn opened this issue Jun 29, 2023 · 2 comments
Open

sse / EventSource #164

magicdawn opened this issue Jun 29, 2023 · 2 comments

Comments

@magicdawn
Copy link
Owner

No description provided.

@magicdawn
Copy link
Owner Author

应用

@magicdawn
Copy link
Owner Author

magicdawn commented Jun 29, 2023

EventSource

mime-type

text/event-stream

server send message

https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#sending_events_from_the_server

以空行分割, 即 \n\n

event: foo
data: foo-data

event: foo
data: foo-data

还可以包含 id:

client

const s = new EventSource('/sse/url')

// when a event has no `event: ` field
s.addEventListener('message', (e) => {
  // 
})

// when a event has `event: foo`
s.addEventListener('foo', (e) => {
  // 
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant