Feat: auto terminate movie

pull/21/head
zijiren233 2 years ago
parent e92e553941
commit e46965c03e

@ -108,17 +108,36 @@ func (r *Room) UpdateMovie(movieId uint, movie model.BaseMovieInfo) error {
if err != nil { if err != nil {
return err return err
} }
switch {
case ((m.Live && m.Proxy) || (m.Live && m.RtmpSource)) && (!movie.Live && !movie.Proxy && !movie.RtmpSource): err = r.terminateMovie(m)
r.rtmpa.DelChannel(m.PullKey) if err != nil {
m.PullKey = "" return err
case m.Proxy && !movie.Proxy:
m.PullKey = ""
} }
m.MovieInfo.BaseMovieInfo = movie m.MovieInfo.BaseMovieInfo = movie
err = r.initMovie(m)
if err != nil {
return err
}
return SaveMovie(m) return SaveMovie(m)
} }
func (r *Room) terminateMovie(movie *model.Movie) error {
switch {
case movie.Live && movie.RtmpSource:
if movie.PullKey != "" {
r.rtmpa.DelChannel(movie.PullKey)
}
case movie.Live && movie.Proxy:
if movie.PullKey != "" {
r.rtmpa.DelChannel(movie.PullKey)
}
}
return nil
}
func (r *Room) initMovie(movie *model.Movie) error { func (r *Room) initMovie(movie *model.Movie) error {
switch { switch {
case movie.RtmpSource && movie.Proxy: case movie.RtmpSource && movie.Proxy:
@ -206,10 +225,16 @@ func (r *Room) initMovie(movie *model.Movie) error {
if !conf.Conf.Proxy.MovieProxy { if !conf.Conf.Proxy.MovieProxy {
return errors.New("movie proxy is not enabled") return errors.New("movie proxy is not enabled")
} }
u, err := url.Parse(movie.Url)
if err != nil {
return err
}
if u.Scheme != "http" && u.Scheme != "https" {
return errors.New("unsupported scheme")
}
if movie.PullKey == "" { if movie.PullKey == "" {
movie.PullKey = uuid.New().String() movie.PullKey = uuid.New().String()
} }
fallthrough
case !movie.Live && !movie.Proxy, movie.Live && !movie.Proxy && !movie.RtmpSource: case !movie.Live && !movie.Proxy, movie.Live && !movie.Proxy && !movie.RtmpSource:
u, err := url.Parse(movie.Url) u, err := url.Parse(movie.Url)
if err != nil { if err != nil {
@ -218,6 +243,7 @@ func (r *Room) initMovie(movie *model.Movie) error {
if u.Scheme != "http" && u.Scheme != "https" { if u.Scheme != "http" && u.Scheme != "https" {
return errors.New("unsupported scheme") return errors.New("unsupported scheme")
} }
movie.PullKey = ""
default: default:
return errors.New("unknown error") return errors.New("unknown error")
} }

Loading…
Cancel
Save