14 // CreateLiveChannel create a live-channel
16 // channelName the name of the channel
17 // config configuration of the channel
19 // CreateLiveChannelResult the result of create live-channel
20 // error nil if success, otherwise error
22 func (bucket Bucket) CreateLiveChannel(channelName string, config LiveChannelConfiguration) (CreateLiveChannelResult, error) {
23 var out CreateLiveChannelResult
25 bs, err := xml.Marshal(config)
30 buffer := new(bytes.Buffer)
33 params := map[string]interface{}{}
35 resp, err := bucket.do("PUT", channelName, params, nil, buffer, nil)
39 defer resp.Body.Close()
41 err = xmlUnmarshal(resp.Body, &out)
46 // PutLiveChannelStatus Set the status of the live-channel: enabled/disabled
48 // channelName the name of the channel
49 // status enabled/disabled
51 // error nil if success, otherwise error
53 func (bucket Bucket) PutLiveChannelStatus(channelName, status string) error {
54 params := map[string]interface{}{}
56 params["status"] = status
58 resp, err := bucket.do("PUT", channelName, params, nil, nil, nil)
62 defer resp.Body.Close()
64 return CheckRespCode(resp.StatusCode, []int{http.StatusOK})
67 // PostVodPlaylist create an playlist based on the specified playlist name, startTime and endTime
69 // channelName the name of the channel
70 // playlistName the name of the playlist, must end with ".m3u8"
71 // startTime the start time of the playlist
72 // endTime the endtime of the playlist
74 // error nil if success, otherwise error
76 func (bucket Bucket) PostVodPlaylist(channelName, playlistName string, startTime, endTime time.Time) error {
77 params := map[string]interface{}{}
79 params["startTime"] = strconv.FormatInt(startTime.Unix(), 10)
80 params["endTime"] = strconv.FormatInt(endTime.Unix(), 10)
82 key := fmt.Sprintf("%s/%s", channelName, playlistName)
83 resp, err := bucket.do("POST", key, params, nil, nil, nil)
87 defer resp.Body.Close()
89 return CheckRespCode(resp.StatusCode, []int{http.StatusOK})
92 // GetVodPlaylist get the playlist based on the specified channelName, startTime and endTime
94 // channelName the name of the channel
95 // startTime the start time of the playlist
96 // endTime the endtime of the playlist
98 // io.ReadCloser reader instance for reading data from response. It must be called close() after the usage and only valid when error is nil.
99 // error nil if success, otherwise error
101 func (bucket Bucket) GetVodPlaylist(channelName string, startTime, endTime time.Time) (io.ReadCloser, error) {
102 params := map[string]interface{}{}
104 params["startTime"] = strconv.FormatInt(startTime.Unix(), 10)
105 params["endTime"] = strconv.FormatInt(endTime.Unix(), 10)
107 resp, err := bucket.do("GET", channelName, params, nil, nil, nil)
112 return resp.Body, nil
116 // GetLiveChannelStat Get the state of the live-channel
118 // channelName the name of the channel
120 // LiveChannelStat the state of the live-channel
121 // error nil if success, otherwise error
123 func (bucket Bucket) GetLiveChannelStat(channelName string) (LiveChannelStat, error) {
124 var out LiveChannelStat
125 params := map[string]interface{}{}
127 params["comp"] = "stat"
129 resp, err := bucket.do("GET", channelName, params, nil, nil, nil)
133 defer resp.Body.Close()
135 err = xmlUnmarshal(resp.Body, &out)
140 // GetLiveChannelInfo Get the configuration info of the live-channel
142 // channelName the name of the channel
144 // LiveChannelConfiguration the configuration info of the live-channel
145 // error nil if success, otherwise error
147 func (bucket Bucket) GetLiveChannelInfo(channelName string) (LiveChannelConfiguration, error) {
148 var out LiveChannelConfiguration
149 params := map[string]interface{}{}
152 resp, err := bucket.do("GET", channelName, params, nil, nil, nil)
156 defer resp.Body.Close()
158 err = xmlUnmarshal(resp.Body, &out)
163 // GetLiveChannelHistory Get push records of live-channel
165 // channelName the name of the channel
167 // LiveChannelHistory push records
168 // error nil if success, otherwise error
170 func (bucket Bucket) GetLiveChannelHistory(channelName string) (LiveChannelHistory, error) {
171 var out LiveChannelHistory
172 params := map[string]interface{}{}
174 params["comp"] = "history"
176 resp, err := bucket.do("GET", channelName, params, nil, nil, nil)
180 defer resp.Body.Close()
182 err = xmlUnmarshal(resp.Body, &out)
187 // ListLiveChannel list the live-channels
189 // options Prefix: filter by the name start with the value of "Prefix"
190 // MaxKeys: the maximum count returned
191 // Marker: cursor from which starting list
193 // ListLiveChannelResult live-channel list
194 // error nil if success, otherwise error
196 func (bucket Bucket) ListLiveChannel(options ...Option) (ListLiveChannelResult, error) {
197 var out ListLiveChannelResult
199 params, err := GetRawParams(options)
206 resp, err := bucket.do("GET", "", params, nil, nil, nil)
210 defer resp.Body.Close()
212 err = xmlUnmarshal(resp.Body, &out)
217 // DeleteLiveChannel Delete the live-channel. When a client trying to stream the live-channel, the operation will fail. it will only delete the live-channel itself and the object generated by the live-channel will not be deleted.
219 // channelName the name of the channel
221 // error nil if success, otherwise error
223 func (bucket Bucket) DeleteLiveChannel(channelName string) error {
224 params := map[string]interface{}{}
227 if channelName == "" {
228 return fmt.Errorf("invalid argument: channel name is empty")
231 resp, err := bucket.do("DELETE", channelName, params, nil, nil, nil)
235 defer resp.Body.Close()
237 return CheckRespCode(resp.StatusCode, []int{http.StatusNoContent})
241 // SignRtmpURL Generate a RTMP push-stream signature URL for the trusted user to push the RTMP stream to the live-channel.
243 // channelName the name of the channel
244 // playlistName the name of the playlist, must end with ".m3u8"
245 // expires expiration (in seconds)
247 // string singed rtmp push stream url
248 // error nil if success, otherwise error
250 func (bucket Bucket) SignRtmpURL(channelName, playlistName string, expires int64) (string, error) {
252 return "", fmt.Errorf("invalid argument: %d, expires must greater than 0", expires)
254 expiration := time.Now().Unix() + expires
256 return bucket.Client.Conn.signRtmpURL(bucket.BucketName, channelName, playlistName, expiration), nil