Debian Codegraph @

testing/web-platform/tests/tools/wave/docs/rest-api/devices-api/register-global.md

raw
1 # `register global event listener` - [Devices API](../README.md#devices-api)
2
3 The `register global event listener` method of the devices API notifies a
4 registered listener upon global device events. It uses HTTP long polling in
5 send the event to this listener in real time, so upon receiving an event, the
6 connection has to be reestablished by the client to receive further events.
7
8 ## HTTP Request
9
10 `GET /api/devices/events`
11
12 ## Query Parameters
13
14 | Parameter | Desciption | Example |
15 | ---------------- | ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
16 | `device_token` | The token of the device which performed the request. (Optional) Lets the server know the registered device is still active. | `device_token=7dafeec0-c351-11e9-84c5-3d1ede2e7d2e` |
17
18 ## Response Payload
19
20 ```json
21 {
22 "type": "<String>",
23 "data": "<Any>"
24 }
25 ```
26
27 - **type** defines what type of event has been triggered.
28 - **data** contains the event specific payload.
29
30 ## Event Types
31
32 See [global events](./event-types.md#global)
33
34 ## Example
35
36 **Request:**
37
38 `GET /api/devices/events`
39
40 **Response:**
41
42 ```json
43 {
44 "type": "device_added",
45 "data": {
46 "token": "1d9f5d30-830f-11ea-8dcb-0021ccd76152",
47 "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36",
48 "last_active": 1587391153295,
49 "name": "Chrome 81.0.4044"
50 }
51 }
52 ```
53
54