10 StartTimeFormat
= "2006-01-02T15:04"
11 LocalTimeFormat
= "Mon _2 Jan 2006 15:04:05"
15 AuthenticateType
= "authenticate"
21 PlaylistsType
= "playlists"
28 StatusChannelInUse
= "channel_in_use"
29 StatusPlaying
= "playing"
32 // Base message type to determine what type of payload is expected.
37 // Initial message from Radio to authenticate itself with a token string.
38 type AuthenticateMessage
struct {
43 // Server updates the radio with the list of files that currently exist.
44 // This will be provided on connect and when there are any changes.
45 // The radio is expected to obtain all these files and cache them locally.
46 type FilesMessage
struct {
51 type PlaylistsMessage
struct {
53 Playlists
[]PlaylistSpec
56 // Any playlist currently being played should be stopped and PTT disengaged.
57 type StopMessage
struct {
61 type StatusMessage
struct {
64 // Status w.r.t. playing a playlist
67 // File being played or about to be played - empty string in idle status
70 // Name of playlist being played - empty string in idle status
73 // Seconds until playback begins - never mind latency
74 DelaySecondsRemaining
int
76 // Number of seconds file has been actually playing
77 PlaybackSecondsElapsed
int
79 // Number of seconds waiting for channel to clear
80 WaitingForChannelSeconds
int
86 // Timestamp of the current time on this radio, using LocalTimeFormat
89 // Time zone in use, e.g. "Australia/Hobart"
93 // Description of an individual file available in the broadcasting system.
94 type FileSpec
struct {
95 // Filename, e.g. "broadcast.wav"
97 // SHA-256 hash of the file's contents
101 type PlaylistSpec
struct {
108 type EntrySpec
struct {
114 func ParseMessage(data
[]byte) (string, interface{}, error
) {
116 err
:= json
.Unmarshal(data
, &t
)
121 if t
.T
== AuthenticateType
{
122 var auth AuthenticateMessage
123 err
= json
.Unmarshal(data
, &auth
)
127 return t
.T
, auth
, nil
130 if t
.T
== FilesType
{
131 var files FilesMessage
132 err
= json
.Unmarshal(data
, &files
)
136 return t
.T
, files
, nil
139 if t
.T
== PlaylistsType
{
140 var playlists PlaylistsMessage
141 err
= json
.Unmarshal(data
, &playlists
)
145 return t
.T
, playlists
, nil
148 if t
.T
== StatusType
{
149 var status StatusMessage
150 err
= json
.Unmarshal(data
, &status
)
154 return t
.T
, status
, nil
159 err
= json
.Unmarshal(data
, &stop
)
163 return t
.T
, stop
, nil
166 return "", nil, errors
.New(fmt
.Sprintf("unknown message type %v", t
.T
))