Initial upload
This commit is contained in:
commit
cefd7abe8a
19 changed files with 1027 additions and 0 deletions
87
app/controller.go
Normal file
87
app/controller.go
Normal file
|
@ -0,0 +1,87 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
Model *Model
|
||||
View *View
|
||||
}
|
||||
|
||||
func (c *Controller) LogAndShowError(err error) {
|
||||
log.Printf("[ERR ] app: %s", err.Error())
|
||||
c.View.PopupError(err)
|
||||
}
|
||||
|
||||
func (c *Controller) DiscoverDevices() {
|
||||
go func() {
|
||||
devices, err := c.Model.DiscoverDevices()
|
||||
if err != nil {
|
||||
c.LogAndShowError(fmt.Errorf("error discovering devices %v", err))
|
||||
return
|
||||
}
|
||||
if len(devices) == 0 {
|
||||
c.LogAndShowError(errors.New("no devices found"))
|
||||
return
|
||||
}
|
||||
c.View.MainScreen(devices)
|
||||
}()
|
||||
c.View.LoadingScreen()
|
||||
}
|
||||
|
||||
func (c *Controller) StartCasting(selected string, mediaURL string) {
|
||||
|
||||
if selected == "" {
|
||||
c.LogAndShowError(errors.New("no device selected"))
|
||||
return
|
||||
}
|
||||
|
||||
err := c.Model.ConnectToDevice(selected)
|
||||
if err != nil {
|
||||
c.LogAndShowError(fmt.Errorf("error connecting to device %v", err))
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
err = c.Model.StartCast(mediaURL)
|
||||
if err != nil {
|
||||
c.LogAndShowError(fmt.Errorf("error starting cast %v", err))
|
||||
c.DiscoverDevices()
|
||||
return
|
||||
}
|
||||
}()
|
||||
c.View.CastingScreen(selected)
|
||||
|
||||
}
|
||||
|
||||
// Note: these are app codes, they are NOT related to fcast opcodes!
|
||||
const (
|
||||
ActionPlay = 0
|
||||
ActionPause = 1
|
||||
ActionSkipBack = 2
|
||||
ActionSkipForward = 3
|
||||
ActionStop = 4
|
||||
ActionVolumeUp = 5
|
||||
ActionVolumeDown = 6
|
||||
ArgsActionSeek = 7 // seekTime
|
||||
|
||||
RespPlaybackUpdate = 0 // videoRuntime, currentTime
|
||||
)
|
||||
|
||||
func (c *Controller) PlayerAction(action int, args ...float32) {
|
||||
err := c.Model.PlayerAction(action, args...)
|
||||
if err != nil {
|
||||
c.LogAndShowError(fmt.Errorf("error performing action %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) ExitCasting() {
|
||||
c.PlayerAction(ActionStop)
|
||||
c.DiscoverDevices()
|
||||
}
|
||||
|
||||
func (c *Controller) ReceiverResponse(action int, args ...float32) {
|
||||
c.View.UpdateCastingScreen(action, args...)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue