10 StartTimeFormat
= "2006-01-02T15:04"
11 LocalTimeFormat
= "Mon _2 Jan 2006 15:04:05"
15 AuthenticateType
= "authenticate"
21 PlaylistsType
= "playlists"
27 StatusChannelInUse
= "channel_in_use"
28 StatusPlaying
= "playing"
31 // Base message type to determine what type of payload is expected.
36 // Initial message from Radio to authenticate itself with a token string.
37 type AuthenticateMessage
struct {
42 // Server updates the radio with the list of files that currently exist.
43 // This will be provided on connect and when there are any changes.
44 // The radio is expected to obtain all these files and cache them locally.
45 type FilesMessage
struct {
50 type PlaylistsMessage
struct {
52 Playlists
[]PlaylistSpec
55 type StatusMessage
struct {
58 // Status w.r.t. playing a playlist
61 // File being played or about to be played - empty string in idle status
64 // Name of playlist being played - empty string in idle status
67 // Seconds until playback begins - never mind latency
68 DelaySecondsRemaining
int
70 // Number of seconds file has been actually playing
71 PlaybackSecondsElapsed
int
73 // Number of seconds waiting for channel to clear
74 WaitingForChannelSeconds
int
80 // Timestamp of the current time on this radio, using LocalTimeFormat
83 // Time zone in use, e.g. "Australia/Hobart"
87 // Description of an individual file available in the broadcasting system.
88 type FileSpec
struct {
89 // Filename, e.g. "broadcast.wav"
91 // SHA-256 hash of the file's contents
95 type PlaylistSpec
struct {
102 type EntrySpec
struct {
108 func ParseMessage(data
[]byte) (string, interface{}, error
) {
110 err
:= json
.Unmarshal(data
, &t
)
115 if t
.T
== AuthenticateType
{
116 var auth AuthenticateMessage
117 err
= json
.Unmarshal(data
, &auth
)
121 return t
.T
, auth
, nil
124 if t
.T
== FilesType
{
125 var files FilesMessage
126 err
= json
.Unmarshal(data
, &files
)
130 return t
.T
, files
, nil
133 if t
.T
== PlaylistsType
{
134 var playlists PlaylistsMessage
135 err
= json
.Unmarshal(data
, &playlists
)
139 return t
.T
, playlists
, nil
142 if t
.T
== StatusType
{
143 var status StatusMessage
144 err
= json
.Unmarshal(data
, &status
)
148 return t
.T
, status
, nil
151 return "", nil, errors
.New(fmt
.Sprintf("unknown message type %v", t
.T
))