Skip to content

Commit

Permalink
more detailed error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed May 21, 2020
1 parent f60e91b commit ed71572
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions server-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ const (
_CLIENT_STATE_RECORD
)

func (cs clientState) String() string {
switch cs {
case _CLIENT_STATE_STARTING:
return "STARTING"

case _CLIENT_STATE_ANNOUNCE:
return "ANNOUNCE"

case _CLIENT_STATE_PRE_PLAY:
return "PRE_PLAY"

case _CLIENT_STATE_PLAY:
return "PLAY"

case _CLIENT_STATE_PRE_RECORD:
return "PRE_RECORD"

case _CLIENT_STATE_RECORD:
return "RECORD"
}
return "UNKNOWN"
}

type serverClient struct {
p *program
conn *gortsplib.ConnServer
Expand Down Expand Up @@ -263,7 +286,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {

case gortsplib.DESCRIBE:
if c.state != _CLIENT_STATE_STARTING {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("client is in state '%d'", c.state))
c.writeResError(req, gortsplib.StatusBadRequest,
fmt.Errorf("client is in state '%s' instead of '%s'", c.state, _CLIENT_STATE_STARTING))
return false
}

Expand Down Expand Up @@ -304,7 +328,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {

case gortsplib.ANNOUNCE:
if c.state != _CLIENT_STATE_STARTING {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("client is in state '%d'", c.state))
c.writeResError(req, gortsplib.StatusBadRequest,
fmt.Errorf("client is in state '%s' instead of '%s'", c.state, _CLIENT_STATE_STARTING))
return false
}

Expand Down Expand Up @@ -669,13 +694,14 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
}

default:
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("client is in state '%d'", c.state))
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("client is in state '%s'", c.state))
return false
}

case gortsplib.PLAY:
if c.state != _CLIENT_STATE_PRE_PLAY {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("client is in state '%d'", c.state))
c.writeResError(req, gortsplib.StatusBadRequest,
fmt.Errorf("client is in state '%s' instead of '%s'", c.state, _CLIENT_STATE_PRE_PLAY))
return false
}

Expand Down Expand Up @@ -752,7 +778,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {

case gortsplib.PAUSE:
if c.state != _CLIENT_STATE_PLAY {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("client is in state '%d'", c.state))
c.writeResError(req, gortsplib.StatusBadRequest,
fmt.Errorf("client is in state '%s' instead of '%s'", c.state, _CLIENT_STATE_PLAY))
return false
}

Expand All @@ -778,7 +805,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {

case gortsplib.RECORD:
if c.state != _CLIENT_STATE_PRE_RECORD {
c.writeResError(req, gortsplib.StatusBadRequest, fmt.Errorf("client is in state '%d'", c.state))
c.writeResError(req, gortsplib.StatusBadRequest,
fmt.Errorf("client is in state '%s' instead of '%s'", c.state, _CLIENT_STATE_PRE_RECORD))
return false
}

Expand Down

0 comments on commit ed71572

Please sign in to comment.