Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livekit-ffi: add DisconnectReason #385

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion livekit-ffi/protocol/room.proto
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,30 @@ enum DataPacketKind {
KIND_RELIABLE = 1;
}

enum DisconnectReason {
UNKNOWN_REASON = 0;
// the client initiated the disconnect
CLIENT_INITIATED = 1;
// another participant with the same identity has joined the room
DUPLICATE_IDENTITY = 2;
// the server instance is shutting down
SERVER_SHUTDOWN = 3;
// RoomService.RemoveParticipant was called
PARTICIPANT_REMOVED = 4;
// RoomService.DeleteRoom was called
ROOM_DELETED = 5;
// the client is attempting to resume a session, but server is not aware of it
STATE_MISMATCH = 6;
// client was unable to connect fully
JOIN_FAILURE = 7;
// Cloud-only, the server requested Participant to migrate the connection elsewhere
MIGRATION = 8;
// the signal websocket was closed unexpectedly
SIGNAL_CLOSE = 9;
// the room was closed, due to all Standard and Ingress participants having left
ROOM_CLOSED = 10;
}

message TranscriptionSegment {
string id = 1;
string text = 2;
Expand Down Expand Up @@ -450,7 +474,9 @@ message TranscriptionReceived {
message ConnectionStateChanged { ConnectionState state = 1; }

message Connected {}
message Disconnected {}
message Disconnected {
DisconnectReason reason = 1;
}
message Reconnecting {}
message Reconnected {}

Expand Down
18 changes: 18 additions & 0 deletions livekit-ffi/src/conversion/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ impl From<EncryptionType> for proto::EncryptionType {
}
}

impl From<DisconnectReason> for proto::DisconnectReason {
fn from(value: DisconnectReason) -> Self {
match value {
DisconnectReason::UnknownReason => Self::UnknownReason,
DisconnectReason::ClientInitiated => Self::ClientInitiated,
DisconnectReason::DuplicateIdentity => Self::DuplicateIdentity,
DisconnectReason::ServerShutdown => Self::ServerShutdown,
DisconnectReason::ParticipantRemoved => Self::ParticipantRemoved,
DisconnectReason::RoomDeleted => Self::RoomDeleted,
DisconnectReason::StateMismatch => Self::StateMismatch,
DisconnectReason::JoinFailure => Self::JoinFailure,
DisconnectReason::Migration => Self::Migration,
DisconnectReason::SignalClose => Self::SignalClose,
DisconnectReason::RoomClosed => Self::RoomClosed,
}
}
}

impl From<proto::KeyProviderOptions> for KeyProviderOptions {
fn from(value: proto::KeyProviderOptions) -> Self {
Self {
Expand Down
66 changes: 65 additions & 1 deletion livekit-ffi/src/livekit.proto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @generated
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FrameCryptor {
Expand Down Expand Up @@ -2608,6 +2607,8 @@ pub struct Connected {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Disconnected {
#[prost(enumeration="DisconnectReason", tag="1")]
pub reason: i32,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -2767,6 +2768,69 @@ impl DataPacketKind {
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum DisconnectReason {
UnknownReason = 0,
/// the client initiated the disconnect
ClientInitiated = 1,
/// another participant with the same identity has joined the room
DuplicateIdentity = 2,
/// the server instance is shutting down
ServerShutdown = 3,
/// RoomService.RemoveParticipant was called
ParticipantRemoved = 4,
/// RoomService.DeleteRoom was called
RoomDeleted = 5,
/// the client is attempting to resume a session, but server is not aware of it
StateMismatch = 6,
/// client was unable to connect fully
JoinFailure = 7,
/// Cloud-only, the server requested Participant to migrate the connection elsewhere
Migration = 8,
/// the signal websocket was closed unexpectedly
SignalClose = 9,
/// the room was closed, due to all Standard and Ingress participants having left
RoomClosed = 10,
}
impl DisconnectReason {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
DisconnectReason::UnknownReason => "UNKNOWN_REASON",
DisconnectReason::ClientInitiated => "CLIENT_INITIATED",
DisconnectReason::DuplicateIdentity => "DUPLICATE_IDENTITY",
DisconnectReason::ServerShutdown => "SERVER_SHUTDOWN",
DisconnectReason::ParticipantRemoved => "PARTICIPANT_REMOVED",
DisconnectReason::RoomDeleted => "ROOM_DELETED",
DisconnectReason::StateMismatch => "STATE_MISMATCH",
DisconnectReason::JoinFailure => "JOIN_FAILURE",
DisconnectReason::Migration => "MIGRATION",
DisconnectReason::SignalClose => "SIGNAL_CLOSE",
DisconnectReason::RoomClosed => "ROOM_CLOSED",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"UNKNOWN_REASON" => Some(Self::UnknownReason),
"CLIENT_INITIATED" => Some(Self::ClientInitiated),
"DUPLICATE_IDENTITY" => Some(Self::DuplicateIdentity),
"SERVER_SHUTDOWN" => Some(Self::ServerShutdown),
"PARTICIPANT_REMOVED" => Some(Self::ParticipantRemoved),
"ROOM_DELETED" => Some(Self::RoomDeleted),
"STATE_MISMATCH" => Some(Self::StateMismatch),
"JOIN_FAILURE" => Some(Self::JoinFailure),
"MIGRATION" => Some(Self::Migration),
"SIGNAL_CLOSE" => Some(Self::SignalClose),
"ROOM_CLOSED" => Some(Self::RoomClosed),
_ => None,
}
}
}
/// Create a new AudioStream
/// AudioStream is used to receive audio frames from a track
#[allow(clippy::derive_partial_eq_without_eq)]
Expand Down
6 changes: 4 additions & 2 deletions livekit-ffi/src/server/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,10 @@ async fn forward_event(
RoomEvent::Connected { .. } => {
// Ignore here, we're already sent the event on connect (see above)
}
RoomEvent::Disconnected { reason: _ } => {
let _ = send_event(proto::room_event::Message::Disconnected(proto::Disconnected {}));
RoomEvent::Disconnected { reason } => {
let _ = send_event(proto::room_event::Message::Disconnected(proto::Disconnected {
reason: proto::DisconnectReason::from(reason).into(),
}));
}
RoomEvent::Reconnecting => {
present_state.lock().reconnecting = true;
Expand Down
2 changes: 1 addition & 1 deletion livekit-protocol/protocol
Submodule protocol updated 49 files
+0 −5 .changeset/brown-rats-visit.md
+0 −5 .changeset/fuzzy-crews-refuse.md
+0 −5 .changeset/healthy-papayas-join.md
+0 −12 .changeset/mighty-steaks-invite.md
+0 −5 .changeset/proud-gorillas-press.md
+0 −5 .changeset/tough-dingos-love.md
+37 −0 CHANGELOG.md
+1 −1 auth/grants.go
+19 −20 go.mod
+38 −38 go.sum
+28 −41 infra/link_grpc.pb.go
+318 −866 livekit/livekit_agent.pb.go
+674 −0 livekit/livekit_agent_dispatch.pb.go
+7 −10 livekit/livekit_agent_grpc.pb.go
+74 −71 livekit/livekit_egress.pb.go
+187 −187 livekit/livekit_egress.twirp.go
+261 −250 livekit/livekit_internal.pb.go
+65 −51 livekit/livekit_models.pb.go
+224 −223 livekit/livekit_room.pb.go
+81 −81 livekit/livekit_room.twirp.go
+365 −356 livekit/livekit_rtc.pb.go
+40 −0 livekit/types.go
+100 −0 livekit/types_test.go
+1 −3 magefile.go
+1 −1 package.json
+18 −0 packages/javascript/CHANGELOG.md
+2 −2 packages/javascript/package.json
+6 −51 protobufs/livekit_agent.proto
+69 −0 protobufs/livekit_agent_dispatch.proto
+1 −0 protobufs/livekit_egress.proto
+2 −1 protobufs/livekit_internal.proto
+11 −0 protobufs/livekit_models.proto
+1 −1 protobufs/livekit_room.proto
+1 −0 protobufs/livekit_rtc.proto
+5 −1 protobufs/rpc/agent.proto
+11 −11 replay/cloud_replay.pb.go
+91 −25 rpc/agent.pb.go
+31 −29 rpc/agent.psrpc.go
+48 −160 rpc/analytics_grpc.pb.go
+16 −16 rpc/participant.psrpc.go
+12 −12 rpc/room.psrpc.go
+13 −2 utils/configobserver.go
+10 −0 utils/configobserver_test.go
+100 −0 utils/configutil/atomic.go
+74 −0 utils/deepcopy.go
+46 −0 utils/deepcopy_test.go
+97 −39 utils/event_emitter.go
+24 −0 utils/event_emitter_test.go
+77 −4 webhook/url_notifier.go
Loading
Loading