mirror of
https://github.com/nostr-protocol/nips.git
synced 2024-09-20 23:05:49 -04:00
95 lines
2.3 KiB
Markdown
95 lines
2.3 KiB
Markdown
# NIP-100 WebRTC
|
|
`draft` `optional` `author:jacany`
|
|
|
|
This NIP defines how to do WebRTC communication over nostr.
|
|
|
|
## 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.)
|
|
|
|
## 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.
|
|
|
|
## 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. ⚠️
|
|
|
|
### Broadcasting that you are present
|
|
Announces that the client is ready to connect to others.
|
|
The connection ID is inferred from the provided pubkey.
|
|
```json
|
|
{
|
|
"kind": 25050,
|
|
"pubkey": "<sender pubkey>",
|
|
"tags": [
|
|
["type", "connect"],
|
|
["r", "<plaintext room id>"]
|
|
]
|
|
}
|
|
```
|
|
|
|
### Closing
|
|
This is used when disconnecting from everybody else. Ex: when browser tab is closed.
|
|
```json
|
|
{
|
|
"kind": 25050,
|
|
"pubkey": "<sender pubkey>",
|
|
"tags": [
|
|
["type", "disconnect"],
|
|
["r", "<plaintext room id>"]
|
|
]
|
|
}
|
|
```
|
|
|
|
### 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"],
|
|
["p", "<reciever>"],
|
|
["r", "<encrypted room id>"]
|
|
],
|
|
"content": {
|
|
"offer": "<offer>",
|
|
"type": "offer"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Answering an Offer
|
|
```json
|
|
{
|
|
"kind": 25050,
|
|
"pubkey": "<sender pubkey>",
|
|
"tags": [
|
|
["type", "answer"],
|
|
["p", "<reciever>"],
|
|
["r", "<encrypted room id>"]
|
|
],
|
|
"content": {
|
|
"sdp": "<sdp>",
|
|
"type": "answer"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Broadcasting ICE Candidate
|
|
```json
|
|
{
|
|
"kind": 25050,
|
|
"pubkey": "<sender pubkey>",
|
|
"tags": [
|
|
["type", "candidate"],
|
|
["p", "<reciever>"],
|
|
["r", "<encrypted room id>"]
|
|
],
|
|
"content": {
|
|
"candidate": "<sdp>",
|
|
<misc>
|
|
}
|
|
}
|
|
``` |