Improve casting resume behavior
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 15m49s
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 15m49s
This commit is contained in:
parent
150348c391
commit
4cf9a2a58f
3 changed files with 57 additions and 11 deletions
32
app/model.go
32
app/model.go
|
@ -7,6 +7,8 @@ import (
|
|||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
|
@ -14,9 +16,11 @@ type Model struct {
|
|||
DiscoveredDevices []fcast.DiscoveredHost
|
||||
Connection *fcast.Connection
|
||||
EventManager *fcast.EventManager
|
||||
DeviceName string
|
||||
Time float32
|
||||
Length float32
|
||||
Volume float32
|
||||
IsReconnecting bool
|
||||
}
|
||||
|
||||
func (m *Model) DiscoverDevices() ([]string, error) {
|
||||
|
@ -47,10 +51,29 @@ func (m *Model) ConnectToDevice(name string) error {
|
|||
return err
|
||||
}
|
||||
m.Connection = connection
|
||||
m.DeviceName = name
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Model) StartCast(mediaURL string) error {
|
||||
func (m *Model) Cast(selectedDevice, mediaURL string) error {
|
||||
err := m.doCast(selectedDevice, mediaURL)
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) || strings.Contains(err.Error(), "software caused connection abort") {
|
||||
m.Controller.ShowReconnecting(true)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
return m.Cast(selectedDevice, mediaURL)
|
||||
}
|
||||
}
|
||||
m.Controller.ShowReconnecting(false)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Model) doCast(selectedDevice, mediaURL string) error {
|
||||
|
||||
err := m.ConnectToDevice(selectedDevice)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to device %v", err)
|
||||
}
|
||||
|
||||
m.EventManager = &fcast.EventManager{}
|
||||
|
||||
|
@ -81,6 +104,13 @@ func (m *Model) StartCast(mediaURL string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
m.Volume = 1
|
||||
}
|
||||
|
||||
err = m.Connection.SendMessage(&fcast.PingMessage{})
|
||||
if err == nil {
|
||||
m.Controller.ShowReconnecting(false)
|
||||
}
|
||||
|
||||
return m.Connection.ListenForMessages(m.EventManager)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue