From f1f62ddda5c32dec33ad54e9497e678e619a7b6c Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sat, 2 Jul 2022 21:22:26 -0700 Subject: [PATCH] Sends disconnect reason when server sends Leave request (#801) * Sends disconnect reason when server sends Leave request * update go.mod --- go.mod | 2 +- go.sum | 4 ++-- pkg/rtc/participant.go | 4 +++- pkg/rtc/types/interfaces.go | 29 +++++++++++++++++++++++++++++ pkg/service/roommanager.go | 1 + 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 8b55b097c..03640dad1 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/google/wire v0.5.0 github.com/gorilla/websocket v1.4.2 github.com/hashicorp/golang-lru v0.5.4 - github.com/livekit/protocol v0.13.4-0.20220616085727-d1616e3cb8d7 + github.com/livekit/protocol v0.13.5-0.20220703041358-5f996eb446f3 github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a github.com/mackerelio/go-osstat v0.2.1 github.com/magefile/mage v1.13.0 diff --git a/go.sum b/go.sum index 4df49e589..0494dd2fe 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA= github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= -github.com/livekit/protocol v0.13.4-0.20220616085727-d1616e3cb8d7 h1:7EOPqrzXSKLvFTYIEeQaH2kuLswCQ0Q7Hb3wL11RlnE= -github.com/livekit/protocol v0.13.4-0.20220616085727-d1616e3cb8d7/go.mod h1:BLtSeVmn2rLP37xjzw7gHgaAmkWl3L/L9bPvgSbaOfo= +github.com/livekit/protocol v0.13.5-0.20220703041358-5f996eb446f3 h1:aKvC6QqcR7HO1X0AQhUwLUVojbSd6PLMhjBIWTTg3Gw= +github.com/livekit/protocol v0.13.5-0.20220703041358-5f996eb446f3/go.mod h1:BLtSeVmn2rLP37xjzw7gHgaAmkWl3L/L9bPvgSbaOfo= github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a h1:cENjhGfslLSDV07gt8ASy47Wd12Q0kBS7hsdunyQ62I= github.com/livekit/rtcscore-go v0.0.0-20220524203225-dfd1ba40744a/go.mod h1:116ych8UaEs9vfIE8n6iZCZ30iagUFTls0vRmC+Ix5U= github.com/mackerelio/go-osstat v0.2.1 h1:5AeAcBEutEErAOlDz6WCkEvm6AKYgHTUQrfwm5RbeQc= diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 09aa6d93d..00e183ff0 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -689,7 +689,9 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea if sendLeave { _ = p.writeMessage(&livekit.SignalResponse{ Message: &livekit.SignalResponse_Leave{ - Leave: &livekit.LeaveRequest{}, + Leave: &livekit.LeaveRequest{ + Reason: reason.ToDisconnectReason(), + }, }, }) } diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index e4c94c000..c8dd746bd 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -123,6 +123,35 @@ func (p ParticipantCloseReason) String() string { } } +func (p ParticipantCloseReason) ToDisconnectReason() livekit.DisconnectReason { + switch p { + case ParticipantCloseReasonClientRequestLeave: + return livekit.DisconnectReason_CLIENT_INITIATED + case ParticipantCloseReasonRoomManagerStop: + return livekit.DisconnectReason_SERVER_SHUTDOWN + case ParticipantCloseReasonVerifyFailed, ParticipantCloseReasonJoinFailed, ParticipantCloseReasonJoinTimeout: + // expected to be connected but is not + return livekit.DisconnectReason_JOIN_FAILURE + case ParticipantCloseReasonPeerConnectionDisconnected: + return livekit.DisconnectReason_STATE_MISMATCH + case ParticipantCloseReasonDuplicateIdentity, ParticipantCloseReasonMigrationComplete, ParticipantCloseReasonStale: + return livekit.DisconnectReason_DUPLICATE_IDENTITY + case ParticipantCloseReasonServiceRequestRemoveParticipant: + return livekit.DisconnectReason_PARTICIPANT_REMOVED + case ParticipantCloseReasonServiceRequestDeleteRoom: + return livekit.DisconnectReason_ROOM_DELETED + case ParticipantCloseReasonSimulateMigration: + return livekit.DisconnectReason_DUPLICATE_IDENTITY + case ParticipantCloseReasonSimulateNodeFailure: + return livekit.DisconnectReason_SERVER_SHUTDOWN + case ParticipantCloseReasonSimulateServerLeave: + return livekit.DisconnectReason_SERVER_SHUTDOWN + default: + // the other types will map to unknown reason + return livekit.DisconnectReason_UNKNOWN_REASON + } +} + // --------------------------------------------- //counterfeiter:generate . Participant diff --git a/pkg/service/roommanager.go b/pkg/service/roommanager.go index 113349cdc..3c64d639c 100644 --- a/pkg/service/roommanager.go +++ b/pkg/service/roommanager.go @@ -218,6 +218,7 @@ func (r *RoomManager) StartSession( Message: &livekit.SignalResponse_Leave{ Leave: &livekit.LeaveRequest{ CanReconnect: true, + Reason: livekit.DisconnectReason_STATE_MISMATCH, }, }, })