10 StartTimeFormat
= "2006-01-02T15:04"
11 StartTimeFormatSecs
= "2006-01-02T15:04:05"
12 LocalTimeFormat
= "Mon _2 Jan 2006 15:04:05"
16 AuthenticateType
= "authenticate"
22 PlaylistsType
= "playlists"
29 StatusChannelInUse
= "channel_in_use"
30 StatusPlaying
= "playing"
33 // Base message type to determine what type of payload is expected.
38 // Initial message from Radio to authenticate itself with a token string.
39 type AuthenticateMessage
struct {
44 // Server updates the radio with the list of files that currently exist.
45 // This will be provided on connect and when there are any changes.
46 // The radio is expected to obtain all these files and cache them locally.
47 type FilesMessage
struct {
52 type PlaylistsMessage
struct {
54 Playlists
[]PlaylistSpec
57 // Any playlist currently being played should be stopped and PTT disengaged.
58 type StopMessage
struct {
62 type StatusMessage
struct {
65 // Status w.r.t. playing a playlist
68 // File being played or about to be played - empty string in idle status
71 // Name of playlist being played - empty string in idle status
74 // Seconds until playback begins - never mind latency
75 DelaySecondsRemaining
int
77 // Number of seconds file has been actually playing
78 PlaybackSecondsElapsed
int
80 // Number of seconds waiting for channel to clear
81 WaitingForChannelSeconds
int
87 // Timestamp of the current time on this radio, using LocalTimeFormat
90 // Time zone in use, e.g. "Australia/Hobart"
94 // Description of an individual file available in the broadcasting system.
95 type FileSpec
struct {
96 // Filename, e.g. "broadcast.wav"
98 // SHA-256 hash of the file's contents
102 type PlaylistSpec
struct {
109 type EntrySpec
struct {
115 func ParseMessage(data
[]byte) (string, interface{}, error
) {
117 err
:= json
.Unmarshal(data
, &t
)
122 if t
.T
== AuthenticateType
{
123 var auth AuthenticateMessage
124 err
= json
.Unmarshal(data
, &auth
)
128 return t
.T
, auth
, nil
131 if t
.T
== FilesType
{
132 var files FilesMessage
133 err
= json
.Unmarshal(data
, &files
)
137 return t
.T
, files
, nil
140 if t
.T
== PlaylistsType
{
141 var playlists PlaylistsMessage
142 err
= json
.Unmarshal(data
, &playlists
)
146 return t
.T
, playlists
, nil
149 if t
.T
== StatusType
{
150 var status StatusMessage
151 err
= json
.Unmarshal(data
, &status
)
155 return t
.T
, status
, nil
160 err
= json
.Unmarshal(data
, &stop
)
164 return t
.T
, stop
, nil
167 return "", nil, errors
.New(fmt
.Sprintf("unknown message type %v", t
.T
))