Files

23 lines
591 B
Go

package asteriskws
import (
"errors"
"net/url"
"strings"
)
func BuildMediaWebSocketURL(baseURL, connectionID string) (string, string, error) {
if strings.TrimSpace(connectionID) == "" {
return "", "", errors.New("media websocket connection id is empty")
}
base := strings.TrimRight(baseURL, "/")
parsed, err := url.Parse(base + "/" + url.PathEscape(connectionID))
if err != nil {
return "", "", err
}
if parsed.Scheme != "ws" && parsed.Scheme != "wss" {
return "", "", errors.New("media websocket URL must use ws or wss")
}
return parsed.String(), parsed.String(), nil
}