api: add push start command

This commit is contained in:
Geno 2021-08-22 17:12:32 +02:00
parent 81c0ed4793
commit a94acd17ad
1 changed files with 25 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
// API URLS for Push // API URLS for Push
const ( const (
URLRequestPushStatus = "/v1/vhosts/%s/apps/%s:pushes" URLRequestPushStatus = "/v1/vhosts/%s/apps/%s:pushes"
URLRequestPushStart = "/v1/vhosts/%s/apps/%s:startPush"
URLRequestPushStop = "/v1/vhosts/%s/apps/%s:stopPush" URLRequestPushStop = "/v1/vhosts/%s/apps/%s:stopPush"
) )
@ -41,6 +42,15 @@ type ResponsePushData struct {
TotalSentTime uint64 `json:"totalsentTime" example:"933808"` TotalSentTime uint64 `json:"totalsentTime" example:"933808"`
} }
// ResponsePushStart one push configuration
type ResponsePushStart struct {
ID string `json:"id" example:"youtube"`
Stream *ResponsePushDataStream `json:"stream"`
Protocol string `json:"protocol" example:"rtmp"`
URL string `json:"url" example:"rtmp://a.rtmp.youtube.com/live2"`
StreamKey string `json:"streamKey" example:"SUPERSECRET"`
}
// ResponsePushDataStream of data of stream // ResponsePushDataStream of data of stream
type ResponsePushDataStream struct { type ResponsePushDataStream struct {
Name string `json:"name" example:"..."` Name string `json:"name" example:"..."`
@ -62,6 +72,21 @@ func (c *Client) RequestPushStatusDefault() (*ResponsePushStatus, error) {
return c.RequestPushStatus(c.DefaultVHost, c.DefaultApp) return c.RequestPushStatus(c.DefaultVHost, c.DefaultApp)
} }
// StartPush to delete an push
func (c *Client) StartPush(vhost, app string, data *ResponsePushStart) (*ResponsePushStatus, error) {
req := ResponsePushStatus{}
url := fmt.Sprintf(URLRequestPushStart, vhost, app)
if err := c.Request(http.MethodPost, url, &data, &req); err != nil {
return &req, err
}
return &req, nil
}
// StartPushDefault to delete an push and on default vhost and app
func (c *Client) StartPushDefault(data *ResponsePushStart) (*ResponsePushStatus, error) {
return c.StartPush(c.DefaultVHost, c.DefaultApp, data)
}
// DeletePush to delete an push // DeletePush to delete an push
func (c *Client) DeletePush(vhost, app, id string) error { func (c *Client) DeletePush(vhost, app, id string) error {
type idJSON struct { type idJSON struct {