Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# you may remove this if you don't use vgo
#- go mod download
# you may remove this if you don't need go generate
#- go generate ./...
version: 2
builds:
- env:
- CGO_ENABLED=0
Expand Down Expand Up @@ -35,10 +30,10 @@ builds:
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
archives:
- id: build
format: tar.gz
formats: tar.gz
format_overrides:
- goos: windows
format: zip
formats: zip
checksum:
name_template: 'checksums.txt'
changelog:
Expand Down
2 changes: 2 additions & 0 deletions .mockery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all: True
dir: "{{.InterfaceDir}}/mocks"
39 changes: 12 additions & 27 deletions application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -18,13 +19,14 @@ import (

"github.com/h2non/filetype"

"path/filepath"

"github.com/buger/jsonparser"
"github.com/pkg/errors"
"github.com/vishen/go-chromecast/cast"
pb "github.com/vishen/go-chromecast/cast/proto"
"github.com/vishen/go-chromecast/playlists"
"github.com/vishen/go-chromecast/storage"
"path/filepath"
)

var (
Expand Down Expand Up @@ -388,7 +390,7 @@ func (a *Application) Update() error {
// Simple retry. We need this for when the device isn't currently
// available, but it is likely that it will come up soon. If the device
// has switch network addresses the caller is expected to handle that situation.
for i := 0; i < a.connectionRetries; i++ {
for i := range a.connectionRetries {
recvStatus, err = a.getReceiverStatus()
if err == nil {
break
Expand Down Expand Up @@ -496,13 +498,9 @@ func (a *Application) TogglePause() error {
}
switch a.media.PlayerState {
case "PLAYING", "BUFFERING":
{
return a.Pause()
}
return a.Pause()
default:
{
return a.Unpause()
}
return a.Unpause()
}
}

Expand Down Expand Up @@ -604,11 +602,9 @@ func (a *Application) Seek(value int) error {
"CC1AD845", // Default media
}

for _, app := range appsSeekTo {
if app == a.application.AppId {
absolute := a.media.CurrentTime + float32(value)
return a.SeekToTime(absolute)
}
if slices.Contains(appsSeekTo, a.application.AppId) {
absolute := a.media.CurrentTime + float32(value)
return a.SeekToTime(absolute)
}

return a.sendMediaRecv(&cast.MediaHeader{
Expand Down Expand Up @@ -1197,7 +1193,7 @@ func (a *Application) startStreamingServer() error {
if !liveStreaming {
http.ServeFile(w, r, filename)
} else {
a.serveLiveStreaming(w, r, filename)
a.serveLiveStreaming(w, filename)
}
} else {
http.Error(w, "Invalid file", 400)
Expand All @@ -1221,7 +1217,7 @@ func (a *Application) startStreamingServer() error {
return nil
}

func (a *Application) serveLiveStreaming(w http.ResponseWriter, r *http.Request, filename string) {
func (a *Application) serveLiveStreaming(w http.ResponseWriter, filename string) {
cmd := exec.Command(
"ffmpeg",
"-re", // encode at 1x playback speed, to not burn the CPU
Expand Down Expand Up @@ -1250,7 +1246,7 @@ func (a *Application) serveLiveStreaming(w http.ResponseWriter, r *http.Request,
}
}

func (a *Application) log(message string, args ...interface{}) {
func (a *Application) log(message string, args ...any) {
if a.debug {
log.WithField("package", "application").Infof(message, args...)
}
Expand Down Expand Up @@ -1318,21 +1314,10 @@ func (a *Application) sendMediaRecv(payload cast.Payload) error {
return err
}

func (a *Application) sendAndWaitDefaultConn(payload cast.Payload) (*pb.CastMessage, error) {
return a.sendAndWait(payload, defaultSender, defaultRecv, namespaceConn)
}

func (a *Application) sendAndWaitDefaultRecv(payload cast.Payload) (*pb.CastMessage, error) {
return a.sendAndWait(payload, defaultSender, defaultRecv, namespaceRecv)
}

func (a *Application) sendAndWaitMediaConn(payload cast.Payload) (*pb.CastMessage, error) {
if a.application == nil {
return nil, ErrApplicationNotSet
}
return a.sendAndWait(payload, defaultSender, a.application.TransportId, namespaceConn)
}

func (a *Application) sendAndWaitMediaRecv(payload cast.Payload) (*pb.CastMessage, error) {
if a.application == nil {
return nil, ErrApplicationNotSet
Expand Down
3 changes: 1 addition & 2 deletions application/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"github.com/vishen/go-chromecast/cast"
)

// getInfo uses the http://<ip>:8008/setup/eureka_endpoint to obtain more
// GetInfo uses the http://<ip>:8008/setup/eureka_endpoint to obtain more
// information about the cast-device.
// OBS: The 8008 seems to be pure http, whereas 8009 is typically the port
// to use for protobuf-communication,

func GetInfo(ip string) (info *cast.DeviceInfo, err error) {
// Note: Services exposed not on 8009 port are "Google Cast Group"s
// The only way to find the true device (group) name, is using mDNS outside of this function.
Expand Down
26 changes: 13 additions & 13 deletions application/mocks/App.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion application/mocks/ApplicationOption.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion application/mocks/CastMessageFunc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions cast/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Connection) RemotePort() (port string, err error) {
return port, err
}

func (c *Connection) log(message string, args ...interface{}) {
func (c *Connection) log(message string, args ...any) {
if c.debug {
log.WithField("package", "cast").Debugf(message, args...)
}
Expand Down Expand Up @@ -212,12 +212,11 @@ func (c *Connection) receiveLoop(ctx context.Context) {
continue
}

c.handleMessage(requestIDi, message, &headers)
c.handleMessage(requestIDi, message)
}
}

func (c *Connection) handleMessage(requestID int, message *pb.CastMessage, headers *PayloadHeader) {

func (c *Connection) handleMessage(requestID int, message *pb.CastMessage) {
messageType, err := jsonparser.GetString([]byte(*message.PayloadUtf8), "type")
if err != nil {
c.log("could not find 'type' key in response message request_id=%d %q: %s", requestID, *message.PayloadUtf8, err)
Expand Down
12 changes: 6 additions & 6 deletions cast/mocks/Conn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cast/mocks/Payload.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions cast/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ type LaunchRequest struct {

type LoadMediaCommand struct {
PayloadHeader
Media MediaItem `json:"media"`
CurrentTime int `json:"currentTime"`
Autoplay bool `json:"autoplay"`
QueueData QueueData `json:"queueData"`
CustomData interface{} `json:"customData"`
Media MediaItem `json:"media"`
CurrentTime int `json:"currentTime"`
Autoplay bool `json:"autoplay"`
QueueData QueueData `json:"queueData"`
CustomData any `json:"customData"`
}

type QueueData struct {
Expand Down
Loading
Loading