Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
stitchng committed Oct 29, 2019
1 parent db6c33a commit 3bf0dcd
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Expand Up @@ -25,7 +25,7 @@ const Route = use('Route');

Route.get('/stream', ({ source }) => {
// send a server-sent events comment
source.send(null, '!This is a comment!');
source.send("Hello AdonisJS", '!This is a comment!');
})//.middleware(['eventsource']);

Route.post('/send/email', 'NotificationsController.sendEmail')
Expand Down Expand Up @@ -86,6 +86,26 @@ class NotificationsController {

module.exports = NotificationsController
```
## Connecting from the client-side

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Polyfill for older browsers without native support for the HTML5 EventSource API. -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=EventSource"></script>
</head>
<body>
<script>
let stream = new EventSource("http://127.0.0.1:3333/stream");
stream.onmessage = function(e){
console.log("Data: ", e.data);
};
</script>
</body>
</html>
```

## License

Expand Down Expand Up @@ -130,4 +150,4 @@ See the [CONTRIBUTING.md](https://github.com/stitchng/adonis-sse/blob/master/CON

>Follow us on facebook if you can to get the latest open source software/freeware news and infomation.
Does your business depend on our open projects? Reach out and support us on [Patreon](https://www.patreon.com/coolcodes/). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
Does your business depend on our open projects? Reach out and support us on [Patreon](https://www.patreon.com/coolcodes/). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

0 comments on commit 3bf0dcd

Please sign in to comment.