All files / modules/services HubFacade.ts

100% Statements 25/25
100% Branches 2/2
100% Functions 2/2
100% Lines 25/25

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 29 30 31 32 33 34 35 36 37 38 39 401x 1x 1x 1x 1x 1x 1x             2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x               2x 2x   1x  
import { useDevicesStore } from "~/stores/useDevicesStore";
import HubSocketService from "./HubSocketService";
import StateManager from "../state/StateManager";
import { useTokenStore } from "~/stores/useTokenStore";
import { useSocketConnectionStore } from "~/stores/useSocketConnectionStore";
import { CONTROL_DEVICE_URL, PAIR_URL, SOCKET_URL } from "~/utils/constants";
import HubAPIService from "./HubAPIService";
 
/**
 * A facade class that provides a simplified interface for interacting with the Hub's services.
 * It combines the `HubSocketService` for managing the socket connection and the `HubAPIService`
 * for interacting with the Hub's API, while managing application state through the `StateManager`.
 */
class HubFacade {
	private stateManager: StateManager = new StateManager(
		useTokenStore.getState(),
		useSocketConnectionStore.getState(),
		useDevicesStore.getState(),
	);
	public socket: HubSocketService = new HubSocketService(
		this.stateManager,
		SOCKET_URL,
	);
	public api: HubAPIService = new HubAPIService(
		this.stateManager,
		PAIR_URL,
		CONTROL_DEVICE_URL,
	);
 
	/**
	 * Creates an instance of HubFacade.
	 *
	 * This constructor initializes the state manager, socket service, and API service
	 * to provide a unified interface for interacting with the Hub.
	 */
	constructor() {}
}
 
export default HubFacade;