Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

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 fd035e9 commit 7a75481
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions server-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ const (
_CLIENT_STATE_PLAY
)

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

case _CLIENT_STATE_PRE_PLAY:
return "PRE_PLAY"

case _CLIENT_STATE_PLAY:
return "PLAY"
}
return "UNKNOWN"
}

type serverClient struct {
p *program
conn *gortsplib.ConnServer
Expand Down Expand Up @@ -222,7 +236,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 @@ -435,13 +450,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 @@ -518,7 +534,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 Down

0 comments on commit 7a75481

Please sign in to comment.