Selector/Selector.Web/scripts/now.ts

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-10-31 19:47:07 +00:00
import * as signalR from "@microsoft/signalr";
2021-11-09 18:17:22 +00:00
import * as Vue from "vue";
import { TrackAudioFeatures, CurrentlyPlayingDTO } from "./HubInterfaces";
import NowPlayingCard from "./Now/NowPlayingCard";
2021-11-11 19:54:28 +00:00
import { AudioFeatureCard, AudioFeatureChartCard, PopularityCard, SpotifyLogoLink } from "./Now/Spotify";
import BaseInfoCard from "./Now/BaseInfoCard";
2021-10-31 19:47:07 +00:00
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hub")
.build();
connection.start()
.then(val => {
connection.invoke("OnConnected");
})
.catch(err => console.error(err));
2021-10-31 19:47:07 +00:00
interface InfoCard {
html: string
}
interface NowPlaying {
currentlyPlaying?: CurrentlyPlayingDTO,
trackFeatures?: TrackAudioFeatures,
cards: InfoCard[]
}
2021-11-09 18:17:22 +00:00
const app = Vue.createApp({
data() {
return {
currentlyPlaying: undefined,
trackFeatures: undefined,
cards: []
} as NowPlaying
2021-11-09 18:17:22 +00:00
},
created() {
connection.on("OnNewPlaying", (context: CurrentlyPlayingDTO) =>
{
console.log(context);
this.currentlyPlaying = context;
2021-11-11 19:54:28 +00:00
this.trackFeatures = null;
this.cards = [];
if(context.track !== null && context.track !== undefined)
{
connection.invoke("SendAudioFeatures", context.track.id);
}
});
connection.on("OnNewAudioFeature", (feature: TrackAudioFeatures) =>
{
console.log(feature);
this.trackFeatures = feature;
});
2021-11-09 18:17:22 +00:00
}
});
app.component("now-playing-card", NowPlayingCard);
2021-11-11 19:54:28 +00:00
app.component("audio-feature-card", AudioFeatureCard);
app.component("audio-feature-chart-card", AudioFeatureChartCard);
app.component("info-card", BaseInfoCard);
app.component("popularity", PopularityCard);
app.component("spotify-logo", SpotifyLogoLink);
2021-11-09 18:17:22 +00:00
const vm = app.mount('#app');