diff --git a/Selector.Web/CSS/now.scss b/Selector.Web/CSS/now.scss new file mode 100644 index 0000000..ff8f550 --- /dev/null +++ b/Selector.Web/CSS/now.scss @@ -0,0 +1,8 @@ + +.card { + background-color: grey; +} + +.now-playing-card { + max-width: 400px; +} \ No newline at end of file diff --git a/Selector.Web/Hubs/NowPlayingHub.cs b/Selector.Web/Hubs/NowPlayingHub.cs index 2d349af..35e85e8 100644 --- a/Selector.Web/Hubs/NowPlayingHub.cs +++ b/Selector.Web/Hubs/NowPlayingHub.cs @@ -2,7 +2,10 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; +using StackExchange.Redis; + using Selector.Cache; +using System.Text.Json; namespace Selector.Web.Hubs { @@ -13,9 +16,18 @@ namespace Selector.Web.Hubs public class NowPlayingHub: Hub { - public Task SendNewPlaying(CurrentlyPlayingDTO context) + private readonly IDatabaseAsync Cache; + + public NowPlayingHub(IDatabaseAsync cache) { - return Clients.All.OnNewPlaying(context); + Cache = cache; + } + + public async Task SendNewPlaying() + { + var nowPlaying = await Cache.StringGetAsync(Key.CurrentlyPlaying(Context.UserIdentifier)); + var deserialised = JsonSerializer.Deserialize(nowPlaying); + await Clients.Caller.OnNewPlaying(deserialised); } } } \ No newline at end of file diff --git a/Selector.Web/Pages/Index.cshtml b/Selector.Web/Pages/Index.cshtml index 190d9d5..70ebfeb 100644 --- a/Selector.Web/Pages/Index.cshtml +++ b/Selector.Web/Pages/Index.cshtml @@ -6,9 +6,4 @@

Welcome

- -
- -@section Scripts { - -} \ No newline at end of file + \ No newline at end of file diff --git a/Selector.Web/Pages/Now.cshtml b/Selector.Web/Pages/Now.cshtml index 6a5dea0..31dbd45 100644 --- a/Selector.Web/Pages/Now.cshtml +++ b/Selector.Web/Pages/Now.cshtml @@ -8,6 +8,7 @@

Now

{{ count }}

+
diff --git a/Selector.Web/Pages/Shared/_Layout.cshtml b/Selector.Web/Pages/Shared/_Layout.cshtml index ba5e913..b8d5726 100644 --- a/Selector.Web/Pages/Shared/_Layout.cshtml +++ b/Selector.Web/Pages/Shared/_Layout.cshtml @@ -28,6 +28,7 @@ + diff --git a/Selector.Web/Startup.cs b/Selector.Web/Startup.cs index 576b93d..7344f61 100644 --- a/Selector.Web/Startup.cs +++ b/Selector.Web/Startup.cs @@ -80,7 +80,7 @@ namespace Selector.Web { // Cookie settings options.Cookie.HttpOnly = true; - options.ExpireTimeSpan = TimeSpan.FromMinutes(5); + options.ExpireTimeSpan = TimeSpan.FromDays(1); options.LoginPath = "/Identity/Account/Login"; options.AccessDeniedPath = "/Identity/Account/AccessDenied"; diff --git a/Selector.Web/scripts/NowPlayingCard.ts b/Selector.Web/scripts/NowPlayingCard.ts new file mode 100644 index 0000000..5f29faf --- /dev/null +++ b/Selector.Web/scripts/NowPlayingCard.ts @@ -0,0 +1,21 @@ +import * as Vue from "vue"; +import { FullTrack } from "./HubInterfaces"; + +let component: Vue.Component = { + props: ['track'], + template: + ` +
+ +

{{ track.name }}

+
+ +
+
+ ` +} + +export default component; \ No newline at end of file diff --git a/Selector.Web/scripts/now.ts b/Selector.Web/scripts/now.ts index 5dd7ffd..cd7f23e 100644 --- a/Selector.Web/scripts/now.ts +++ b/Selector.Web/scripts/now.ts @@ -1,24 +1,49 @@ import * as signalR from "@microsoft/signalr"; import * as Vue from "vue"; import { FullTrack, CurrentlyPlayingDTO } from "./HubInterfaces"; +import NowPlayingCard from "./NowPlayingCard"; const connection = new signalR.HubConnectionBuilder() .withUrl("/hub") .build(); -connection.on("OnNewPlaying", (context: CurrentlyPlayingDTO) => console.log(context)); - connection.start().catch(err => console.error(err)); +interface NowPlaying { + currentlyPlaying?: CurrentlyPlayingDTO +} + const app = Vue.createApp({ data() { return { - count: 4 - } + currentlyPlaying: { + track: { + name: "No Playback", + album: { + name: "", + images: [ + { + url: "" + } + ] + }, + artists: [ + { + name: "" + } + ] + } + } + } as NowPlaying }, created() { - console.log(this.count); + connection.on("OnNewPlaying", (context: CurrentlyPlayingDTO) => + { + console.log(context); + this.currentlyPlaying = context; + }); } }); -// app.component("", TrackNowPlaying); + +app.component("now-playing-card", NowPlayingCard); const vm = app.mount('#app'); \ No newline at end of file diff --git a/Selector.Web/tsconfig.json b/Selector.Web/tsconfig.json index bf000ef..bb33bee 100644 --- a/Selector.Web/tsconfig.json +++ b/Selector.Web/tsconfig.json @@ -4,7 +4,7 @@ "strict": true, "sourceMap": true, "noImplicitAny": true, - "noEmitOnError": true, + "noEmitOnError": false, "module": "es6", "target": "es5", "allowJs": true, @@ -19,6 +19,7 @@ } }, "include": [ - "scripts/**/*" + "scripts/**/*", + "vue-file-import.d.ts" ] } \ No newline at end of file diff --git a/Selector/Watcher/WatcherFactory.cs b/Selector/Watcher/WatcherFactory.cs index c665554..26e57ba 100644 --- a/Selector/Watcher/WatcherFactory.cs +++ b/Selector/Watcher/WatcherFactory.cs @@ -27,6 +27,7 @@ namespace Selector var config = await spotifyFactory.GetConfig(); var client = new SpotifyClient(config); + // TODO: catch spotify exceptions var user = await client.UserProfile.Current(); return new PlayerWatcher(