Skip to content

Commit

Permalink
Merge 667d8ee into 54c73fa
Browse files Browse the repository at this point in the history
  • Loading branch information
gongo committed Oct 25, 2016
2 parents 54c73fa + 667d8ee commit a3a2ac1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
14 changes: 9 additions & 5 deletions .travis.yml
@@ -1,16 +1,20 @@
language: go

sudo: false

go:
- 1.4
- 1.5
- 1.7

branches:
only:
- master

install:
- go get github.com/miekg/dns
- go get github.com/gongo/text-parameters
- go get github.com/DHowett/go-plist
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi

script:
- $HOME/gopath/bin/goveralls -service=travis-ci
- go test -covermode=count -coverprofile=profile.cov
- $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=travis-ci
10 changes: 10 additions & 0 deletions client.go
Expand Up @@ -21,6 +21,9 @@ type PlaybackInfo struct {
// IsReadyToPlay, if true, content is currently playing or ready to play.
IsReadyToPlay bool `plist:"readyToPlay"`

// ReadyToPlayValue represents the information on whether content is currently playing, ready to play or not.
ReadyToPlayValue interface{} `plist:"readyToPlay"`

// Duration represents playback duration in seconds.
Duration float64 `plist:"duration"`

Expand Down Expand Up @@ -212,6 +215,13 @@ func (c *Client) GetPlaybackInfo() (*PlaybackInfo, error) {
return nil, err
}

switch t := info.ReadyToPlayValue.(type) {
case uint64: // AppleTV 4G
info.IsReadyToPlay = (t == 1)
case bool: // AppleTV 2G, 3G
info.IsReadyToPlay = t
}

return info, nil
}

Expand Down
36 changes: 36 additions & 0 deletions client_test.go
Expand Up @@ -50,6 +50,15 @@ var (
<key>readyToPlay</key>
<true/>
</dict>
</plist>`

playingPlaybackInfoAt4G = `
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>readyToPlay</key>
<integer>1</integer>
</dict>
</plist>`
)

Expand Down Expand Up @@ -290,6 +299,33 @@ func TestGetPlaybackInfo(t *testing.T) {
}
}

func TestGetPlaybackInfoWithVariousVersion(t *testing.T) {
expectRequests := []testExpectRequest{
{"GET", "/playback-info"},
{"GET", "/playback-info"},
}
responseXMLs := []string{playingPlaybackInfo, playingPlaybackInfoAt4G}

ts := airTestServer(t, expectRequests, func(t *testing.T, w http.ResponseWriter, req *http.Request) {
xml := responseXMLs[0]
responseXMLs = responseXMLs[1:]
w.Write([]byte(xml))
})

client := getTestClient(t, ts)

for range responseXMLs {
info, err := client.GetPlaybackInfo()
if err != nil {
t.Fatal(err)
}

if !info.IsReadyToPlay {
t.Fatal("PlaybackInfo is not ready to play status")
}
}
}

func TestClientToPasswordRequiredDevice(t *testing.T) {
expectRequests := []testExpectRequest{
{"POST", "/play"},
Expand Down

0 comments on commit a3a2ac1

Please sign in to comment.