2014-02-10 21:01:55 +01:00
|
|
|
package goSam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2014-02-14 12:05:13 +01:00
|
|
|
// StreamConnect asks SAM for a TCP-Like connection to dest, has to be called on a new Client
|
2021-04-15 17:21:41 -04:00
|
|
|
func (c *Client) StreamConnect(dest string) error {
|
2020-11-29 16:09:55 -05:00
|
|
|
if dest == "" {
|
2020-11-29 16:23:55 -05:00
|
|
|
return nil
|
2020-11-29 16:09:55 -05:00
|
|
|
}
|
2021-04-15 17:21:41 -04:00
|
|
|
r, err := c.sendCmd("STREAM CONNECT ID=%s DESTINATION=%s %s %s\n", c.ID(), dest, c.from(), c.to())
|
2014-02-10 21:01:55 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:03:05 +01:00
|
|
|
// TODO: move check into sendCmd()
|
2014-02-10 21:01:55 +01:00
|
|
|
if r.Topic != "STREAM" || r.Type != "STATUS" {
|
2020-09-13 01:32:22 -04:00
|
|
|
return fmt.Errorf("Stream Connect Unknown Reply: %+v\n", r)
|
2014-02-10 21:01:55 +01:00
|
|
|
}
|
|
|
|
|
2014-02-11 13:11:26 +01:00
|
|
|
result := r.Pairs["RESULT"]
|
|
|
|
if result != "OK" {
|
2014-02-11 14:08:52 +01:00
|
|
|
return ReplyError{result, r}
|
2014-02-10 21:01:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2014-02-12 22:14:19 +01:00
|
|
|
|
2014-02-14 12:05:13 +01:00
|
|
|
// StreamAccept asks SAM to accept a TCP-Like connection
|
2021-04-15 17:21:41 -04:00
|
|
|
func (c *Client) StreamAccept() (*Reply, error) {
|
|
|
|
r, err := c.sendCmd("STREAM ACCEPT ID=%s SILENT=false\n", c.ID())
|
2014-02-12 22:14:19 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:03:05 +01:00
|
|
|
// TODO: move check into sendCmd()
|
2014-02-12 22:14:19 +01:00
|
|
|
if r.Topic != "STREAM" || r.Type != "STATUS" {
|
2020-09-13 01:32:22 -04:00
|
|
|
return nil, fmt.Errorf("Stream Accept Unknown Reply: %+v\n", r)
|
2014-02-12 22:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result := r.Pairs["RESULT"]
|
|
|
|
if result != "OK" {
|
|
|
|
return nil, ReplyError{result, r}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r, nil
|
|
|
|
}
|