Skip to content

Commit

Permalink
Code refactoring after #967
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 29, 2024
1 parent d967014 commit e304035
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions pkg/isapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package isapi

import (
"errors"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/tcp"
"io"
"net"
"net/http"
"net/url"

"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/tcp"
)

type Client struct {
Expand Down Expand Up @@ -84,15 +85,13 @@ func (c *Client) Dial() (err error) {
}

func (c *Client) Open() (err error) {
// 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
}
// 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.
if err = c.Close(); err != nil {
return err
}

link := c.url + "/ISAPI/System/TwoWayAudio/channels/" + c.channel
req, err := http.NewRequest("PUT", link+"/open", nil)
Expand Down
6 changes: 3 additions & 3 deletions pkg/tcp/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http"
"strings"
"time"

"github.com/AlexxIT/go2rtc/pkg/core"
)

// Do - http.Client with support Digest Authorization
Expand Down Expand Up @@ -115,9 +117,7 @@ func Do(req *http.Request) (*http.Response, error) {
)
case "auth":
nc := "00000001"
// TODO: Random cnonce
// Here is temp static cnonce of required 32 bytes
cnonce := "ZDlmODczZTk2NjQyZTQ4OGQ5ZGEzOTI3YTc5Y2Q0ZGM="
cnonce := core.RandString(32, 64)
response := HexMD5(ha1, nonce, nc, cnonce, qop, ha2)
header = fmt.Sprintf(
`Digest username="%s", realm="%s", nonce="%s", uri="%s", qop=%s, nc=%s, cnonce="%s", response="%s"`,
Expand Down

0 comments on commit e304035

Please sign in to comment.