mirror of
https://github.com/gowvp/gb28181.git
synced 2026-04-22 23:17:19 +08:00
显示播放状态
This commit is contained in:
@@ -10,7 +10,7 @@ require (
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
github.com/google/wire v0.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/ixugo/goddd v1.3.6
|
||||
github.com/ixugo/goddd v1.3.9
|
||||
github.com/jinzhu/copier v0.4.0
|
||||
github.com/pelletier/go-toml/v2 v2.2.3
|
||||
github.com/shirou/gopsutil/v4 v4.25.7
|
||||
|
||||
@@ -59,8 +59,8 @@ github.com/google/wire v0.6.0 h1:HBkoIh4BdSxoyo9PveV8giw7ZsaBOvzWKfcg/6MrVwI=
|
||||
github.com/google/wire v0.6.0/go.mod h1:F4QhpQ9EDIdJ1Mbop/NZBRB+5yrR6qg3BnctaoUk6NA=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/ixugo/goddd v1.3.6 h1:jOCXGkn1Dh7lLmzj1LOVP6ME1mjhcp1Ao6E1cy6iQds=
|
||||
github.com/ixugo/goddd v1.3.6/go.mod h1:gb102fElow80HXqvrTlJ56eE5vFEYnI7Nx46Iw/m5eU=
|
||||
github.com/ixugo/goddd v1.3.9 h1:i3AducuSOrrUaRmoHfF1OuvoEvLP30mfw6g5E3dWz9w=
|
||||
github.com/ixugo/goddd v1.3.9/go.mod h1:gb102fElow80HXqvrTlJ56eE5vFEYnI7Nx46Iw/m5eU=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ func Run(bc *conf.Bootstrap) {
|
||||
go setupZLM(ctx, bc.ConfigDir)
|
||||
|
||||
// 如果需要执行表迁移,递增此版本号和表更新说明
|
||||
versionapi.DBVersion = "0.0.11"
|
||||
versionapi.DBVersion = "0.0.12"
|
||||
versionapi.DBRemark = "add stream proxy"
|
||||
|
||||
handler, cleanUp, err := wireApp(bc, log)
|
||||
|
||||
@@ -12,6 +12,7 @@ type Channel struct {
|
||||
Name string `gorm:"column:name;notNull;default:'';comment:通道名称" json:"name"` // 通道名称
|
||||
PTZType int `gorm:"column:ptztype;notNull;default:0;comment:云台类型" json:"ptztype"` // 云台类型
|
||||
IsOnline bool `gorm:"column:is_online;notNull;default:FALSE;comment:是否在线" json:"is_online"` // 是否在线
|
||||
IsPlaying bool `gorm:"column:is_playing;notNull;default:FALSE;comment:是否播放中" json:"is_playing"` // 是否播放中
|
||||
Ext DeviceExt `gorm:"column:ext;notNull;default:'{}';type:jsonb" json:"ext"`
|
||||
CreatedAt orm.Time `gorm:"column:created_at;notNull;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt orm.Time `gorm:"column:updated_at;notNull;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
|
||||
@@ -47,6 +47,7 @@ func (c Core) FindChannelsForDevice(ctx context.Context, in *FindDeviceInput) ([
|
||||
for _, ch := range item.Children {
|
||||
if !item.IsOnline {
|
||||
ch.IsOnline = false
|
||||
ch.IsPlaying = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,7 +123,7 @@ func (c Core) EditDevice(ctx context.Context, in *EditDeviceInput, id string) (*
|
||||
slog.ErrorContext(ctx, "Copy", "err", err)
|
||||
}
|
||||
}, orm.Where("id=?", id)); err != nil {
|
||||
return nil, reason.ErrDB.Withf(`Edit err[%s]`, err.Error())
|
||||
return nil, reason.ErrDB.Withf(`Edit err[%s] id[%s]`, err.Error(), id)
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
@@ -64,6 +64,16 @@ func (g GB28181) Edit(deviceID string, changeFn func(*Device)) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g GB28181) EditPlaying(deviceID, channelID string, playing bool) error {
|
||||
var ch Channel
|
||||
if err := g.store.Channel().Edit(context.TODO(), &ch, func(c *Channel) {
|
||||
c.IsPlaying = playing
|
||||
}, orm.Where("device_id = ? AND channel_id = ?", deviceID, channelID)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g GB28181) SaveChannels(channels []*Channel) error {
|
||||
if len(channels) <= 0 {
|
||||
return nil
|
||||
@@ -74,6 +84,7 @@ func (g GB28181) SaveChannels(channels []*Channel) error {
|
||||
d.Channels = len(channels)
|
||||
}, orm.Where("device_id=?", channels[0].DeviceID))
|
||||
|
||||
// chIDs := make([]string, 0, 8)
|
||||
for _, channel := range channels {
|
||||
var ch Channel
|
||||
if err := g.store.Channel().Edit(context.TODO(), &ch, func(c *Channel) {
|
||||
@@ -84,7 +95,13 @@ func (g GB28181) SaveChannels(channels []*Channel) error {
|
||||
channel.DID = dev.ID
|
||||
g.store.Channel().Add(context.TODO(), channel)
|
||||
}
|
||||
// chIDs = append(chIDs, channel.ID)
|
||||
}
|
||||
|
||||
// TODO: 清理相关资源
|
||||
// if len(chIDs) > 0 {
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -94,14 +94,13 @@ func setupRouter(r *gin.Engine, uc *Usecase) {
|
||||
versionapi.Register(r, uc.Version, auth)
|
||||
statapi.Register(r)
|
||||
registerZLMWebhookAPI(r, uc.WebHookAPI)
|
||||
// TODO: 待增加鉴权
|
||||
|
||||
registerPushAPI(r, uc.MediaAPI)
|
||||
registerGB28181(r, uc.GB28181API)
|
||||
registerProxy(r, uc.ProxyAPI)
|
||||
registerConfig(r, uc.ConfigAPI)
|
||||
registerSms(r, uc.SMSAPI)
|
||||
RegisterUser(r, uc.UserAPI)
|
||||
registerPushAPI(r, uc.MediaAPI, auth)
|
||||
registerGB28181(r, uc.GB28181API, auth)
|
||||
registerProxy(r, uc.ProxyAPI, auth)
|
||||
registerConfig(r, uc.ConfigAPI, auth)
|
||||
registerSms(r, uc.SMSAPI, auth)
|
||||
RegisterUser(r, uc.UserAPI, auth)
|
||||
|
||||
r.Any("/proxy/sms/*path", uc.proxySMS)
|
||||
}
|
||||
|
||||
@@ -301,11 +301,13 @@ func (a GB28181API) refreshSnapshot(c *gin.Context, in *refreshSnapshotInput) (a
|
||||
|
||||
path := readCoverPath(a.uc.Conf.ConfigDir, channelID)
|
||||
|
||||
token := c.GetString("token")
|
||||
|
||||
// 获取文件的修改时间
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err == nil {
|
||||
if fileInfo.ModTime().Unix() > time.Now().Unix()-in.WithinSeconds {
|
||||
return gin.H{"link": fmt.Sprintf("/api/channels/%s/snapshot", channelID)}, nil
|
||||
return gin.H{"link": fmt.Sprintf("%s/channels/%s/snapshot?token=%s", web.GetBaseURL(c.Request), channelID, token)}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +330,7 @@ func (a GB28181API) refreshSnapshot(c *gin.Context, in *refreshSnapshotInput) (a
|
||||
}
|
||||
}
|
||||
|
||||
return gin.H{"link": fmt.Sprintf("/channels/%s/snapshot", channelID)}, nil
|
||||
return gin.H{"link": fmt.Sprintf("%s/channels/%s/snapshot?token=%s", web.GetBaseURL(c.Request), channelID, token)}, nil
|
||||
}
|
||||
|
||||
func (a GB28181API) getSnapshot(c *gin.Context) {
|
||||
|
||||
@@ -62,7 +62,7 @@ func NewHTTPHandler(uc *Usecase) http.Handler {
|
||||
cfg := uc.Conf.Server
|
||||
// 检查是否设置了 JWT 密钥,如果未设置,则生成一个长度为 32 的随机字符串作为密钥
|
||||
if cfg.HTTP.JwtSecret == "" {
|
||||
cfg.HTTP.JwtSecret = orm.GenerateRandomString(32) // 生成一个长度为 32 的随机字符串作为密钥
|
||||
uc.Conf.Server.HTTP.JwtSecret = orm.GenerateRandomString(32) // 生成一个长度为 32 的随机字符串作为密钥
|
||||
}
|
||||
// 如果不处于调试模式,将 Gin 设置为发布模式
|
||||
if !cfg.Debug {
|
||||
|
||||
@@ -54,6 +54,10 @@ func (g *GB28181API) StopPlay(in *StopPlayInput) error {
|
||||
|
||||
ch.device.playMutex.Lock()
|
||||
defer ch.device.playMutex.Unlock()
|
||||
|
||||
defer func() {
|
||||
g.svr.gb.core.EditPlaying(in.Channel.DeviceID, in.Channel.ChannelID, false)
|
||||
}()
|
||||
return g.stopPlay(ch, in)
|
||||
}
|
||||
|
||||
@@ -102,6 +106,8 @@ func (g *GB28181API) Play(in *PlayInput) error {
|
||||
return err
|
||||
}
|
||||
|
||||
g.svr.gb.core.EditPlaying(in.Channel.DeviceID, in.Channel.ChannelID, true)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user