diff --git a/client.go b/client.go index f3ab785e..07743a21 100644 --- a/client.go +++ b/client.go @@ -529,19 +529,22 @@ func (c *Client) runInner() error { } func (c *Client) doClose() { + if c.state != clientStatePlay && c.state != clientStateRecord && c.conn != nil { + c.connCloserStop() + } + if c.state == clientStatePlay || c.state == clientStateRecord { c.playRecordStop(true) + } + if c.baseURL != nil { c.do(&base.Request{ Method: base.Teardown, URL: c.baseURL, }, true, false) + } - c.nconn.Close() - c.nconn = nil - c.conn = nil - } else if c.nconn != nil { - c.connCloserStop() + if c.nconn != nil { c.nconn.Close() c.nconn = nil c.conn = nil @@ -1259,6 +1262,7 @@ func (c *Client) doSetup( // switch transport automatically if c.effectiveTransport == nil && c.Transport == nil { + c.baseURL = baseURL return c.trySwitchingProtocol2(medi, baseURL) } diff --git a/client_play_test.go b/client_play_test.go index 3800e9cb..0ca83cdd 100644 --- a/client_play_test.go +++ b/client_play_test.go @@ -1128,6 +1128,15 @@ func TestClientPlayAutomaticProtocol(t *testing.T) { }) require.NoError(t, err) + req, err = co.ReadRequest() + require.NoError(t, err) + require.Equal(t, base.Teardown, req.Method) + + err = co.WriteResponse(&base.Response{ + StatusCode: base.StatusOK, + }) + require.NoError(t, err) + _, err = co.ReadRequest() require.Error(t, err) }() diff --git a/client_test.go b/client_test.go index 6da894a2..68ae72a3 100644 --- a/client_test.go +++ b/client_test.go @@ -103,7 +103,6 @@ func TestClientSession(t *testing.T) { req, err = conn.ReadRequest() require.NoError(t, err) require.Equal(t, base.Describe, req.Method) - require.Equal(t, base.HeaderValue{"123456"}, req.Header["Session"]) medias := media.Medias{testH264Media}