mirror of
https://github.com/gowvp/gb28181.git
synced 2026-04-22 23:17:19 +08:00
删除设备的同时清理通道
This commit is contained in:
+2
-2
@@ -2,7 +2,6 @@ package gbs
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
|
||||
@@ -70,9 +69,10 @@ func (g GB28181API) sipMessageCatalog(ctx *sip.Context) {
|
||||
// QueryCatalog 设备目录查询或订阅请求
|
||||
// GB/T28181 81 页 A.2.4.3
|
||||
func (g *GB28181API) QueryCatalog(deviceID string) error {
|
||||
slog.Debug("QueryCatalog", "deviceID", deviceID)
|
||||
ipc, ok := g.svr.memoryStorer.Load(deviceID)
|
||||
if !ok {
|
||||
return fmt.Errorf("device not found")
|
||||
return ErrDeviceOffline
|
||||
}
|
||||
|
||||
_, err := g.svr.wrapRequest(ipc, sip.MethodMessage, &sip.ContentTypeXML, sip.GetCatalogXML(deviceID))
|
||||
|
||||
+11
-6
@@ -21,13 +21,14 @@ var (
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
channels conc.Map[string, *Channel]
|
||||
Channels conc.Map[string, *Channel]
|
||||
|
||||
registerWithKeepaliveMutex sync.Mutex
|
||||
// 播放互斥锁也可以移动到 channel 属性
|
||||
playMutex sync.Mutex
|
||||
|
||||
IsOnline bool
|
||||
Address string
|
||||
|
||||
conn sip.Connection
|
||||
source net.Addr
|
||||
@@ -38,7 +39,7 @@ type Device struct {
|
||||
Expires int
|
||||
}
|
||||
|
||||
func NewDevice(conn sip.Connection, d *gb28181.Device, channels []*gb28181.Channel) *Device {
|
||||
func NewDevice(conn sip.Connection, d *gb28181.Device) *Device {
|
||||
uri, err := sip.ParseURI(fmt.Sprintf("sip:%s@%s", d.DeviceID, d.Address))
|
||||
if err != nil {
|
||||
slog.Error("parse uri", "err", err, "did", d.ID)
|
||||
@@ -58,20 +59,24 @@ func NewDevice(conn sip.Connection, d *gb28181.Device, channels []*gb28181.Chann
|
||||
URI: uri,
|
||||
Params: sip.NewParams(),
|
||||
},
|
||||
Address: d.Address,
|
||||
LastKeepaliveAt: d.KeepaliveAt.Time,
|
||||
LastRegisterAt: d.RegisteredAt.Time,
|
||||
IsOnline: d.IsOnline,
|
||||
}
|
||||
|
||||
return &c
|
||||
}
|
||||
|
||||
func (d *Device) LoadChannels(channels ...*gb28181.Channel) {
|
||||
for _, channel := range channels {
|
||||
ch := Channel{
|
||||
ChannelID: channel.ChannelID,
|
||||
device: &c,
|
||||
device: d,
|
||||
}
|
||||
ch.init(d.Address)
|
||||
c.channels.Store(channel.ChannelID, &ch)
|
||||
d.Channels.Store(channel.ChannelID, &ch)
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
// Conn implements Targeter.
|
||||
@@ -164,7 +169,7 @@ func newDevice(network, address string, conn sip.Connection) *Device {
|
||||
// }
|
||||
|
||||
func (c *Device) GetChannel(channelID string) (*Channel, bool) {
|
||||
return c.channels.Load(channelID)
|
||||
return c.Channels.Load(channelID)
|
||||
}
|
||||
|
||||
// func (c *Client) Delete(deviceID string) {
|
||||
|
||||
Reference in New Issue
Block a user