import {CLIENT_ACT, CLIENT_HELLO, CLIENT_REFRESH, ClientCommand, SentAction} from "../actions/ClientAction"; import {ClientActPB_IDed, ClientCommandPB} from "../proto/client"; import {sendableActionToPB} from "./SyncableActionToPb"; export function sentActionToPb(message: SentAction): ClientActPB_IDed { return { id: message.id, action: sendableActionToPB(message.action), } } export function clientToPb(message: ClientCommand): ClientCommandPB { switch (message.type) { case CLIENT_HELLO: return { hello: { version: message.version, }, refresh: undefined, act: undefined, } case CLIENT_REFRESH: return { refresh: { }, hello: undefined, act: undefined, } case CLIENT_ACT: return { act: { actions: message.actions.map(sentActionToPb) }, hello: undefined, refresh: undefined, } } }