Merge pull request #967 from f1d094/master
Modify ISAPI to reliably open connections
This commit is contained in:
+12
-3
@@ -84,8 +84,17 @@ func (c *Client) Dial() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Open() (err error) {
|
func (c *Client) Open() (err error) {
|
||||||
link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel
|
// Hikvision ISAPI may not accept a new open request if the previous one was not closed (e.g.
|
||||||
|
// using the test button on-camera or via curl command) but a close request can be sent even if
|
||||||
|
// the audio is already closed. So, we send a close request first and then open it again. Seems
|
||||||
|
// janky but it works.
|
||||||
|
|
||||||
|
err = c.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel
|
||||||
req, err := http.NewRequest("PUT", link+"/open", nil)
|
req, err := http.NewRequest("PUT", link+"/open", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -124,8 +133,8 @@ func (c *Client) Open() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Close() (err error) {
|
func (c *Client) Close() (err error) {
|
||||||
link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel + "/close"
|
link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel
|
||||||
req, err := http.NewRequest("PUT", link+"/open", nil)
|
req, err := http.NewRequest("PUT", link+"/close", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -115,7 +115,9 @@ func Do(req *http.Request) (*http.Response, error) {
|
|||||||
)
|
)
|
||||||
case "auth":
|
case "auth":
|
||||||
nc := "00000001"
|
nc := "00000001"
|
||||||
cnonce := "00000001" // TODO: random...
|
// TODO: Random cnonce
|
||||||
|
// Here is temp static cnonce of required 32 bytes
|
||||||
|
cnonce := "ZDlmODczZTk2NjQyZTQ4OGQ5ZGEzOTI3YTc5Y2Q0ZGM="
|
||||||
response := HexMD5(ha1, nonce, nc, cnonce, qop, ha2)
|
response := HexMD5(ha1, nonce, nc, cnonce, qop, ha2)
|
||||||
header = fmt.Sprintf(
|
header = fmt.Sprintf(
|
||||||
`Digest username="%s", realm="%s", nonce="%s", uri="%s", qop=%s, nc=%s, cnonce="%s", response="%s"`,
|
`Digest username="%s", realm="%s", nonce="%s", uri="%s", qop=%s, nc=%s, cnonce="%s", response="%s"`,
|
||||||
|
|||||||
Reference in New Issue
Block a user