Skip to content

Commit

Permalink
api: sort results of /list endpoints (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed May 18, 2023
1 parent cbc0cb2 commit 6cb3ff0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions internal/core/hls_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"context"
"fmt"
"sort"
"sync"

"github.com/bluenviron/mediamtx/internal/conf"
Expand Down Expand Up @@ -200,6 +201,10 @@ outer:
data.Items = append(data.Items, muxer.apiItem())
}

sort.Slice(data.Items, func(i, j int) bool {
return data.Items[i].Created.Before(data.Items[j].Created)
})

req.res <- hlsManagerAPIMuxersListRes{
data: data,
}
Expand Down
5 changes: 5 additions & 0 deletions internal/core/path_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"context"
"fmt"
"sort"
"sync"

"github.com/bluenviron/mediamtx/internal/conf"
Expand Down Expand Up @@ -513,6 +514,10 @@ func (pm *pathManager) apiPathsList() (*apiPathsList, error) {
res.data.Items = append(res.data.Items, item)
}

sort.Slice(res.data.Items, func(i, j int) bool {
return res.data.Items[i].Name < res.data.Items[j].Name
})

return res.data, nil

case <-pm.ctx.Done():
Expand Down
5 changes: 5 additions & 0 deletions internal/core/rtmp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"net"
"sort"
"sync"

"github.com/google/uuid"
Expand Down Expand Up @@ -223,6 +224,10 @@ outer:
data.Items = append(data.Items, c.apiItem())
}

sort.Slice(data.Items, func(i, j int) bool {
return data.Items[i].Created.Before(data.Items[j].Created)
})

req.res <- rtmpServerAPIConnsListRes{data: data}

case req := <-s.chAPIConnsGet:
Expand Down
9 changes: 9 additions & 0 deletions internal/core/rtsp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"sort"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -360,6 +361,10 @@ func (s *rtspServer) apiConnsList() (*apiRTSPConnsList, error) {
data.Items = append(data.Items, c.apiItem())
}

sort.Slice(data.Items, func(i, j int) bool {
return data.Items[i].Created.Before(data.Items[j].Created)
})

return data, nil
}

Expand Down Expand Up @@ -401,6 +406,10 @@ func (s *rtspServer) apiSessionsList() (*apiRTSPSessionsList, error) {
data.Items = append(data.Items, s.apiItem())
}

sort.Slice(data.Items, func(i, j int) bool {
return data.Items[i].Created.Before(data.Items[j].Created)
})

return data, nil
}

Expand Down
13 changes: 9 additions & 4 deletions internal/core/webrtc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"net/http"
"regexp"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -150,7 +151,7 @@ type webRTCManager struct {
chSessionClose chan *webRTCSession
chSessionAddCandidates chan webRTCSessionAddCandidatesReq
chAPISessionsList chan webRTCManagerAPISessionsListReq
chAPIConnsGet chan webRTCManagerAPISessionsGetReq
chAPISessionsGet chan webRTCManagerAPISessionsGetReq
chAPIConnsKick chan webRTCManagerAPISessionsKickReq

// out
Expand Down Expand Up @@ -194,7 +195,7 @@ func newWebRTCManager(
chSessionClose: make(chan *webRTCSession),
chSessionAddCandidates: make(chan webRTCSessionAddCandidatesReq),
chAPISessionsList: make(chan webRTCManagerAPISessionsListReq),
chAPIConnsGet: make(chan webRTCManagerAPISessionsGetReq),
chAPISessionsGet: make(chan webRTCManagerAPISessionsGetReq),
chAPIConnsKick: make(chan webRTCManagerAPISessionsKickReq),
done: make(chan struct{}),
}
Expand Down Expand Up @@ -312,9 +313,13 @@ outer:
data.Items = append(data.Items, sx.apiItem())
}

sort.Slice(data.Items, func(i, j int) bool {
return data.Items[i].Created.Before(data.Items[j].Created)
})

req.res <- webRTCManagerAPISessionsListRes{data: data}

case req := <-m.chAPIConnsGet:
case req := <-m.chAPISessionsGet:
sx := m.findSessionByUUID(req.uuid)
if sx == nil {
req.res <- webRTCManagerAPISessionsGetRes{err: fmt.Errorf("not found")}
Expand Down Expand Up @@ -479,7 +484,7 @@ func (m *webRTCManager) apiSessionsGet(uuid uuid.UUID) (*apiWebRTCSession, error
}

select {
case m.chAPIConnsGet <- req:
case m.chAPISessionsGet <- req:
res := <-req.res
return res.data, res.err

Expand Down

0 comments on commit 6cb3ff0

Please sign in to comment.