Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

63 řádky
1.4KB

  1. package nmos
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "fmt"
  7. "net/http"
  8. "strings"
  9. "time"
  10. )
  11. type ConnectionClient struct {
  12. BaseURL string
  13. HTTPClient *http.Client
  14. }
  15. func NewConnectionClient(baseURL string) *ConnectionClient {
  16. return &ConnectionClient{
  17. BaseURL: strings.TrimRight(baseURL, "/"),
  18. HTTPClient: &http.Client{
  19. Timeout: 10 * time.Second,
  20. },
  21. }
  22. }
  23. func (c *ConnectionClient) StageReceiver(ctx context.Context, receiverID string, reqBody StagedReceiverRequest) error {
  24. body, err := json.Marshal(reqBody)
  25. if err != nil {
  26. return err
  27. }
  28. url := fmt.Sprintf("%s/x-nmos/connection/v1.1/receivers/%s/staged", c.BaseURL, receiverID)
  29. req, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, bytes.NewReader(body))
  30. if err != nil {
  31. return err
  32. }
  33. req.Header.Set("Content-Type", "application/json")
  34. resp, err := c.HTTPClient.Do(req)
  35. if err != nil {
  36. return err
  37. }
  38. defer resp.Body.Close()
  39. if resp.StatusCode < 200 || resp.StatusCode >= 300 {
  40. return fmt.Errorf("NMOS IS-05 stage receiver returned %s", resp.Status)
  41. }
  42. return nil
  43. }
  44. func BuildRTPReceiverStagedRequest(senderID *string, sdp string) StagedReceiverRequest {
  45. transportFile := map[string]string{
  46. "data": sdp,
  47. "type": "application/sdp",
  48. }
  49. return StagedReceiverRequest{
  50. MasterEnable: true,
  51. Activation: Activation{
  52. Mode: "activate_immediate",
  53. },
  54. SenderID: senderID,
  55. TransportFile: transportFile,
  56. }
  57. }