Skip to content

Commit

Permalink
SET_CERTIFIED_DEVICES RPC command (discord#566)
Browse files Browse the repository at this point in the history
* More info for certified devices WOOOOOAH

* How to image paths

* Related devices

* Vendor and model are objects

* How to do the linking please

* Mas updates

* http response

* RPC -> websocket, moved to topics

* WebSockets
  • Loading branch information
msciotti authored Mar 22, 2018
1 parent ed1765e commit 003cf61
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 0 deletions.
159 changes: 159 additions & 0 deletions docs/topics/Certified_Devices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Certified Devices

Baked into Discord is the ability for hardware manufacturers to tell us a little more about the certified devices that are plugged into a user's computer. Unfortunately, no, you can't show that a user's PUBG Chicken Dinner was all thanks to the amazing TotallyRealHardware RGB Mouse and Keyboard Set Extraordinaire™, but you _can_ give them an amazing experience using your hardware with Discord!

## How's it work?

I'm glad you asked!

1. [Create an application](https://discordapp.com/developers/applications/me) for your hardware vendor—save the Client ID!
2. Talk to Discord via one simple HTTP or WebSocket call
3. Send us a [`SET_CERTIFIED_DEVICES`](#DOCS_TOPICS_RPC/set-certified-devices) WebSocket payload or equivalent HTTP POST whenever the state of the device changes

Yup, that's it. You give us the real-time info about any connected devices, and we'll handle the rest to make sure that anyone using your device will have an awesome experience. Your device will also have a `CERTIFIED` badge in Discord's audio settings, and really, who doesn't love badges?

![](certified-device.png)

## HTTP

Discord listens for request on `http://127.0.0.1:PORT/rpc?v=1&client_id=YOUR_CLIENT_ID`, where `PORT` is a range of ports from `6463` to `6473`. You should iterate over these ports with your request until one returns a success response code. Keep track of that successful port number for the rest of the session.

###### Querystring Parameters

| Name | Value | Required |
| --------- | -------------------- | -------- |
| v | 1 | yes |
| client_id | your app's client id | yes |

To keep your hardware in sync with Discord, POST to this endpoint any time the hardware mute is toggled, or one of the voice features like echo cancellation is enabled or disabled by the user. This lets Discord get out of the way of your optimization when you're in control, or help out when you're not, ensuring an awesome experience for anyone using your hardware.

###### HTTP Request Example

```
curl -X POST -H 'Content-Type: application/json' -d '
{
"nonce": "9b4e9711-97f3-4f35-b047-32c82a51978e",
"cmd": "SET_CERTIFIED_DEVICES",
"args": {
"devices": [
{
"type": "audioinput",
"id": "aafc2003-da0e-42a3-b982-6a17a2812510",
"vendor": {
"name": "SteelSeries",
"url": "https://steelseries.com"
},
"model": {
"name": "Arctis 7",
"url": "https://steelseries.com/gaming-headsets/arctis-7"
},
"related": ["aafc2003-da0e-42a3-b982-6a17a2819999"],
"echo_cancellation": true,
"noise_suppression": true,
"automatic_gain_control": true,
"hardware_mute": false
}
]
}
}
' http://127.0.0.1:PORT/rpc?v=1&client_id=YOUR_CLIENT_ID
```

The socket will respond with a `200 OK` status code and the following JSON.

###### HTTP Response Example

```json
{
"cmd": "SET_CERTIFIED_DEVICES",
"data": null,
"evt": null,
"nonce": "9b4e9711-97f3-4f35-b047-32c82a51978e"
}
```

## WebSocket

If WebSockets are your thing, you can easily keep your hardware up to date by sending `SET_CERTIFIED_DEVICES` commands over the socket whenever your device state changes. Open a connection to `ws://127.0.0.1:PORT?v=1&client_id=YOUR_CLIENT_ID&encoding=json`, where `PORT` is a range of ports from `6463` to `6473`. You should iterate over these ports with your request until one successfully connects. Keep track of that port number for the rest of the session.

###### RPC Command Example

```json
{
"nonce": "9b4e9711-97f3-4f35-b047-32c82a51978e",
"cmd": "SET_CERTIFIED_DEVICES",
"args": {
"devices": [
{
"type": "audioinput",
"id": "aafc2003-da0e-42a3-b982-6a17a2812510",
"vendor": {
"name": "SteelSeries",
"url": "https://steelseries.com"
},
"model": {
"name": "Arctis 7",
"url": "https://steelseries.com/gaming-headsets/arctis-7"
},
"related": ["aafc2003-da0e-42a3-b982-6a17a2819999"],
"echo_cancellation": true,
"noise_suppression": true,
"automatic_gain_control": true,
"hardware_mute": false
}
]
}
}
```

###### RPC Response Example

```json
{
"nonce": "9b4e9711-97f3-4f35-b047-32c82a51978e",
"cmd": "SET_CERTIFIED_DEVICES",
"data": null,
"evt": null
}
```

## Models

## Device Object

| Field | Type | Description |
| ------------------------ | -------------------------------------------------------------------- | -------------------------------------------------------- |
| type | [device type](#DOCS_RICH_PRESENCE_CERTIFIED_DEVICES/device-type) | the type of device |
| id | string | the device's Windows UUID |
| vendor | [vendor](#DOCS_RICH_PRESENCE_CERTIFIED_DEVICES/vendor-object) object | the hardware vendor |
| model | [model](#DOCS_RICH_PRESENCE_CERTIFIED_DEVICES/model-object) object | the model of the product |
| related | array of strings | UUIDs of related products |
| echo_cancellation?* | bool | if the device's native echo cancellation is enabled |
| noise_suppression?* | bool | if the device's native noise suppression is enabled |
| automatic_gain_control?* | bool | if the device's native automatic gain control is enabled |
| hardware_mute?* | bool | if the device is hardware muted |

*These fields are only applicable for `AUDIO_INPUT` device types

### Vendor Object

| Field | Type | Description |
| ----- | ------ | ------------------ |
| name | string | name of the vendor |
| url | string | url for the vendor |

### Model Object

| Field | Type | Description |
| ----- | ------ | ----------------- |
| name | string | name of the model |
| url | string | url for the model |

### Device Types

| Type | Value |
| ------------ | ------------- |
| AUDIO_INPUT | "audioinput" |
| AUDIO_OUTPUT | "audiooutput" |
| VIDEO_INPUT | "videoinput" |

84 changes: 84 additions & 0 deletions docs/topics/RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Commands are requests made to the RPC socket by a client.
| [GET_VOICE_SETTINGS](#DOCS_TOPICS_RPC/getvoicesettings) | used to retrieve the client's voice settings |
| [SET_VOICE_SETTINGS](#DOCS_TOPICS_RPC/setvoicesettings) | used to set the client's voice settings |
| [CAPTURE_SHORTCUT](#DOCS_TOPICS_RPC/captureshortcut) | used to capture a keyboard shortcut entered by the user |
| [SET_CERTIFIED_DEVICES](#DOCS_TOPICS_RPC/setcertifieddevices) | used by hardware manufacturers to send info about certified devices |

Events are payloads sent over the socket to a client that correspond events in Discord.

Expand Down Expand Up @@ -960,6 +961,89 @@ Note: The `START` call will return the captured shortcut in its `data` object, w
}
```

#### SET_CERTIFIED_DEVICES

Used by hardware manufacturers to send information about the current state of their certified devices that are connected to Discord.

###### Set Certified Devices Argument Strucure

| Field | Type | Description |
| ------------------------ | -------------------------------------------------------------------- | -------------------------------------------------------- |
| type | [device type](#DOCS_RICH_PRESENCE_CERTIFIED_DEVICES/device-type) | the type of device |
| id | string | the device's Windows UUID |
| vendor | [vendor](#DOCS_RICH_PRESENCE_CERTIFIED_DEVICES/vendor-object) object | the hardware vendor |
| model | [model](#DOCS_RICH_PRESENCE_CERTIFIED_DEVICES/model-object) object | the model of the product |
| related | array of strings | UUIDs of related products |
| echo_cancellation?* | bool | if the device's native echo cancellation is enabled |
| noise_suppression?* | bool | if the device's native noise suppression is enabled |
| automatic_gain_control?* | bool | if the device's native automatic gain control is enabled |
| hardware_mute?* | bool | if the device is hardware muted |

*These fields are only applicable for `AUDIO_INPUT` device types

## Vendor Object

| Field | Type | Description |
| ----- | ------ | ------------------ |
| name | string | name of the vendor |
| url | string | url for the vendor |

## Model Object

| Field | Type | Description |
| ----- | ------ | ----------------- |
| name | string | name of the model |
| url | string | url for the model |

## Device Types

| Type | Value |
| ------------ | ------------- |
| AUDIO_INPUT | "audioinput" |
| AUDIO_OUTPUT | "audiooutput" |
| VIDEO_INPUT | "videoinput" |

###### Example Set Certified Devices Command Payload

```json
{
"nonce": "9b4e9711-97f3-4f35-b047-32c82a51978e",
"cmd": "SET_CERTIFIED_DEVICES",
"args": {
"devices": [
{
"type": "audioinput",
"id": "aafc2003-da0e-42a3-b982-6a17a2812510",
"vendor": {
"name": "SteelSeries",
"url": "https://steelseries.com"
},
"model": {
"name": "Arctis 7",
"url": "https://steelseries.com/gaming-headsets/arctis-7"
},
"related": ["aafc2003-da0e-42a3-b982-6a17a2819999"],
"echo_cancellation": true,
"noise_suppression": true,
"automatic_gain_control": true,
"hardware_mute": false
}
]
}
}
```

###### Example Set Certified Devices Response Payload

```json
{
"nonce": "9b4e9711-97f3-4f35-b047-32c82a51978e",
"cmd": "SET_CERTIFIED_DEVICES",
"data": null,
"evt": null
}
```

#### READY

###### Ready Dispatch Data Structure
Expand Down
Binary file added images/certified-device.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 003cf61

Please sign in to comment.