import { Callbag } from "callbag"; import { ClientMessage, MessageTypes, ServerMessage } from "./LockstepClient"; type Client = Callbag, ClientMessage>; /** Stub loopback server that handles a single client, for schemes where GlobalInput = LocalInput[] */ export function Loopback(start: number, data?: Client | ClientMessage) { if(start != 0) return; const sink = data as Client; sink(0, (type: number, data?: Client | ClientMessage) => { if(type == 1) { // message from client; just reflect for now const message = data as ClientMessage; switch(message.t) { case MessageTypes.INPUT: sink(1, { t: MessageTypes.INPUT, i: [message.i], }); break; } } }); sink(1, {t: MessageTypes.SET_STATE, u: 0, s: {}}); };