2023-03-21 13:00:34 -04:00
NIP-100 WebRTC
==============
2023-03-13 19:58:18 -04:00
`draft` `optional` `author:jacany`
2023-03-14 13:34:36 -04:00
This NIP defines how to do WebRTC communication over nostr.
2023-03-21 13:00:34 -04:00
---------------------------------
2023-03-13 19:58:18 -04:00
2023-03-13 20:11:27 -04:00
## Defining Rooms
2023-03-21 13:00:34 -04:00
Rooms are essentially the space that you will be connected to. How rooms are defined depends.
1. Is this a one-on-one call? In that case just use the `p` tag.
2. If it is a group call (multiple people), then you will need both the `p` tag for communicating who the event is for, and the `r` tag for defining the room id.
In that case, when you are sending `connect` or `disconnect` , the usage of the `p` and `r` tag varies on your requirements
2023-03-13 20:11:27 -04:00
2023-03-14 13:34:36 -04:00
## Peers
Who the client connects to can be chosen by the client. Ex: you can connect to everyone peer-to-peer or a WebRTC media server that is listening on nostr relays.
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
2023-03-14 13:34:36 -04:00
Announces that the client is ready to connect to others.
2023-03-13 19:58:18 -04:00
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-21 13:00:34 -04:00
...roominfo
2023-03-13 19:58:18 -04:00
]
}
```
### Closing
2023-03-14 13:34:36 -04:00
This is used when disconnecting from everybody else. Ex: when browser tab is closed.
2023-03-13 19:58:18 -04:00
```json
{
"kind": 25050,
"pubkey": "< sender pubkey > ",
"tags": [
2023-03-13 20:11:27 -04:00
["type", "disconnect"],
2023-03-21 13:00:34 -04:00
...roominfo
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-14 15:14:22 -04:00
["p", "< reciever > "],
2023-03-21 13:00:34 -04:00
["r", "< optional 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-14 15:14:22 -04:00
["p", "< reciever > "],
2023-03-21 13:00:34 -04:00
["r", "< optional 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-14 15:14:22 -04:00
["p", "< reciever > "],
2023-03-21 13:00:34 -04:00
["r", "< optional encrypted room id > "]
2023-03-13 19:58:18 -04:00
],
"content": {
"candidate": "< sdp > ",
2023-03-21 13:00:34 -04:00
...misc
2023-03-13 19:58:18 -04:00
}
}
2023-03-14 13:34:36 -04:00
```