nips/100.md
2023-03-21 13:00:34 -04:00

2.5 KiB

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. 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

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.

{
    "kind": 25050,
    "pubkey": "<sender pubkey>",
    "tags": [
        ["type", "connect"],
        ...roominfo
    ]
}

Closing

This is used when disconnecting from everybody else. Ex: when browser tab is closed.

{
    "kind": 25050,
    "pubkey": "<sender pubkey>",
    "tags": [
        ["type", "disconnect"],
        ...roominfo
    ]
}

Offering to connect

Used when responding to a type:connect. Offering to connect to that peer.

{
    "kind": 25050,
    "pubkey": "<sender pubkey>",
    "tags": [
        ["type", "offer"],
        ["p", "<reciever>"],
        ["r", "<optional encrypted room id>"]
    ],
    "content": {
        "offer": "<offer>",
        "type": "offer"
    }
}

Answering an Offer

{
    "kind": 25050,
    "pubkey": "<sender pubkey>",
    "tags": [
        ["type", "answer"],
        ["p", "<reciever>"],
        ["r", "<optional encrypted room id>"]
    ],
    "content": {
        "sdp": "<sdp>",
        "type": "answer"
    }
}

Broadcasting ICE Candidate

{
    "kind": 25050,
    "pubkey": "<sender pubkey>",
    "tags": [
        ["type", "candidate"],
        ["p", "<reciever>"],
        ["r", "<optional encrypted room id>"]
    ],
    "content": {
        "candidate": "<sdp>",
        ...misc
    }
}