syntax = "proto3";

package livekit;
option go_package = "github.com/livekit/protocol/livekit";
option csharp_namespace = "LiveKit.Proto";
option ruby_package = "LiveKit::Proto";

// internal protos, not exposed to clients
import "livekit_models.proto";
import "livekit_rtc.proto";
import "livekit_room.proto";

enum NodeType {
  SERVER = 0;
  CONTROLLER = 1;
  MEDIA = 2;
  TURN = 4;
}

enum NodeState {
  STARTING_UP = 0;
  SERVING = 1;
  SHUTTING_DOWN = 2;
}

message Node {
  string id = 1;
  string ip = 2;
  uint32 num_cpus = 3;
  NodeStats stats = 4;
  NodeType type = 5;
  NodeState state = 6;
  string region = 7;
}

message NodeStats {
  // when server was started
  int64 started_at = 1;
  // when server last reported its status
  int64 updated_at = 2;

  // room
  int32 num_rooms = 3;
  int32 num_clients = 4;
  int32 num_tracks_in = 5;
  int32 num_tracks_out = 6;

  // packet
  uint64 bytes_in = 7;
  uint64 bytes_out = 8;
  uint64 packets_in = 9;
  uint64 packets_out = 10;
  uint64 nack_total = 11;
  float bytes_in_per_sec = 12;
  float bytes_out_per_sec = 13;
  float packets_in_per_sec = 14;
  float packets_out_per_sec = 15;
  float nack_per_sec = 16;

  // system
  uint32 num_cpus = 17;
  float load_avg_last1min = 18;
  float load_avg_last5min = 19;
  float load_avg_last15min = 20;
  float cpu_load = 21;
  uint32 sys_packets_out = 28;
  uint32 sys_packets_dropped = 29;
  float sys_packets_out_per_sec = 30;
  float sys_packets_dropped_per_sec = 31;
  float sys_packets_dropped_pct_per_sec = 32;

  // retransmissions
  uint64 retransmit_bytes_out = 22;
  uint64 retransmit_packets_out = 23;
  float retransmit_bytes_out_per_sec = 24;
  float retransmit_packets_out_per_sec = 25;

  // participant joins
  uint64 participant_join = 26;
  float participant_join_per_sec = 27;
}

// message to RTC nodes
message RTCNodeMessage {
  string participant_key = 1;
  int64 sender_time = 11;
  string connection_id = 13;
  oneof message {
    StartSession start_session = 2;
    SignalRequest request = 3;
    // internal messages
    RoomParticipantIdentity remove_participant = 4;
    MuteRoomTrackRequest mute_track = 5;
    UpdateParticipantRequest update_participant = 6;
    DeleteRoomRequest delete_room = 7;
    UpdateSubscriptionsRequest update_subscriptions = 8;
    SendDataRequest send_data = 9;
    UpdateRoomMetadataRequest update_room_metadata = 10;
    KeepAlive keep_alive = 12;
  }
}

// message to Signal nodes
message SignalNodeMessage {
  string connection_id = 1;
  oneof message {
    SignalResponse response = 2;
    EndSession end_session = 3;
  }
}

message StartSession {
  string room_name = 1;
  string identity = 2;
  string connection_id = 3;
  // if a client is reconnecting (i.e. resume instead of restart)
  bool reconnect = 4;
  bool auto_subscribe = 9;
  bool hidden = 10;
  ClientInfo client = 11;
  bool recorder = 12;
  string name = 13;
  // A user's ClaimGrants serialized in JSON
  string grants_json = 14;
  bool adaptive_stream = 15;
  //if reconnect, client will set current sid
  string participant_id = 16; 
}

message EndSession {
}

message RemoveParticipant {
  string participant_id = 1;
}

message KeepAlive {
}
