forked from abourget/ari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridges.go
101 lines (80 loc) · 2.56 KB
/
bridges.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package ari
import "fmt"
type BridgeService struct {
client *Client
}
func (s *BridgeService) List() ([]*Bridge, error) {
var out []*Bridge
return out, s.client.Get("/bridges", nil, &out)
}
func (s *BridgeService) Create(params CreateBridgeParams) (*Bridge, error) {
var out Bridge
return &out, s.client.Post("/bridges", params, &out)
}
type CreateBridgeParams struct {
Type string `json:"type,omitempty"`
BridgeID string `json:"bridgeId,omitempty"`
Name string `json:"name,omitempty"`
}
func (s *BridgeService) Get(bridgeID string) (*Bridge, error) {
var out Bridge
return &out, s.client.Get(fmt.Sprintf("/bridges/%s", bridgeID), nil, &out)
}
func (s *BridgeService) Destroy(bridgeID string) error {
return s.client.Delete(fmt.Sprintf("/bridges/%s", bridgeID), nil)
}
type Bridge struct {
ID string
Name string
Technology string
Creator string
Channels []string
BridgeType string `json:"bridge_type"`
BridgeClass string `json:"bridge_class"`
// For further manipulations
client *Client
}
func (b *Bridge) setClient(client *Client) {
b.client = client
}
func (b *Bridge) Destroy() error {
return b.client.Delete(fmt.Sprintf("/bridges/%s", b.ID), nil)
}
// AddChannel adds a channel to a bridge. `role` can be `participant` or `announcer`
func (b *Bridge) AddChannel(channel string, role RoleType) error {
params := map[string]string{
"channel": channel,
"role": string(role),
}
return b.client.Post(fmt.Sprintf("/bridges/%s/addChannel", b.ID), params, nil)
}
type RoleType string
const (
Participant RoleType = "participant"
Announcer RoleType = "announcer"
)
func (b *Bridge) RemoveChannel(channel string) error {
params := map[string]string{
"channel": channel,
}
return b.client.Post(fmt.Sprintf("/bridges/%s/removeChannel", b.ID), params, nil)
}
// StartMOH starts Music on hold. If mohClass is "", it will not be sent as a param on the request.
func (b *Bridge) StartMOH(mohClass string) error {
var payload interface{}
if mohClass != "" {
payload = map[string]string{"mohClass": mohClass}
}
return b.client.Post(fmt.Sprintf("/bridges/%s/moh", b.ID), payload, nil)
}
func (b *Bridge) StopMOH() error {
return b.client.Delete(fmt.Sprintf("/bridges/%s/moh", b.ID), nil)
}
func (b *Bridge) Play(params PlayParams) (*Playback, error) {
var out Playback
return &out, b.client.Post(fmt.Sprintf("/bridges/%s/play", b.ID), ¶ms, &out)
}
func (b *Bridge) Record(params RecordParams) (*LiveRecording, error) {
var out LiveRecording
return &out, b.client.Post(fmt.Sprintf("/bridges/%s/record", b.ID), ¶ms, &out)
}