@@ -241,18 +241,33 @@ let historyEndPoint userID =
241241 })
242242 }
243243
244- let startupEndpoint =
244+ let startupEndpoint userID =
245245 pipeline {
246246 set_ header " Content-Type" " application/json"
247247 plug ( fun next ctx -> task {
248- let! sas = getSASMediaLink " d97cdddb-8a19-4690-8ba5-b8ea43d3641f"
249- let action = TagActionForBox.PlayMusik sas
248+ match ! AzureTable.getUser userID with
249+ | None ->
250+ return ! Response.notFound ctx userID
251+ | Some user ->
252+ let! sas = getSASMediaLink " d97cdddb-8a19-4690-8ba5-b8ea43d3641f"
250253
251- let txt =
252- action
253- |> TagActionForBox.Encoder
254- |> Encode.toString 0
255- return ! setBodyFromString txt next ctx
254+ match user.SpeakerType with
255+ | SpeakerType.Local ->
256+ let txt =
257+ TagActionForBox.PlayMusik sas
258+ |> TagActionForBox.Encoder
259+ |> Encode.toString 0
260+ return ! setBodyFromString txt next ctx
261+ | SpeakerType.Sonos ->
262+ let logger = ctx.GetLogger " Startup"
263+ let! session = Sonos.createOrJoinSession logger user.SonosAccessToken Sonos.group
264+ do ! Sonos.playURL logger user.SonosAccessToken session " StartupSound" sas " StartupSound"
265+
266+ let txt =
267+ TagActionForBox.Ignore
268+ |> TagActionForBox.Encoder
269+ |> Encode.toString 0
270+ return ! setBodyFromString txt next ctx
256271 })
257272 }
258273
@@ -293,7 +308,7 @@ let webApp =
293308 getf " /api/volumedown/%s " volumeDownEndpoint
294309 postf " /api/upload/%s " uploadEndpoint
295310 getf " /api/history/%s " historyEndPoint
296- get " /api/startup" startupEndpoint
311+ getf " /api/startup/ %s " startupEndpoint
297312 get " /api/firmware" firmwareEndpoint
298313 get " /api/latestfirmware" getLatestFirmware
299314 getf " /api/taghistorysocket/%s " ( TagHistorySocket.openSocket tagHistoryBroadcaster)
0 commit comments