mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-12 14:52:07 +08:00
接入萤石摄像头后端优化
This commit is contained in:
@@ -26,6 +26,7 @@ func InitRouter() *transport.HttpServer {
|
||||
// 是否允许跨域
|
||||
if serverConfig.Cors {
|
||||
container.Filter(middleware.Cors(container).Filter)
|
||||
container.Filter(container.OPTIONSFilter)
|
||||
}
|
||||
// 流量限制
|
||||
if serverConfig.Rate.Enable {
|
||||
|
||||
@@ -37,10 +37,9 @@ func (s *HttpServer) Type() Type {
|
||||
func (s *HttpServer) Start(ctx context.Context) error {
|
||||
global.Log.Infof("HTTP Server listen: %s", s.Addr)
|
||||
go func() {
|
||||
s.srv.ListenAndServe()
|
||||
/*if err := s.srv.ListenAndServe(); err != nil {
|
||||
if err := s.srv.ListenAndServe(); err != nil {
|
||||
global.Log.Errorf("error http serve: %s", err)
|
||||
}*/
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (ys *Ys) GetDeviceLiveAddress(deviceSerial string, channelNo int) (live []L
|
||||
params := make(map[string]interface{})
|
||||
params["deviceSerial"] = deviceSerial
|
||||
params["channelNo"] = channelNo
|
||||
params["protocol"] = 1 //流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
|
||||
params["protocol"] = 4 //流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
|
||||
params["type"] = "1" //地址的类型,1-预览,2-本地录像回放,3-云存储录像回放,非必选,默认为1;回放仅支持rtmp、ezopen、flv协议
|
||||
params["quality"] = 1 //视频清晰度,1-高清(主码流)、2-流畅(子码流)
|
||||
_, err = ys.authorizeRequset("POST", DEVICELIVEADDRESS, params, &live)
|
||||
|
||||
@@ -26,6 +26,7 @@ type Device struct {
|
||||
Status int `json:"status"`
|
||||
Defence int `json:"defence"`
|
||||
DeviceVersion string `json:"deviceVersion"`
|
||||
NetAddress string `json:"netAddress"`
|
||||
}
|
||||
|
||||
// Channel 萤石摄像头通道数据结构
|
||||
|
||||
33
pkg/ys/ys.go
33
pkg/ys/ys.go
@@ -1,12 +1,10 @@
|
||||
package ys
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"github.com/PandaXGO/PandaKit/httpclient"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -75,36 +73,19 @@ func (ys *Ys) requset(method, url string, params map[string]interface{}, data in
|
||||
return
|
||||
}
|
||||
}()
|
||||
var r http.Request
|
||||
r.ParseForm()
|
||||
ps := make([]string, 0)
|
||||
for k, v := range params {
|
||||
r.Form.Add(k, fmt.Sprint(v))
|
||||
ps = append(ps, fmt.Sprintf("%s=%v", k, v))
|
||||
}
|
||||
req, err := http.NewRequest(method, url, strings.NewReader(r.Form.Encode()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
client := &http.Client{Timeout: 60 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
buf, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res = Status{
|
||||
status = &Status{
|
||||
Data: data,
|
||||
}
|
||||
err = json.Unmarshal(buf, &res)
|
||||
err = httpclient.NewRequest(url).Timeout(60).PostParams(strings.Join(ps, "&")).BodyToObj(status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if res.Code != "200" {
|
||||
return status, errors.New(res.Msg)
|
||||
if status.Code != "200" {
|
||||
return status, errors.New(status.Msg)
|
||||
}
|
||||
return status, nil
|
||||
}
|
||||
|
||||
@@ -9,10 +9,38 @@ func TestYs_GetDeviceList(t *testing.T) {
|
||||
IsRAM: 0,
|
||||
AccountID: "",
|
||||
}
|
||||
devices, total, err := ys.GetDeviceList(1, 10)
|
||||
devices, total, err := ys.GetDeviceList(0, 10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(devices)
|
||||
t.Log(total)
|
||||
}
|
||||
|
||||
func TestYs_GetDeviceChannelList(t *testing.T) {
|
||||
ys := &Ys{
|
||||
AppKey: "",
|
||||
Secret: "",
|
||||
IsRAM: 0,
|
||||
AccountID: "",
|
||||
}
|
||||
chans, err := ys.GetDeviceChannelList("BA1996108")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(chans)
|
||||
}
|
||||
|
||||
func TestYs_GetDeviceDeviceLiveAddress(t *testing.T) {
|
||||
ys := &Ys{
|
||||
AppKey: "2cc6a5edcee046c1b8bc9a857d67a287",
|
||||
Secret: "9eb8f595dc02859c91a5d7d0593f8a07",
|
||||
IsRAM: 0,
|
||||
AccountID: "",
|
||||
}
|
||||
live, err := ys.GetDeviceLiveAddress("BA1996108", 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(live)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user