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";
|
2022-06-23 19:26:36 +01:00
|
|
|
import { TrackAudioFeatures, PlayCount, CurrentlyPlayingDTO, CountSample } from "./HubInterfaces";
|
2021-11-10 01:46:30 +00:00
|
|
|
import NowPlayingCard from "./Now/NowPlayingCard";
|
2021-11-11 19:54:28 +00:00
|
|
|
import { AudioFeatureCard, AudioFeatureChartCard, PopularityCard, SpotifyLogoLink } from "./Now/Spotify";
|
2022-06-23 19:26:36 +01:00
|
|
|
import { PlayCountChartCard, CombinedPlayCountChartCard } from "./Now/PlayCountGraph";
|
|
|
|
import { ArtistBreakdownChartCard } from "./Now/ArtistBreakdownGraph";
|
2021-12-01 23:34:30 +00:00
|
|
|
import { PlayCountCard, LastFmLogoLink } from "./Now/LastFm";
|
2021-11-10 01:46:30 +00:00
|
|
|
import BaseInfoCard from "./Now/BaseInfoCard";
|
2021-10-31 19:47:07 +00:00
|
|
|
|
|
|
|
const connection = new signalR.HubConnectionBuilder()
|
|
|
|
.withUrl("/hub")
|
2022-11-12 11:05:42 +00:00
|
|
|
.withAutomaticReconnect()
|
2021-10-31 19:47:07 +00:00
|
|
|
.build();
|
|
|
|
|
2021-11-09 22:47:49 +00:00
|
|
|
connection.start()
|
|
|
|
.then(val => {
|
|
|
|
connection.invoke("OnConnected");
|
|
|
|
})
|
|
|
|
.catch(err => console.error(err));
|
2021-10-31 19:47:07 +00:00
|
|
|
|
2021-11-10 01:46:30 +00:00
|
|
|
interface InfoCard {
|
2022-06-02 00:53:57 +01:00
|
|
|
Content: string
|
2021-11-10 01:46:30 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 20:58:02 +00:00
|
|
|
interface NowPlaying {
|
2021-11-10 01:46:30 +00:00
|
|
|
currentlyPlaying?: CurrentlyPlayingDTO,
|
|
|
|
trackFeatures?: TrackAudioFeatures,
|
2021-11-30 20:38:26 +00:00
|
|
|
playCount?: PlayCount,
|
2021-11-10 01:46:30 +00:00
|
|
|
cards: InfoCard[]
|
2021-11-09 20:58:02 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 19:26:36 +01:00
|
|
|
export interface ScrobbleDataSeries {
|
|
|
|
label: string,
|
|
|
|
colour: string,
|
|
|
|
data: CountSample[]
|
|
|
|
}
|
|
|
|
|
2021-11-09 18:17:22 +00:00
|
|
|
const app = Vue.createApp({
|
|
|
|
data() {
|
|
|
|
return {
|
2021-11-10 01:46:30 +00:00
|
|
|
currentlyPlaying: undefined,
|
|
|
|
trackFeatures: undefined,
|
2021-11-30 20:38:26 +00:00
|
|
|
playCount: undefined,
|
2021-11-10 01:46:30 +00:00
|
|
|
cards: []
|
2021-11-09 20:58:02 +00:00
|
|
|
} as NowPlaying
|
2021-11-09 18:17:22 +00:00
|
|
|
},
|
2021-12-01 23:34:30 +00:00
|
|
|
computed: {
|
|
|
|
lastfmTrack() {
|
|
|
|
return {
|
|
|
|
name: this.currentlyPlaying.track.name,
|
|
|
|
artist: this.currentlyPlaying.track.artists[0].name,
|
|
|
|
album: this.currentlyPlaying.track.album.name,
|
|
|
|
album_artist: this.currentlyPlaying.track.album.artists[0].name,
|
|
|
|
};
|
2022-06-18 10:56:34 +01:00
|
|
|
},
|
|
|
|
showArtistChart(){
|
2022-06-22 21:51:38 +01:00
|
|
|
return this.playCount !== null && this.playCount !== undefined && this.playCount.artistCountData.length > 3;
|
2022-06-18 10:56:34 +01:00
|
|
|
},
|
|
|
|
showAlbumChart() {
|
2022-06-22 21:51:38 +01:00
|
|
|
return this.playCount !== null && this.playCount !== undefined && this.playCount.albumCountData.length > 3;
|
2022-06-18 10:56:34 +01:00
|
|
|
},
|
|
|
|
showTrackChart(){
|
2022-06-22 21:51:38 +01:00
|
|
|
return this.playCount !== null && this.playCount !== undefined && this.playCount.trackCountData.length > 3;
|
2022-06-23 19:26:36 +01:00
|
|
|
},
|
2022-06-28 07:25:24 +01:00
|
|
|
showArtistBreakdown(){
|
|
|
|
return this.playCount !== null && this.playCount !== undefined && this.playCount.artist > 0;
|
|
|
|
},
|
2022-06-23 19:26:36 +01:00
|
|
|
earliestDate(){
|
|
|
|
return this.playCount.artistCountData[0].timeStamp;
|
|
|
|
},
|
|
|
|
latestDate(){
|
|
|
|
return this.playCount.artistCountData.at(-1).timeStamp;
|
|
|
|
},
|
|
|
|
trackGraphTitle() { return `${this.currentlyPlaying.track.name} 🎵`},
|
|
|
|
albumGraphTitle() { return `${this.currentlyPlaying.track.album.name} 💿`},
|
|
|
|
artistGraphTitle() { return `${this.currentlyPlaying.track.artists[0].name} 🎤`},
|
|
|
|
combinedData(){
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: "artist",
|
|
|
|
colour: "#598556",
|
|
|
|
data: this.playCount.artistCountData
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "album",
|
|
|
|
colour: "#a34c77",
|
|
|
|
data: this.playCount.albumCountData
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "track",
|
|
|
|
colour: "#7a99c2",
|
|
|
|
data: this.playCount.trackCountData
|
|
|
|
}];
|
2021-12-01 23:34:30 +00:00
|
|
|
}
|
|
|
|
},
|
2021-11-09 18:17:22 +00:00
|
|
|
created() {
|
2021-11-09 20:58:02 +00:00
|
|
|
connection.on("OnNewPlaying", (context: CurrentlyPlayingDTO) =>
|
|
|
|
{
|
|
|
|
console.log(context);
|
|
|
|
this.currentlyPlaying = context;
|
2021-11-11 19:54:28 +00:00
|
|
|
this.trackFeatures = null;
|
2021-11-30 20:38:26 +00:00
|
|
|
this.playCount = null;
|
2021-11-10 01:46:30 +00:00
|
|
|
this.cards = [];
|
|
|
|
|
2021-11-10 23:54:28 +00:00
|
|
|
if(context.track !== null && context.track !== undefined)
|
|
|
|
{
|
2022-06-18 10:56:34 +01:00
|
|
|
if(context.track.id !== null)
|
|
|
|
{
|
|
|
|
connection.invoke("SendAudioFeatures", context.track.id);
|
|
|
|
}
|
2021-11-30 20:38:26 +00:00
|
|
|
connection.invoke("SendPlayCount",
|
|
|
|
context.track.name,
|
|
|
|
context.track.artists[0].name,
|
|
|
|
context.track.album.name,
|
|
|
|
context.track.album.artists[0].name
|
|
|
|
);
|
2022-06-02 00:53:57 +01:00
|
|
|
connection.invoke("SendFacts",
|
|
|
|
context.track.name,
|
|
|
|
context.track.artists[0].name,
|
|
|
|
context.track.album.name,
|
|
|
|
context.track.album.artists[0].name
|
|
|
|
);
|
2021-11-10 23:54:28 +00:00
|
|
|
}
|
2021-11-09 20:58:02 +00:00
|
|
|
});
|
2021-11-10 01:46:30 +00:00
|
|
|
|
2021-11-10 23:54:28 +00:00
|
|
|
connection.on("OnNewAudioFeature", (feature: TrackAudioFeatures) =>
|
|
|
|
{
|
|
|
|
console.log(feature);
|
|
|
|
this.trackFeatures = feature;
|
|
|
|
});
|
2021-11-30 20:38:26 +00:00
|
|
|
|
|
|
|
connection.on("OnNewPlayCount", (count: PlayCount) => {
|
|
|
|
|
|
|
|
console.log(count);
|
|
|
|
this.playCount = count;
|
|
|
|
});
|
2022-06-02 00:53:57 +01:00
|
|
|
|
|
|
|
connection.on("OnNewCard", (card: InfoCard) => {
|
|
|
|
|
|
|
|
console.log(card);
|
|
|
|
this.cards.push(card);
|
|
|
|
});
|
2021-11-09 18:17:22 +00:00
|
|
|
}
|
|
|
|
});
|
2021-11-09 20:58:02 +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);
|
2021-11-10 01:46:30 +00:00
|
|
|
app.component("info-card", BaseInfoCard);
|
|
|
|
app.component("popularity", PopularityCard);
|
|
|
|
app.component("spotify-logo", SpotifyLogoLink);
|
2021-12-01 23:34:30 +00:00
|
|
|
app.component("lastfm-logo", LastFmLogoLink);
|
2021-11-30 20:38:26 +00:00
|
|
|
app.component("play-count-card", PlayCountCard);
|
2022-06-18 10:56:34 +01:00
|
|
|
app.component("play-count-chart-card", PlayCountChartCard);
|
2022-06-23 19:26:36 +01:00
|
|
|
app.component("play-count-chart-card-comb", CombinedPlayCountChartCard);
|
|
|
|
app.component("artist-breakdown", ArtistBreakdownChartCard);
|
2021-11-09 18:17:22 +00:00
|
|
|
const vm = app.mount('#app');
|