-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #706 from 0xJacky/feat/sse-notify
enhance(sse): add X-Accel-Buffering header Merge pull request #697 from 0xJacky/feat/sse-notify feat: sse notify
- Loading branch information
Showing
16 changed files
with
207 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package notification | ||
|
||
import ( | ||
"github.com/0xJacky/Nginx-UI/internal/notification" | ||
"github.com/0xJacky/Nginx-UI/model" | ||
"github.com/gin-gonic/gin" | ||
"io" | ||
"time" | ||
) | ||
|
||
func Live(c *gin.Context) { | ||
c.Header("Content-Type", "text/event-stream") | ||
c.Header("Cache-Control", "no-cache") | ||
c.Header("Connection", "keep-alive") | ||
// https://stackoverflow.com/questions/27898622/server-sent-events-stopped-work-after-enabling-ssl-on-proxy/27960243#27960243 | ||
c.Header("X-Accel-Buffering", "no") | ||
|
||
evtChan := make(chan *model.Notification) | ||
|
||
notification.SetClient(c, evtChan) | ||
|
||
notify := c.Writer.CloseNotify() | ||
|
||
c.Stream(func(w io.Writer) bool { | ||
c.SSEvent("heartbeat", "") | ||
return false | ||
}) | ||
|
||
for { | ||
select { | ||
case n := <-evtChan: | ||
c.Stream(func(w io.Writer) bool { | ||
c.SSEvent("message", n) | ||
return false | ||
}) | ||
case <-time.After(30 * time.Second): | ||
c.Stream(func(w io.Writer) bool { | ||
c.SSEvent("heartbeat", "") | ||
return false | ||
}) | ||
case <-notify: | ||
notification.RemoveClient(c) | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"2.0.0-beta.39","build_id":1,"total_build":368} | ||
{"version":"2.0.0-beta.39","build_id":3,"total_build":370} |
Oops, something went wrong.