Skip to content

Commit

Permalink
examples: minor (see previous commits)
Browse files Browse the repository at this point in the history
examples: 3rd-party sse (2):  add the same client-side as the original 3rd-party example
  • Loading branch information
kataras committed Jan 27, 2021
1 parent bccd5eb commit 61f04ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions _examples/response-writer/sse-third-party-2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>SSE Examples</title>
</head>
<body>
<strong>Messages</strong>
<br>
<div id="messages"></div>

<script type="text/javascript">
e1 = new EventSource('/events/channel-1');
e1.onmessage = function(event) {
document.getElementById('messages').innerHTML += 'Message on channel-1: ' + event.data + '<br>';
};

e2 = new EventSource('/events/channel-2');
e2.onmessage = function(event) {
document.getElementById('messages').innerHTML += 'Message on channel-2: ' + event.data + '<br>';
};
</script>
</body>
</html>
6 changes: 4 additions & 2 deletions _examples/response-writer/sse-third-party-2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"github.com/kataras/iris/v12"
)

// Install the sse third-party package
// Install the sse third-party package.
// $ go get -u github.com/alexandrevicenzi/go-sse
//
// Documentation: https://pkg.go.dev/github.com/alexandrevicenzi/go-sse
func main() {
s := sse.NewServer(&sse.Options{
// Increase default retry interval to 10s.
Expand All @@ -35,7 +37,7 @@ func main() {

app := iris.New()
app.Get("/", func(ctx iris.Context) {
ctx.ServeFile("../static/index.html")
ctx.ServeFile("./index.html")
})
app.Get("/events/{channel}", iris.FromStd(s))

Expand Down

0 comments on commit 61f04ee

Please sign in to comment.