forked from cryptix/goSam
-
Notifications
You must be signed in to change notification settings - Fork 5
/
stream.go
48 lines (39 loc) · 1.05 KB
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gosam
import (
"fmt"
)
// StreamConnect asks SAM for a TCP-Like connection to dest, has to be called on a new Client
func (c *Client) StreamConnect(dest string) error {
if dest == "" {
return nil
}
r, err := c.sendCmd("STREAM CONNECT ID=%s DESTINATION=%s %s %s\n", c.ID(), dest, c.from(), c.to())
if err != nil {
return err
}
// TODO: move check into sendCmd()
if r.Topic != "STREAM" || r.Type != "STATUS" {
return fmt.Errorf("Stream Connect Unknown Reply: %+v\n", r)
}
result := r.Pairs["RESULT"]
if result != "OK" {
return ReplyError{result, r}
}
return nil
}
// StreamAccept asks SAM to accept a TCP-Like connection
func (c *Client) StreamAccept() (*Reply, error) {
r, err := c.sendCmd("STREAM ACCEPT ID=%s SILENT=false\n", c.ID())
if err != nil {
return nil, err
}
// TODO: move check into sendCmd()
if r.Topic != "STREAM" || r.Type != "STATUS" {
return nil, fmt.Errorf("Stream Accept Unknown Reply: %+v\n", r)
}
result := r.Pairs["RESULT"]
if result != "OK" {
return nil, ReplyError{result, r}
}
return r, nil
}