github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/egress/types.go (about) 1 package egress 2 3 import "github.com/whoyao/protocol/livekit" 4 5 const ( 6 EgressTypeRoomComposite = "room_composite" 7 EgressTypeWeb = "web" 8 EgressTypeTrackComposite = "track_composite" 9 EgressTypeTrack = "track" 10 11 OutputTypeFile = "file" 12 OutputTypeStream = "stream" 13 OutputTypeSegments = "segments" 14 OutputTypeMultiple = "multiple" 15 16 Unknown = "unknown" 17 ) 18 19 func GetTypes(info *livekit.EgressInfo) (string, string) { 20 switch req := info.Request.(type) { 21 case *livekit.EgressInfo_RoomComposite: 22 return EgressTypeRoomComposite, getOutputType(req.RoomComposite) 23 24 case *livekit.EgressInfo_Web: 25 return EgressTypeWeb, getOutputType(req.Web) 26 27 case *livekit.EgressInfo_TrackComposite: 28 return EgressTypeTrackComposite, getOutputType(req.TrackComposite) 29 30 case *livekit.EgressInfo_Track: 31 switch req.Track.Output.(type) { 32 case *livekit.TrackEgressRequest_File: 33 return EgressTypeTrack, OutputTypeFile 34 case *livekit.TrackEgressRequest_WebsocketUrl: 35 return EgressTypeTrack, OutputTypeStream 36 } 37 } 38 39 return Unknown, Unknown 40 } 41 42 func getOutputType(req interface { 43 GetFile() *livekit.EncodedFileOutput 44 GetStream() *livekit.StreamOutput 45 GetSegments() *livekit.SegmentedFileOutput 46 GetFileOutputs() []*livekit.EncodedFileOutput 47 GetStreamOutputs() []*livekit.StreamOutput 48 GetSegmentOutputs() []*livekit.SegmentedFileOutput 49 }) string { 50 hasFile := len(req.GetFileOutputs()) > 0 51 hasStream := len(req.GetStreamOutputs()) > 0 52 hasSegments := len(req.GetSegmentOutputs()) > 0 53 54 switch { 55 case (hasFile && (hasStream || hasSegments)) || (hasStream && hasSegments): 56 return OutputTypeMultiple 57 case hasFile || req.GetFile() != nil: 58 return OutputTypeFile 59 case hasStream || req.GetStream() != nil: 60 return OutputTypeStream 61 case hasSegments || req.GetSegments() != nil: 62 return OutputTypeSegments 63 } 64 65 return Unknown 66 }