All files / Rindu/hooks useReconnectSpotifyPlayer.ts

58.33% Statements 7/12
66.66% Branches 2/3
50% Functions 2/4
54.54% Lines 6/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2919x   19x     41x                 41x   41x 41x                      
import { Dispatch, SetStateAction, useEffect } from "react";
 
import { useAuth } from "hooks";
import { AudioPlayer } from "hooks/useSpotifyPlayer";
 
export function useReconnectSpotifyPlayer({
  reconnect,
  player,
  setReconnectionError,
}: {
  reconnect: boolean;
  player: Spotify.Player | AudioPlayer | undefined;
  setReconnectionError: Dispatch<SetStateAction<boolean>>;
}): void {
  const { isPremium } = useAuth();
 
  useEffect(() => {
    if (!reconnect || !isPremium) return;
    const timer = setTimeout(() => {
      (player as Spotify.Player).connect();
      setReconnectionError(false);
    }, 2000);
 
    return () => {
      clearTimeout(timer);
    };
  }, [isPremium, player, reconnect, setReconnectionError]);
}