master
adb-sh 2 years ago
parent 41691a452b
commit 0023959398

@ -6,7 +6,12 @@ export const applyUserRoutes = (router) => {
applyUserRoutesPublic(router);
router.get('/me/currentlyPlaying', async (req, res) => {
const currentlyPlaying = await (await res.locals.user.spotify.local)?.player?.getCurrentlyPlaying('track');
const userLocal = await res.locals.user.spotify.local;
if (!userLocal.player) {
res.status(500);
res.send({ message: 'player is unavailable' });
}
const currentlyPlaying = await userLocal.player.getCurrentlyPlaying('track');
res.status(200);
res.send({ currentlyPlaying });
});

@ -41,4 +41,4 @@ export const findUserBySpotifyId = async (
const newUser = await createLocalUser({ refreshToken });
store.users.push(newUser);
return newUser;
}
};

@ -14,14 +14,14 @@ export const syncSession = async sessionStore => {
const clientStore = await UserStore.findById(client._id);
const clientLocal = await clientStore.spotify.local;
const clientCP = await clientLocal.player.getCurrentlyPlaying("track");
if (clientCP.isPlaying && !hostCP?.item?.uri || !hostCP.isPlaying) {
if (clientCP?.isPlaying && !hostCP?.item?.uri || !hostCP?.isPlaying) {
await clientLocal.player.pause();
} else if (hostCP.isPlaying && clientCP?.item?.id !== hostCP?.item?.id || !clientCP.isPlaying) {
} else if (hostCP?.isPlaying && clientCP?.item?.id !== hostCP?.item?.id || !clientCP?.isPlaying) {
await clientLocal.player.play({
uris: [hostCP?.item?.uri],
position: hostCP.progress + (new Date - hostCPDate),
});
} else if (Math.abs(clientCP.progress - hostCP.progress + (new Date - hostCPDate)) > 500) {
} else if (clientCP?.isPlaying && hostCP?.isPlaying && Math.abs(clientCP.progress - hostCP.progress + (new Date - hostCPDate)) > 500) {
await clientLocal.player.seek(hostCP.progress + (new Date - hostCPDate));
}
}));

Loading…
Cancel
Save