mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-17 20:24:38 +00:00
34 lines
639 B
Go
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"])
|
||
|
}
|