export const EdenWebsocketMessageTypes = {
    playerUpdate: "player-update",
    playersSync: "players-sync",
};
function isObject(value) {
    return typeof value === "object" && value !== null;
}
export function parseIncomingWebsocketMessage(raw) {
    if (typeof raw !== "string") {
        return undefined;
    }
    try {
        const parsed = JSON.parse(raw);
        if (!isObject(parsed) || typeof parsed.type !== "string") {
            return undefined;
        }
        if (parsed.type === EdenWebsocketMessageTypes.playersSync) {
            return {
                type: EdenWebsocketMessageTypes.playersSync,
                players: Array.isArray(parsed.players)
                    ? parsed.players
                    : [],
            };
        }
        return undefined;
    }
    catch {
        return undefined;
    }
}
export function buildPlayerUpdateMessage(payload) {
    return {
        type: EdenWebsocketMessageTypes.playerUpdate,
        ...payload,
    };
}
