Sends disconnect reason when server sends Leave request (#801)

* Sends disconnect reason when server sends Leave request

* update go.mod
This commit is contained in:
David Zhao
2022-07-02 21:22:26 -07:00
committed by GitHub
parent d0bbea6e91
commit f1f62ddda5
5 changed files with 36 additions and 4 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+3 -1
View File
@@ -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(),
},
},
})
}
+29
View File
@@ -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
+1
View File
@@ -218,6 +218,7 @@ func (r *RoomManager) StartSession(
Message: &livekit.SignalResponse_Leave{
Leave: &livekit.LeaveRequest{
CanReconnect: true,
Reason: livekit.DisconnectReason_STATE_MISMATCH,
},
},
})