diff --git a/channel.go b/channel.go index b85023e..d10ddfd 100644 --- a/channel.go +++ b/channel.go @@ -120,10 +120,10 @@ type Channel interface { // when `Exec`ed, by which audio may be sent or received. The stage version // of this command will not actually communicate with Asterisk until Exec is // called on the returned ExternalMedia channel. - StageExternalMedia(key *Key, opts ExternalMediaOptions) (*ChannelHandle, error) + StageExternalMedia(key *Key, opts ExternalMediaOptions, variables interface{}) (*ChannelHandle, error) // ExternalMedia creates a new non-telephony external media channel by which audio may be sent or received - ExternalMedia(key *Key, opts ExternalMediaOptions) (*ChannelHandle, error) + ExternalMedia(key *Key, opts ExternalMediaOptions, variables interface{}) (*ChannelHandle, error) // Subscribe subscribes on the channel events Subscribe(key *Key, n ...string) Subscription @@ -264,8 +264,8 @@ type ExternalMediaOptions struct { // Direction specifies the directionality of the audio stream. Options include 'both'. This parameter is optional and if not specified, 'both' will be used. Direction string `json:"direction"` - // Variables defines the set of channel variables which should be bound to this channel upon creation. This parameter is optional. - Variables map[string]string `json:"variables"` + // Data defines the set of channel data which should be bound to this channel upon creation. This parameter is optional. + Data string `json:"data"` } // ChannelHandle provides a wrapper on the Channel interface for operations on a particular channel ID. @@ -523,13 +523,13 @@ func (ch *ChannelHandle) StageSnoop(snoopID string, opts *SnoopOptions) (*Channe // when `Exec`ed, by which audio may be sent or received. The stage version // of this command will not actually communicate with Asterisk until Exec is // called on the returned ExternalMedia channel. -func (ch *ChannelHandle) StageExternalMedia(opts ExternalMediaOptions) (*ChannelHandle, error) { - return ch.c.StageExternalMedia(ch.key, opts) +func (ch *ChannelHandle) StageExternalMedia(opts ExternalMediaOptions, variables interface{}) (*ChannelHandle, error) { + return ch.c.StageExternalMedia(ch.key, opts, variables) } // ExternalMedia creates a new non-telephony external media channel by which audio may be sent or received -func (ch *ChannelHandle) ExternalMedia(opts ExternalMediaOptions) (*ChannelHandle, error) { - return ch.c.ExternalMedia(ch.key, opts) +func (ch *ChannelHandle) ExternalMedia(opts ExternalMediaOptions, variables interface{}) (*ChannelHandle, error) { + return ch.c.ExternalMedia(ch.key, opts, variables) } // ---- diff --git a/client/native/channel.go b/client/native/channel.go index 6fde174..013be50 100644 --- a/client/native/channel.go +++ b/client/native/channel.go @@ -3,6 +3,7 @@ package native import ( "errors" "fmt" + "net/url" "time" "github.com/CyCoreSystems/ari/v5" @@ -377,8 +378,8 @@ func (c *Channel) StageSnoop(key *ari.Key, snoopID string, opts *ari.SnoopOption } // ExternalMedia implements the ari.Channel interface -func (c *Channel) ExternalMedia(key *ari.Key, opts ari.ExternalMediaOptions) (*ari.ChannelHandle, error) { - h, err := c.StageExternalMedia(key, opts) +func (c *Channel) ExternalMedia(key *ari.Key, opts ari.ExternalMediaOptions, variables interface{}) (*ari.ChannelHandle, error) { + h, err := c.StageExternalMedia(key, opts, variables) if err != nil { return nil, err } @@ -387,7 +388,7 @@ func (c *Channel) ExternalMedia(key *ari.Key, opts ari.ExternalMediaOptions) (*a } // StageExternalMedia implements the ari.Channel interface -func (c *Channel) StageExternalMedia(key *ari.Key, opts ari.ExternalMediaOptions) (*ari.ChannelHandle, error) { +func (c *Channel) StageExternalMedia(key *ari.Key, opts ari.ExternalMediaOptions, variables interface{}) (*ari.ChannelHandle, error) { if opts.ChannelID == "" { opts.ChannelID = rid.New(rid.Channel) } @@ -424,7 +425,28 @@ func (c *Channel) StageExternalMedia(key *ari.Key, opts ari.ExternalMediaOptions k := c.client.stamp(ari.NewKey(ari.ChannelKey, opts.ChannelID)) return ari.NewChannelHandle(k, c, func(ch *ari.ChannelHandle) error { - return c.client.post("/channels/externalMedia", nil, &opts) + base, err := url.Parse("/channels/externalMedia") + if err != nil { + return err + } + + // mandatory query type parameters + params := url.Values{} + params.Add("app", opts.App) + params.Add("external_host", opts.ExternalHost) + params.Add("format", opts.Format) + + // optional query type parameters + params.Add("encapsulation", opts.Encapsulation) + params.Add("transport", opts.Transport) + params.Add("connection_type", opts.ConnectionType) + params.Add("direction", opts.Direction) + if opts.Data != "" { + params.Add("data", opts.Data) + } + base.RawQuery = params.Encode() + + return c.client.post(base.String(), nil, variables) }), nil }