debug
This commit is contained in:
parent
41691a452b
commit
0023959398
@ -6,7 +6,12 @@ export const applyUserRoutes = (router) => {
|
|||||||
applyUserRoutesPublic(router);
|
applyUserRoutesPublic(router);
|
||||||
|
|
||||||
router.get('/me/currentlyPlaying', async (req, res) => {
|
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.status(200);
|
||||||
res.send({ currentlyPlaying });
|
res.send({ currentlyPlaying });
|
||||||
});
|
});
|
||||||
|
@ -41,4 +41,4 @@ export const findUserBySpotifyId = async (
|
|||||||
const newUser = await createLocalUser({ refreshToken });
|
const newUser = await createLocalUser({ refreshToken });
|
||||||
store.users.push(newUser);
|
store.users.push(newUser);
|
||||||
return newUser;
|
return newUser;
|
||||||
}
|
};
|
||||||
|
@ -14,14 +14,14 @@ export const syncSession = async sessionStore => {
|
|||||||
const clientStore = await UserStore.findById(client._id);
|
const clientStore = await UserStore.findById(client._id);
|
||||||
const clientLocal = await clientStore.spotify.local;
|
const clientLocal = await clientStore.spotify.local;
|
||||||
const clientCP = await clientLocal.player.getCurrentlyPlaying("track");
|
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();
|
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({
|
await clientLocal.player.play({
|
||||||
uris: [hostCP?.item?.uri],
|
uris: [hostCP?.item?.uri],
|
||||||
position: hostCP.progress + (new Date - hostCPDate),
|
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));
|
await clientLocal.player.seek(hostCP.progress + (new Date - hostCPDate));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user