Support channels for DVRIP

This commit is contained in:
Alexey Khit
2023-02-11 12:45:46 +03:00
parent 3f338c83b7
commit b2029d1004
+18 -5
View File
@@ -66,11 +66,25 @@ func (c *Client) Dial() (err error) {
c.reader = bufio.NewReader(c.conn)
c.stream = u.Path
if c.stream == "" {
c.stream = "Main"
query := u.Query()
channel := query.Get("channel")
if channel == "" {
channel = "0"
}
subtype := query.Get("subtype")
switch subtype {
case "", "0":
subtype = "Main"
case "1":
subtype = "Extra1"
}
c.stream = fmt.Sprintf(
`{"Channel":%s,"CombinMode":"NONE","StreamType":"%s","TransMode":"TCP"}`,
channel, subtype,
)
if u.User != nil {
pass, _ := u.User.Password()
return c.Login(u.User.Username(), pass)
@@ -94,8 +108,7 @@ func (c *Client) Login(user, pass string) (err error) {
}
func (c *Client) Play() (err error) {
format := `{"Name":"OPMonitor","SessionID":"0x%08X","OPMonitor":{"Action":"%s","Parameter":` +
`{"Channel":0,"CombinMode":"NONE","StreamType":"%s","TransMode":"TCP"}}}`
format := `{"Name":"OPMonitor","SessionID":"0x%08X","OPMonitor":{"Action":"%s","Parameter":%s}}`
data := fmt.Sprintf(format, c.session, "Claim", c.stream)
if err = c.Request(OPMonitorClaim, data); err != nil {