diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 57f67e3..2ed6335 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,6 @@ # Release Notes -## 0.16.23 - 2018-12-15 +## 0.16.24 - 2018-12-18 * Update to ASP.NET 2.2 ## 0.15.11 - 2018-11-05 @@ -18,7 +18,7 @@ ## 0.11.21 - 2018-10-23 * Next/Previous buttons -## 0.10.37 - 2018-10-23<> +## 0.10.37 - 2018-10-23 * Use better UI ## 0.9.7 - 2018-10-18 diff --git a/src/Client/ReleaseNotes.fs b/src/Client/ReleaseNotes.fs index b19ff69..4a55d88 100644 --- a/src/Client/ReleaseNotes.fs +++ b/src/Client/ReleaseNotes.fs @@ -1,13 +1,13 @@ module internal ReleaseNotes -let Version = "0.16.23" +let Version = "0.16.24" let IsPrerelease = false let Notes = """ # Release Notes -## 0.16.23 - 2018-12-15 +## 0.16.24 - 2018-12-18 * Update to ASP.NET 2.2 ## 0.15.11 - 2018-11-05 @@ -25,7 +25,7 @@ let Notes = """ ## 0.11.21 - 2018-10-23 * Next/Previous buttons -## 0.10.37 - 2018-10-23<> +## 0.10.37 - 2018-10-23 * Use better UI ## 0.9.7 - 2018-10-18 diff --git a/src/PiServer/PiServer.fs b/src/PiServer/PiServer.fs index 1dc6857..3224462 100644 --- a/src/PiServer/PiServer.fs +++ b/src/PiServer/PiServer.fs @@ -56,10 +56,10 @@ type Msg = | NewRFID of string | CheckFirmware | FirmwareUpToDate of unit -| ExecuteActions of TagAction list +| ExecuteAction of TagActionForBox | RFIDRemoved | DiscoverStartup -| NewTag of Tag +| NewTag of TagForBox | Play of PlayList | NextMediaFile | PreviousMediaFile @@ -116,7 +116,7 @@ let resolveRFID (model:Model,token:string) = task { let url = sprintf @"%s/api/tags/%s/%s" model.TagServer model.UserID token let! result = webClient.DownloadStringTaskAsync(System.Uri url) - match Decode.fromString Tag.Decoder result with + match Decode.fromString TagForBox.Decoder result with | Error msg -> return failwith msg | Ok tag -> return tag } @@ -181,12 +181,12 @@ let checkFirmware (model:Model) = task { log.ErrorFormat("Upgrade error: {0}", exn.Message) } -let getStartupActions (model:Model) = task { +let getStartupAction (model:Model) = task { use webClient = new System.Net.WebClient() let url = sprintf @"%s/api/startup" model.TagServer let! result = webClient.DownloadStringTaskAsync(System.Uri url) - match Decode.fromString (Decode.list TagAction.Decoder) result with + match Decode.fromString (TagActionForBox.Decoder) result with | Error msg -> return failwith msg | Ok actions -> return actions } @@ -209,7 +209,7 @@ let update (msg:Msg) (model:Model) = | NewTag tag -> log.InfoFormat("Got new tag from server: {0}", tag) - model, Cmd.ofMsg (ExecuteActions [tag.Action]) + model, Cmd.ofMsg (ExecuteAction tag.Action) | Play playList -> let model = { model with PlayList = Some playList } @@ -253,7 +253,7 @@ let update (msg:Msg) (model:Model) = model, Cmd.none | DiscoverStartup -> - model, Cmd.ofTask getStartupActions model ExecuteActions Err + model, Cmd.ofTask getStartupAction model ExecuteAction Err | FirmwareUpToDate _ -> log.InfoFormat("Firmware {0} is uptodate.", ReleaseNotes.Version) @@ -264,29 +264,19 @@ let update (msg:Msg) (model:Model) = [fun dispatch -> rfidLoop (dispatch,model.NodeServices) |> Async.AwaitTask |> Async.StartImmediate ] ] - | ExecuteActions actions -> - match actions with - | action::rest -> - match action with - | TagAction.UnknownTag -> - log.Warn "Unknown Tag" - model, Cmd.ofMsg (ExecuteActions rest) - | TagAction.StopMusik -> - model, Cmd.batch [Cmd.ofMsg (FinishPlaylist()); Cmd.ofMsg (ExecuteActions rest) ] - | TagAction.PlayMusik urls -> - let playList : PlayList = { - MediaFiles = urls - Position = 0 - } - model, Cmd.batch [Cmd.ofMsg (Play playList); Cmd.ofMsg (ExecuteActions rest) ] - | TagAction.PlayYoutube _ -> - log.Error "Youtube links need to be converted to direct links by the tag server" - model, Cmd.ofMsg (ExecuteActions rest) - | TagAction.PlayBlobMusik _ -> - log.Error "Blobs links need to be converted to direct links by the tag server" - model, Cmd.ofMsg (ExecuteActions rest) - | _ -> model, Cmd.none - + | ExecuteAction action -> + match action with + | TagActionForBox.UnknownTag -> + log.Warn "Unknown Tag" + model, Cmd.none + | TagActionForBox.StopMusik -> + model, Cmd.ofMsg (FinishPlaylist()) + | TagActionForBox.PlayMusik urls -> + let playList : PlayList = { + MediaFiles = urls + Position = 0 + } + model, Cmd.batch [Cmd.ofMsg (Play playList) ] | Err exn -> log.ErrorFormat("Error: {0}", exn.Message) model, Cmd.none diff --git a/src/Server/Server.fs b/src/Server/Server.fs index 6d9b91f..1bc1724 100644 --- a/src/Server/Server.fs +++ b/src/Server/Server.fs @@ -113,7 +113,7 @@ let uploadEndpoint (token:string) = let file = form.Files.[0] use stream = file.OpenReadStream() let! tagAction = uploadMusik stream - let tag = { Token = System.Guid.NewGuid().ToString(); Action = tagAction; Description = ""; Object = "" } + let tag : Tag = { Token = System.Guid.NewGuid().ToString(); Action = tagAction; Description = ""; Object = "" } let! _saved = AzureTable.saveTag token tag let! tag = mapBlobMusikTag tag let txt = Tag.Encoder tag |> Encode.toString 0 @@ -133,7 +133,13 @@ let tagEndpoint (userID,token) = | _ -> task { return { Token = token; Action = TagAction.UnknownTag; Description = ""; Object = "" } } let! tag = tag |> mapYoutube - let txt = Tag.Encoder tag |> Encode.toString 0 + let tag : TagForBox = { + Token = tag.Token + Object = tag.Object + Description = tag.Description + Action = TagActionForBox.GetFromTagAction tag.Action } + + let txt = TagForBox.Encoder tag |> Encode.toString 0 return! setBodyFromString txt next ctx }) } @@ -153,12 +159,11 @@ let startupEndpoint = set_header "Content-Type" "application/json" plug (fun next ctx -> task { let! sas = getSASMediaLink "d97cdddb-8a19-4690-8ba5-b8ea43d3641f" - let actions = [ TagAction.PlayMusik [| sas |] ] + let action = TagActionForBox.PlayMusik [| sas |] let txt = - actions - |> List.map TagAction.Encoder - |> Encode.list + action + |> TagActionForBox.Encoder |> Encode.toString 0 return! setBodyFromString txt next ctx }) diff --git a/src/Shared/Shared.fs b/src/Shared/Shared.fs index b3807b1..969b3a9 100644 --- a/src/Shared/Shared.fs +++ b/src/Shared/Shared.fs @@ -66,6 +66,43 @@ type TagAction = |> Decode.map TagAction.PlayBlobMusik ] + +[] +type TagActionForBox = +| UnknownTag +| StopMusik +| PlayMusik of string [] + + static member GetFromTagAction(action:TagAction) = + match action with + | TagAction.StopMusik -> TagActionForBox.StopMusik + | TagAction.UnknownTag -> TagActionForBox.UnknownTag + | TagAction.PlayMusik urls -> TagActionForBox.PlayMusik urls + | _ -> failwithf "Can't convert %A" action + + static member Encoder (action : TagActionForBox) = + match action with + | TagActionForBox.UnknownTag -> + Encode.object [ + "UnknownTag", Encode.nil + ] + | TagActionForBox.StopMusik -> + Encode.object [ + "StopMusik", Encode.nil + ] + | TagActionForBox.PlayMusik urls -> + Encode.object [ + "PlayMusik", Encode.array (Array.map Encode.string urls) + ] + + static member Decoder = + Decode.oneOf [ + Decode.field "UnknownTag" (Decode.succeed TagActionForBox.UnknownTag) + Decode.field "StopMusik" (Decode.succeed TagActionForBox.StopMusik) + Decode.field "PlayMusik" (Decode.array Decode.string) + |> Decode.map TagActionForBox.PlayMusik + ] + type Link = { Token : string Url : string @@ -95,6 +132,28 @@ type Tag = ) +type TagForBox = + { Token : string + Object : string + Description : string + Action : TagActionForBox } + + static member Encoder (tag : TagForBox) = + Encode.object [ + "Token", Encode.string tag.Token + "Description", Encode.string tag.Description + "Object", Encode.string tag.Object + "Action", TagActionForBox.Encoder tag.Action + ] + + static member Decoder = + Decode.object (fun get -> + { Token = get.Required.Field "Token" Decode.string + Object = get.Required.Field "Object" Decode.string + Description = get.Required.Field "Description" Decode.string + Action = get.Required.Field "Action" TagActionForBox.Decoder } + ) + type TagList = { Tags : Tag [] }