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

Add EventSource support #11235

Merged
merged 17 commits into from
May 7, 2020
Merged

Add EventSource support #11235

merged 17 commits into from
May 7, 2020

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Apr 28, 2020

If the browser supports EventSource switch to use this instead of
polling 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-type text/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.

If the browser supports EventSource switch to use this instead of
polling notifications.

Signed-off-by: Andrew Thornton <[email protected]>
@zeripath zeripath added the topic/ui Change the appearance of the Gitea UI label Apr 28, 2020
@zeripath zeripath added this to the 1.12.0 milestone Apr 28, 2020
Signed-off-by: Andrew Thornton <[email protected]>
routers/routes/routes.go Show resolved Hide resolved
web_src/js/features/notification.js Outdated Show resolved Hide resolved
web_src/js/features/notification.js Outdated Show resolved Hide resolved
web_src/js/features/notification.js Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 29, 2020
@silverwind
Copy link
Member

This does seem to add quite a bit of backend code. Did you consider a third-party SSE implementation?

@zeripath
Copy link
Contributor Author

@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]>
@a1012112796
Copy link
Member

@zeripath what is event-stream? suggest add more detail description or screenshoots about this feature. Thanks

@zeripath zeripath changed the title Add event-stream support Add EventSource support Apr 29, 2020
@zeripath
Copy link
Contributor Author

@a1012112796 I've updated the head.

modules/eventsource/manager_run.go Outdated Show resolved Hide resolved
models/notification.go Outdated Show resolved Hide resolved
modules/eventsource/event.go Show resolved Hide resolved
modules/eventsource/event.go Show resolved Hide resolved
modules/eventsource/event.go Show resolved Hide resolved
modules/eventsource/event.go Show resolved Hide resolved
modules/eventsource/manager.go Show resolved Hide resolved
modules/eventsource/manager.go Outdated Show resolved Hide resolved
modules/eventsource/manager.go Outdated Show resolved Hide resolved
routers/events/events.go Show resolved Hide resolved
modules/eventsource/event.go Outdated Show resolved Hide resolved
modules/eventsource/manager.go Show resolved Hide resolved
modules/eventsource/manager.go Outdated Show resolved Hide resolved
modules/eventsource/manager_run.go Outdated Show resolved Hide resolved
modules/eventsource/manager_run.go Outdated Show resolved Hide resolved
routers/events/events.go Show resolved Hide resolved
routers/events/events.go Outdated Show resolved Hide resolved
routers/events/events.go Outdated Show resolved Hide resolved
Copy link
Member

@guillep2k guillep2k left a 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.

@guillep2k
Copy link
Member

/go/src/code.gitea.io/gitea/models/notification.go:10:2: \"strconv\" imported but not used

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 5, 2020
Copy link
Member

@silverwind silverwind left a 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

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 7, 2020
@zeripath
Copy link
Contributor Author

zeripath commented May 7, 2020

Make lg-tm work

@zeripath zeripath merged commit 791353c into go-gitea:master May 7, 2020
@zeripath zeripath deleted the event-source branch May 7, 2020 21:49
ydelafollye pushed a commit to ydelafollye/gitea that referenced this pull request Jul 31, 2020
If the browser supports EventSource switch to use this instead of
polling notifications.

Signed-off-by: Andrew Thornton [email protected]
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/ui Change the appearance of the Gitea UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants