import {BaseAction} from "./BaseAction"; import {AppAction} from "./AppAction"; import {CellColorAction, isCellColorAction} from "./CellAction"; import {isUserActiveColorAction, UserActiveColorAction} from "./UserAction"; export const CLIENT_HELLO = "CLIENT_HELLO" /** Sent when the client connects. */ export interface ClientHelloCommand extends BaseAction { readonly type: typeof CLIENT_HELLO /** The protocol version the client is running on */ readonly version: number } export function isClientHelloCommand(action: AppAction): action is ClientHelloCommand { return action.type === CLIENT_HELLO } export const CLIENT_REFRESH = "CLIENT_REFRESH" /** Sent when the user requests a refresh. */ export interface ClientRefreshCommand extends BaseAction { readonly type: typeof CLIENT_REFRESH } export function isClientRefreshCommand(action: AppAction): action is ClientRefreshCommand { return action.type === CLIENT_REFRESH } export const CLIENT_PENDING = "CLIENT_PENDING" /** Synthesized when a user action is ready to be sent to the server. */ export interface ClientPendingAction extends BaseAction { readonly type: typeof CLIENT_PENDING readonly pending: SendableAction } export function isClientPendingAction(action: AppAction): action is ClientPendingAction { return action.type === CLIENT_PENDING } export interface SentAction { readonly id: number readonly action: SendableAction } export const CLIENT_ACT = "CLIENT_ACT" /** Sent to the server when the user performs an action. */ export interface ClientActCommand extends BaseAction { readonly type: typeof CLIENT_ACT readonly actions: readonly SentAction[] } export function isClientActCommand(action: AppAction): action is ClientActCommand { return action.type === CLIENT_ACT } export const CLIENT_GOODBYE = "CLIENT_GOODBYE" /** Synthesized when the client wants to close the connection. */ export interface ClientGoodbyeAction extends BaseAction { readonly type: typeof CLIENT_GOODBYE readonly code: number, readonly reason: string, } export function isClientGoodbyeCommand(action: AppAction): action is ClientGoodbyeAction { return action.type === CLIENT_GOODBYE } export type SendableAction = CellColorAction | UserActiveColorAction export function isSendableAction(action: AppAction): action is SendableAction { return isCellColorAction(action) || isUserActiveColorAction(action) } export type ClientCommand = ClientHelloCommand | ClientRefreshCommand | ClientActCommand export function isClientCommand(action: AppAction): action is ClientCommand { return isClientHelloCommand(action) || isClientRefreshCommand(action) || isClientActCommand(action) } export type ClientAction = ClientCommand | ClientPendingAction | ClientGoodbyeAction export function isClientAction(action: AppAction): action is ClientAction { return isClientCommand(action) || isClientPendingAction(action) || isClientGoodbyeCommand(action) }