mediamtx/internal/whip/get_ice_servers.go
2023-08-03 23:12:05 +02:00

34 lines
639 B
Go

package whip
import (
"context"
"fmt"
"net/http"
"github.com/pion/webrtc/v3"
)
// GetICEServers posts a WHIP/WHEP request for ICE servers.
func GetICEServers(
ctx context.Context,
hc *http.Client,
ur string,
) ([]webrtc.ICEServer, error) {
req, err := http.NewRequestWithContext(ctx, "OPTIONS", ur, nil)
if err != nil {
return nil, err
}
res, err := hc.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusNoContent {
return nil, fmt.Errorf("bad status code: %v", res.StatusCode)
}
return LinkHeaderUnmarshal(res.Header["Link"])
}