-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Add EventSource support #11235
Add EventSource support #11235
Conversation
If the browser supports EventSource switch to use this instead of polling notifications. Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
This does seem to add quite a bit of backend code. Did you consider a third-party SSE implementation? |
@silverwind there was genuinely nothing appropriate - and not dead already - and we'd just have to do more work to shim around it. |
Signed-off-by: Andrew Thornton <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
@zeripath what is event-stream? suggest add more detail description or screenshoots about this feature. Thanks |
@a1012112796 I've updated the head. |
Co-authored-by: guillep2k <[email protected]>
Signed-off-by: Andrew Thornton <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything else looks good. Waiting for resolution about the CORS configuration to approve.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with above doc suggestions
Make lg-tm work |
If the browser supports EventSource switch to use this instead of polling notifications. Signed-off-by: Andrew Thornton [email protected]
If the browser supports
EventSource
switch to use this instead ofpolling notifications.
Signed-off-by: Andrew Thornton [email protected]
What is an EventSource?
See https://developer.mozilla.org/en-US/docs/Web/API/EventSource
It's used for Server-Side Events notification.
Creating an EventSource causes JS to open a long-standing request, in this case to
${AppSubUrl}/user/events
with the expected mime-typetext/event-stream
. In this PR we use this stream to obtain a updated count of notifications. However, future extensions of this work could use this along with https://fomantic-ui.com/modules/toast.html to give users a running update of their dashboard.Using the event-stream we could add in error and task information for long running things - e.g. report when migrations and mirroring are complete, or errors from cron tasks.
We can further use the stream to alert that they have logged on to a different browser/device and logged out from those.
In my testing on Chrome only one EventSource is opened per target-url per browser session. So if you have multiple tabs open for Gitea there will only be one EventSource.