| 1 |
# `events` - [Sessions API](../README.md#sessions-api) |
| 2 |
|
| 3 |
Session events can be used to send messages related to a specific session for |
| 4 |
others to receive. This can include status updates or action that running |
| 5 |
session react on. |
| 6 |
|
| 7 |
For possible events see [Session Event Types](./event-types.md) |
| 8 |
|
| 9 |
## 1. `listen events` |
| 10 |
|
| 11 |
Listen for session specific events by registering on the `events` endpoint using HTTP long polling. |
| 12 |
|
| 13 |
### HTTP Request |
| 14 |
|
| 15 |
``` |
| 16 |
GET /api/sessions/<token>/events |
| 17 |
``` |
| 18 |
|
| 19 |
### Query Parameters |
| 20 |
|
| 21 |
| Parameter | Desciption | Default | Example | |
| 22 |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------- | -------------- | |
| 23 |
| `last_event` | The number of the last received event. All events that are newer than `last_event` are returned immediately. If there are no newer events, connection stays open until a new event is triggered. | None | `last_event=5` | |
| 24 |
|
| 25 |
#### Response Payload |
| 26 |
|
| 27 |
```json |
| 28 |
[ |
| 29 |
{ |
| 30 |
"type": "String", |
| 31 |
"data": "String", |
| 32 |
"number": "Number" |
| 33 |
}, |
| 34 |
... |
| 35 |
] |
| 36 |
``` |
| 37 |
|
| 38 |
- **type**: the type of event that occurred. |
| 39 |
- **data**: the actual payload of the event |
| 40 |
- **number**: the number of the event |
| 41 |
|
| 42 |
#### Example |
| 43 |
|
| 44 |
``` |
| 45 |
GET /api/sessions/6fdbd1a0-c339-11e9-b775-6d49dd567772/events?last_event=8 |
| 46 |
``` |
| 47 |
|
| 48 |
```json |
| 49 |
[ |
| 50 |
{ |
| 51 |
"type": "status", |
| 52 |
"data": "paused", |
| 53 |
"number": 9 |
| 54 |
}, |
| 55 |
{ |
| 56 |
"type": "status", |
| 57 |
"data": "running", |
| 58 |
"number": 10 |
| 59 |
}, |
| 60 |
{ |
| 61 |
"type": "status", |
| 62 |
"data": "paused", |
| 63 |
"number": 11 |
| 64 |
}, |
| 65 |
{ |
| 66 |
"type": "status", |
| 67 |
"data": "running", |
| 68 |
"number": 12 |
| 69 |
} |
| 70 |
] |
| 71 |
``` |
| 72 |
|
| 73 |
## 2. `push events` |
| 74 |
|
| 75 |
Push session specific events for any registered listeners to receive. |
| 76 |
|
| 77 |
### HTTP Request |
| 78 |
|
| 79 |
``` |
| 80 |
POST /api/sessions/<token>/events |
| 81 |
``` |
| 82 |
|
| 83 |
```json |
| 84 |
{ |
| 85 |
"type": "String", |
| 86 |
"data": "String" |
| 87 |
} |
| 88 |
``` |
| 89 |
|
| 90 |
- **type**: the type of event that occurred. |
| 91 |
- **data**: the actual payload of the event |
| 92 |
|
| 93 |
#### Example |
| 94 |
|
| 95 |
``` |
| 96 |
POST /api/sessions/6fdbd1a0-c339-11e9-b775-6d49dd567772/events |
| 97 |
``` |
| 98 |
|
| 99 |
```json |
| 100 |
{ |
| 101 |
"type": "status", |
| 102 |
"data": "paused" |
| 103 |
} |
| 104 |
``` |