Selector/Selector.Web/scripts/now.ts

61 lines
1.7 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";
import { 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;
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);
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');