Skip to content

Commit

Permalink
allow calling PLAY twice (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Nov 24, 2020
1 parent 359a7f0 commit 7365dc0
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,31 +770,35 @@ func (c *Client) handleRequest(req *base.Request) error {
}

case base.PLAY:
// play can be sent twice, allow calling it even if we're already playing
err := c.checkState(map[state]struct{}{
statePrePlay: {},
statePlay: {},
})
if err != nil {
c.writeResError(cseq, base.StatusBadRequest, err)
return errStateTerminate
}

basePath, ok := req.URL.BasePath()
if !ok {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL))
return errStateTerminate
}
if c.state == statePrePlay {
basePath, ok := req.URL.BasePath()
if !ok {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL))
return errStateTerminate
}

// path can end with a slash, remove it
basePath = strings.TrimSuffix(basePath, "/")
// path can end with a slash, remove it
basePath = strings.TrimSuffix(basePath, "/")

if basePath != c.path.Name() {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("path has changed, was '%s', now is '%s'", c.path.Name(), basePath))
return errStateTerminate
}
if basePath != c.path.Name() {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("path has changed, was '%s', now is '%s'", c.path.Name(), basePath))
return errStateTerminate
}

if len(c.streamTracks) == 0 {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("no tracks have been setup"))
return errStateTerminate
if len(c.streamTracks) == 0 {
c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("no tracks have been setup"))
return errStateTerminate
}
}

// write response before setting state
Expand All @@ -807,7 +811,11 @@ func (c *Client) handleRequest(req *base.Request) error {
"Session": base.HeaderValue{sessionId},
},
})
return errStatePlay

if c.state == c.statePrePlay {
return errStatePlay
}
return nil

case base.RECORD:
err := c.checkState(map[state]struct{}{
Expand Down

0 comments on commit 7365dc0

Please # to comment.