Browse Source

more detailed error messages

pull/31/head v0.6.2
aler9 5 years ago
parent
commit
ed715723f2
  1. 40
      server-client.go

40
server-client.go

@ -38,6 +38,29 @@ const (
_CLIENT_STATE_RECORD _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 { type serverClient struct {
p *program p *program
conn *gortsplib.ConnServer conn *gortsplib.ConnServer
@ -263,7 +286,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
case gortsplib.DESCRIBE: case gortsplib.DESCRIBE:
if c.state != _CLIENT_STATE_STARTING { 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 return false
} }
@ -304,7 +328,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
case gortsplib.ANNOUNCE: case gortsplib.ANNOUNCE:
if c.state != _CLIENT_STATE_STARTING { 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 return false
} }
@ -669,13 +694,14 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
} }
default: 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 return false
} }
case gortsplib.PLAY: case gortsplib.PLAY:
if c.state != _CLIENT_STATE_PRE_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 return false
} }
@ -752,7 +778,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
case gortsplib.PAUSE: case gortsplib.PAUSE:
if c.state != _CLIENT_STATE_PLAY { 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 return false
} }
@ -778,7 +805,8 @@ func (c *serverClient) handleRequest(req *gortsplib.Request) bool {
case gortsplib.RECORD: case gortsplib.RECORD:
if c.state != _CLIENT_STATE_PRE_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 return false
} }

Loading…
Cancel
Save