
syntax = "proto3";
option go_package = "github.com/coder/coder/peerbroker/proto";

package peerbroker;

message WebRTCSessionDescription {
    int32 sdp_type = 1;
    string sdp = 2;
}

message Exchange {
    oneof message {
        WebRTCSessionDescription sdp = 1;
        string ice_candidate = 2;
    }
}

// PeerBroker mediates WebRTC connection signaling.
service PeerBroker {
    // NegotiateConnection establishes a bidirectional stream to negotiate a new WebRTC connection.
    // 1. Client sends WebRTCSessionDescription to the server.
    // 2. Server sends WebRTCSessionDescription to the client, exchanging encryption keys.
    // 3. Client<->Server exchange ICE Candidates to establish a peered connection.
    // 
    // See: https://davekilian.com/webrtc-the-hard-way.html
    rpc NegotiateConnection(stream Exchange) returns (stream Exchange);
}