-
Notifications
You must be signed in to change notification settings - Fork 1
/
streamFile.go
179 lines (148 loc) · 6.57 KB
/
streamFile.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package wserest
import (
"strconv"
"github.com/openfresh/wse-rest-library-go/entity/application"
"github.com/openfresh/wse-rest-library-go/entity/application/helper"
"github.com/openfresh/wse-rest-library-go/entity/base"
)
// StreamFile is Stream File utility
type StreamFile struct {
wowza
applicationName string
mediaCasterType string
applicationInstance string
}
// NewStreamFile create StreamFile
func NewStreamFile(settings *helper.Settings, appName, streamFileName string) *StreamFile {
s := new(StreamFile)
s.init(settings)
s.baseURI = s.host() + "/servers/" + s.serverInstance() + "/vhosts/" + s.vHostInstance() + "/applications/" + appName + "/streamfiles"
if appName != "" {
s.applicationName = appName
}
if streamFileName != "" {
s.props["name"] = streamFileName
}
return s
}
// Get retrieves the specified Stream File configuration
func (s *StreamFile) Get() (map[string]interface{}, error) {
s.AddSkipParameter("name")
s.setRestURI(s.baseURI + "/" + s.props["name"].(string))
return s.sendRequest(s.preparePropertiesForRequest(), []base.Entity{}, GET, "")
}
// GetAll retrieves the list of Stream Files for the specified VHost
func (s *StreamFile) GetAll() (map[string]interface{}, error) {
s.AddSkipParameter("name")
s.setRestURI(s.baseURI)
return s.sendRequest(s.preparePropertiesForRequest(), []base.Entity{}, GET, "")
}
// Create adds the specified Stream File configuration
func (s *StreamFile) Create(urlProps map[string]interface{}, mediaCasterType string, applicationInstance string) (map[string]interface{}, error) {
if mediaCasterType == "" {
mediaCasterType = "rtp"
}
if applicationInstance == "" {
applicationInstance = "_definst_"
}
s.mediaCasterType = mediaCasterType
s.applicationInstance = applicationInstance
sf := application.NewStreamFiles()
sf.ID = "connectAppName=" + s.applicationName + "&appInstance=" + applicationInstance + "&mediaCasterType=" + mediaCasterType
sf.Href = s.baseURI + "/streamfiles/" + sf.ID
entities := s.getEntities([]base.Entity{sf}, "")
s.setRestURI(s.baseURI + "/" + s.props["name"].(string))
response, err := s.sendRequest(s.preparePropertiesForRequest(), entities, POST, "")
if err == nil {
items := s.getAdvancedSettings(urlProps)
return s.addURL(items)
}
return response, err
}
func (s *StreamFile) addURL(advancedSettings []*helper.AdvancedSettingItem) (map[string]interface{}, error) {
s.AddSkipParameter("name")
s.setRestURI(s.props["restURI"].(string) + "/adv")
s.AddAdditionalParameter("version", "1430601267443")
s.AddAdditionalParameter("advancedSettings", advancedSettings)
return s.sendRequest(s.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
func (s *StreamFile) getAdvancedSettings(urlProps map[string]interface{}) []*helper.AdvancedSettingItem {
items := make([]*helper.AdvancedSettingItem, 0)
for k, v := range urlProps {
item := helper.NewAdvancedSettingItem()
item.Name = k
switch t := v.(type) {
default:
case bool:
item.Value = strconv.FormatBool(t)
item.Type = "Boolean"
case int:
item.Value = strconv.Itoa(t)
item.Type = "Integer"
case string:
item.Value = t
item.Type = "String"
}
items = append(items, item)
}
return items
}
// Update updates the Advanced Stream File configuration
func (s *StreamFile) Update(urlProps map[string]interface{}) (map[string]interface{}, error) {
s.setRestURI(s.baseURI + "/" + s.props["name"].(string))
items := s.getAdvancedSettings(urlProps)
return s.addURL(items)
}
// Remove deletes the specified Stream File configuration
func (s *StreamFile) Remove() (map[string]interface{}, error) {
s.AddSkipParameter("name")
s.setRestURI(s.baseURI + "/" + s.props["name"].(string))
return s.sendRequest(s.preparePropertiesForRequest(), []base.Entity{}, DELETE, "")
}
// Connect connects
func (s *StreamFile) Connect(subFolder string) (map[string]interface{}, error) {
s.AddSkipParameter("name")
// s.AddAdditionalParameter("connectAppName", s.applicationName)
// s.AddAdditionalParameter("appInstance", s.applicationInstance)
// s.AddAdditionalParameter("mediaCasterType", s.mediaCasterType)
streamFilePath := ""
if subFolder != "" {
streamFilePath = subFolder + "/" + s.props["name"].(string)
} else {
streamFilePath = s.props["name"].(string)
}
s.setRestURI(s.baseURI + "/" + streamFilePath + "/actions/connect")
return s.sendRequest(s.preparePropertiesForRequest(), []base.Entity{}, PUT,
"connectAppName="+s.applicationName+"&appInstance="+s.applicationInstance+"&mediaCasterType="+s.mediaCasterType)
}
// Disconnect disconnect
func (s *StreamFile) Disconnect() (map[string]interface{}, error) {
/*
* curl -X PUT --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8'
* "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/[YOUR-APP-NAME]/instances/_definst_/incomingstreams/[STREAM-FILE-NAME]/actions/disconnectStream"
*
*
* "http:\/\/127.0.0.1:8087\/v2\/servers\/_defaultServer_\/vhosts\/_defaultVHost_\/applications\/live\/instances\/_definst_\/incomingstreams\/bolton_mass\/actions\/disconnectStream"
*/
s.AddSkipParameter("name")
// s.AddAdditionalParameter("connectAppName", s.applicationName)
// s.AddAdditionalParameter("appInstance", s.applicationInstance)
// s.AddAdditionalParameter("mediaCasterType", s.mediaCasterType)
baseURI := s.host() + "/servers/" + s.serverInstance() + "/vhosts/" + s.vHostInstance() + "/applications/" + s.applicationName + "/instances/"
s.setRestURI(baseURI + s.applicationInstance + "/incomingstreams/" + s.props["name"].(string) + ".stream/actions/disconnectStream")
return s.sendRequest(s.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// Reset stream
func (s *StreamFile) Reset() (map[string]interface{}, error) {
/*
* curl -X PUT --header 'Accept:application/json; charset=utf-8' --header 'Content-type:application/json; charset=utf-8'
* "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/[YOUR-APP-NAME]/instances/_definst_/incomingstreams/[STREAM-FILE-NAME]/actions/resetStream"
*
*
* "http:\/\/127.0.0.1:8087\/v2\/servers\/_defaultServer_\/vhosts\/_defaultVHost_\/applications\/live\/instances\/_definst_\/incomingstreams\/bolton_mass\/actions\/resetStream"
*/
s.AddSkipParameter("name")
baseURI := s.host() + "/servers/" + s.serverInstance() + "/vhosts/" + s.vHostInstance() + "/applications/" + s.applicationName + "/instances/"
s.setRestURI(baseURI + s.applicationInstance + "/incomingstreams/" + s.props["name"].(string) + ".stream/actions/resetStream")
return s.sendRequest(s.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}