github.com/optim-corp/cios-golang-sdk@v0.5.1/sdk/service/video/video_streaming.go (about) 1 package srvvideo 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "log" 7 _http "net/http" 8 "net/http/httputil" 9 10 "github.com/fcfcqloow/go-advance/check" 11 cnv "github.com/fcfcqloow/go-advance/convert" 12 13 "github.com/optim-corp/cios-golang-sdk/cios" 14 ciosctx "github.com/optim-corp/cios-golang-sdk/ctx" 15 "github.com/optim-corp/cios-golang-sdk/util" 16 ) 17 18 func MakeGetVideosOpts() cios.ApiGetVideoStreamsListRequest { 19 return cios.ApiGetVideoStreamsListRequest{} 20 } 21 22 func (self *CiosVideoStreaming) GetVideoInfos(ctx ciosctx.RequestCtx, params cios.ApiGetVideoStreamsListRequest) ([]cios.Video, *_http.Response, error) { 23 if err := self.refresh(); err != nil { 24 return nil, nil, err 25 } 26 params.Ctx = self.withHost(ctx) 27 params.ApiService = self.ApiClient.VideostreamingOperationsApi 28 params.P_deviceId = util.ToNil(params.P_deviceId) 29 params.P_resourceOwnerId = util.ToNil(params.P_resourceOwnerId) 30 r, h, e := params.Execute() 31 if e != nil { 32 return nil, nil, e 33 } 34 return r.Videos, h, e 35 } 36 func (self *CiosVideoStreaming) GetVideoInfo(ctx ciosctx.RequestCtx, videoID string) (cios.Video, *_http.Response, error) { 37 if err := self.refresh(); err != nil { 38 return cios.Video{}, nil, err 39 } 40 response, httpResponse, err := self.ApiClient.VideostreamingOperationsApi.GetVideoStreams(self.withHost(ctx), videoID).Execute() 41 if err != nil { 42 return cios.Video{}, httpResponse, err 43 } 44 return response.Video, httpResponse, err 45 } 46 47 func (self *CiosVideoStreaming) UpdateVideoInfo(ctx ciosctx.RequestCtx, videoID string, name, description string) (cios.Video, *_http.Response, error) { 48 if err := self.refresh(); err != nil { 49 return cios.Video{}, nil, err 50 } 51 response, httpResponse, err := self.ApiClient.VideostreamingOperationsApi. 52 UpdateStreams(self.withHost(ctx), videoID). 53 VideoUpdateRequest(cios.VideoUpdateRequest{ 54 VideoName: util.ToNilStr(name), 55 VideoDescription: util.ToNilStr(description), 56 }).Execute() 57 if err != nil { 58 return cios.Video{}, httpResponse, err 59 } 60 return response.Video, httpResponse, err 61 } 62 63 // MEMO: No OpenAPI 64 func (self *CiosVideoStreaming) GetThumbnail(ctx ciosctx.RequestCtx, videoID string) (img []byte, httpResponse *_http.Response, err error) { 65 if err := self.refresh(); err != nil { 66 return nil, nil, err 67 } 68 69 req, err := _http.NewRequest(_http.MethodGet, fmt.Sprintf("%s/v2/video_streams/%s/thumbnail", self.Url, videoID), nil) 70 if err != nil { 71 return 72 } 73 74 token := ciosctx.Token(ctx) 75 if check.IsNil(token) { 76 token = self.token 77 } 78 79 req.Header.Add("Authentication", cnv.MustStr(token)) 80 81 if self.ApiClient.GetConfig().Debug { 82 dump, err := httputil.DumpRequestOut(req, true) 83 if err != nil { 84 return nil, nil, err 85 } 86 log.Printf("\n%s\n", string(dump)) 87 } 88 89 if httpResponse, err = self.ApiClient.GetConfig().HTTPClient.Do(req); err == nil { 90 defer httpResponse.Body.Close() 91 img, err = ioutil.ReadAll(httpResponse.Body) 92 } 93 94 if err != nil { 95 return 96 } 97 98 if self.ApiClient.GetConfig().Debug { 99 dump, err := httputil.DumpResponse(httpResponse, true) 100 if err != nil { 101 return nil, httpResponse, err 102 } 103 log.Printf("\n%s\n", string(dump)) 104 } 105 return 106 } 107 108 func (self *CiosVideoStreaming) Play(ctx ciosctx.RequestCtx, videoID string) (cios.Room, *_http.Response, error) { 109 if err := self.refresh(); err != nil { 110 return cios.Room{}, nil, err 111 } 112 room, httpResponse, err := self.ApiClient.VideostreamingOperationsApi.CreateVideoStreamsPlay(self.withHost(ctx), videoID).Execute() 113 if err != nil { 114 return cios.Room{}, httpResponse, err 115 } 116 return room.Room, httpResponse, err 117 } 118 func (self *CiosVideoStreaming) Stop(ctx ciosctx.RequestCtx, videoID string) (*_http.Response, error) { 119 if err := self.refresh(); err != nil { 120 return nil, err 121 } 122 return self.ApiClient.VideostreamingOperationsApi.CreateVideoStreamsStop(self.withHost(ctx), videoID).Execute() 123 }