2023-03-13 20:11:27 -04:00
# NIP-100 WebRTC
2023-03-13 19:58:18 -04:00
`draft` `optional` `author:jacany`
This NIP defines how to do WebRTC communication over nostr
2023-03-13 20:11:27 -04:00
## Defining Rooms
Rooms are essentially the space that you will be connected to. This must be defined by a `r` tag following the pubkey of the person you are connected to or some other identifier (maybe a lobby id for a joinable voice channel, etc.)
2023-03-14 12:04:37 -04:00
## Encryption
The `content` field and `r` tag of types `offer` , `answer` , and `candidate` should be encrypted, similarly to `NIP-04` .
Clients MUST listen for the `p` tag containing their pubkey so they know that event is intended for them
⚠️ `content` FIELDS SHOULD BE JSON STRINGIFIED, AND THEN ENCRYPTED. ⚠️
2023-03-13 19:58:18 -04:00
### Broadcasting that you are present
Announces that you are here, and ready to connect to others.
The connection ID is inferred from the provided pubkey.
```json
{
"kind": 25050,
"pubkey": "< sender pubkey > ",
"tags": [
2023-03-13 20:11:27 -04:00
["type", "connect"],
2023-03-14 12:04:37 -04:00
["r", "< plaintext room id > "]
2023-03-13 19:58:18 -04:00
]
}
```
### Closing
```json
{
"kind": 25050,
"pubkey": "< sender pubkey > ",
"tags": [
2023-03-13 20:11:27 -04:00
["type", "disconnect"],
2023-03-14 12:04:37 -04:00
["r", "< plaintext room id > "]
2023-03-13 19:58:18 -04:00
]
}
```
### Offering to connect
Used when responding to a `type:connect` . Offering to connect to that peer.
```json
{
"kind": 25050,
"pubkey": "< sender pubkey > ",
"tags": [
["type", "offer"],
2023-03-13 20:11:27 -04:00
["p", "< reciever pubkey > "],
2023-03-14 12:04:37 -04:00
["r", "< encrypted room id > "]
2023-03-13 19:58:18 -04:00
],
"content": {
"offer": "< offer > ",
"type": "offer"
}
}
```
### Answering an Offer
```json
{
"kind": 25050,
"pubkey": "< sender pubkey > ",
"tags": [
["type", "answer"],
2023-03-13 20:11:27 -04:00
["p", "< reciever pubkey > "],
2023-03-14 12:04:37 -04:00
["r", "< encrypted room id > "]
2023-03-13 19:58:18 -04:00
],
"content": {
"sdp": "< sdp > ",
"type": "answer"
}
}
```
### Broadcasting ICE Candidate
```json
{
"kind": 25050,
"pubkey": "< sender pubkey > ",
"tags": [
2023-03-14 10:37:35 -04:00
["type", "candidate"],
2023-03-13 20:11:27 -04:00
["p", "< reciever pubkey > "],
2023-03-14 12:04:37 -04:00
["r", "< encrypted room id > "]
2023-03-13 19:58:18 -04:00
],
"content": {
"candidate": "< sdp > ",
< misc >
}
}
```
2023-03-14 12:04:37 -04:00
Essentially, just directly feed what comes out of the WebRTC functions straight into the `content` field after encrypting it.