import { WebSocketClient as WSClient } from "@autoplex/websocket-client";
import store, { Action } from "./store";

class WebSocketClient extends WSClient
{
	/**
	 * Setup the socket
	 */
	protected setup() {
		store.watch(state => state.user, () => this.authStateChanged());
	}

	/**
	 * Get the app's current auth JWT
	 */
	protected jwt() {
		return store.state.user?.token ?? null;
	}

	/**
	 * Forget the JWT and log out of the app
	 */
	protected forgetJwt() {
		store.dispatch(Action.AuthForget, undefined);
	}
}

export default new WebSocketClient("ws://localhost:3250/");
