From 76ca66429896345adf8ff83fb3c43832c796643f Mon Sep 17 00:00:00 2001 From: Alois Date: Fri, 3 Apr 2026 00:38:35 +0200 Subject: [PATCH] Fully renamed socket to ttp --- .../web/src/features/conversation/context.tsx | 4 +-- apps/web/src/features/legal/screen.tsx | 2 +- apps/web/src/routes/app/home.tsx | 4 +-- packages/call/src/values.ts | 4 +-- packages/chat/src/behaviour/conversation.ts | 4 +-- packages/chat/src/components/input.tsx | 4 +-- packages/chat/src/context.tsx | 4 +-- packages/chat/src/values.ts | 4 +-- packages/shared/src/data.ts | 8 ++--- packages/shared/src/log.tsx | 15 +++++++- packages/ttp/src/context.tsx | 34 +++++++++---------- packages/ttp/src/core.ts | 4 +-- packages/user/src/context.tsx | 6 ++-- 13 files changed, 55 insertions(+), 42 deletions(-) diff --git a/apps/web/src/features/conversation/context.tsx b/apps/web/src/features/conversation/context.tsx index fa0a2ee..11ae41d 100644 --- a/apps/web/src/features/conversation/context.tsx +++ b/apps/web/src/features/conversation/context.tsx @@ -1,4 +1,4 @@ -import { useSocket } from "@tensamin/ttp/context"; +import { useTTP } from "@tensamin/ttp/context"; import { createContext, useContext, @@ -31,7 +31,7 @@ export default function ConversationProvider(props: { children: ReactNode }) { ); const [communities, setCommunities] = useState(null); - const { send } = useSocket(); + const { send } = useTTP(); useEffect(() => { let active = true; diff --git a/apps/web/src/features/legal/screen.tsx b/apps/web/src/features/legal/screen.tsx index d7fbb8e..e301674 100644 --- a/apps/web/src/features/legal/screen.tsx +++ b/apps/web/src/features/legal/screen.tsx @@ -148,7 +148,7 @@ export default function Screen(props: { children: React.ReactNode }) { return () => { active = false; }; - }, [load, location.pathname]); + }, [load, location.pathname, userId]); if (error !== "" && errorDescription !== "") { return ; diff --git a/apps/web/src/routes/app/home.tsx b/apps/web/src/routes/app/home.tsx index ff56b0b..a42f096 100644 --- a/apps/web/src/routes/app/home.tsx +++ b/apps/web/src/routes/app/home.tsx @@ -11,7 +11,7 @@ import { } from "@tensamin/ui/cmp/dialog"; import z from "zod"; import { toast } from "@tensamin/shared/log"; -import { useSocket } from "@tensamin/ttp/context"; +import { useTTP } from "@tensamin/ttp/context"; import { useState } from "react"; import { Loader2 } from "lucide-react"; @@ -27,7 +27,7 @@ export default function Page() { // Add Conversation Button Component function AddConversationButton() { - const { send } = useSocket(); + const { send } = useTTP(); const [loading, setLoading] = useState(false); function submit(username: string | null) { diff --git a/packages/call/src/values.ts b/packages/call/src/values.ts index 692737b..87fac4f 100644 --- a/packages/call/src/values.ts +++ b/packages/call/src/values.ts @@ -1,8 +1,8 @@ import { z } from "zod"; -import { socket } from "@tensamin/shared/data"; +import { ttp } from "@tensamin/shared/data"; export type RawMessages = z.infer< - typeof socket.messages_get.response + typeof ttp.messages_get.response >["messages"]; export type RawMessage = RawMessages[number]; diff --git a/packages/chat/src/behaviour/conversation.ts b/packages/chat/src/behaviour/conversation.ts index d50223f..b41c01a 100644 --- a/packages/chat/src/behaviour/conversation.ts +++ b/packages/chat/src/behaviour/conversation.ts @@ -1,5 +1,5 @@ import type { BoundSendFn } from "@tensamin/ttp/core"; -import type { Socket } from "@tensamin/shared/data"; +import type { TTP } from "@tensamin/shared/data"; import type { RawMessages } from "../values"; /** @@ -11,7 +11,7 @@ import type { RawMessages } from "../values"; * @returns Promise. */ export async function getMessages( - send: BoundSendFn, + send: BoundSendFn, amount: number, offset: number, user_id: number, diff --git a/packages/chat/src/components/input.tsx b/packages/chat/src/components/input.tsx index 42b94f9..698b0fd 100644 --- a/packages/chat/src/components/input.tsx +++ b/packages/chat/src/components/input.tsx @@ -6,7 +6,7 @@ import { Button } from "@tensamin/ui/cmp/button"; import { Plus, Laugh, Clapperboard } from "lucide-react"; import { useChat } from "../context"; -import { useSocket } from "@tensamin/ttp/context"; +import { useTTP } from "@tensamin/ttp/context"; import { useCrypto } from "@tensamin/crypto/context"; import { log, toast } from "@tensamin/shared/log"; @@ -15,7 +15,7 @@ export default function InputComponent() { const [invertEnterBehavior, setInvertEnterBehavior] = React.useState(false); const { encrypt } = useCrypto(); - const { send } = useSocket(); + const { send } = useTTP(); const { addLiveMessage, sharedSecret, userId } = useChat(); const { load } = useStorage(); diff --git a/packages/chat/src/context.tsx b/packages/chat/src/context.tsx index 096d28f..533e209 100644 --- a/packages/chat/src/context.tsx +++ b/packages/chat/src/context.tsx @@ -14,7 +14,7 @@ import type { LiveMessage, RawMessage, RawMessages } from "./values"; import { useCrypto } from "@tensamin/crypto/context"; import { useUser } from "@tensamin/user/context"; import { useStorage } from "@tensamin/storage/context"; -import { useSocket } from "@tensamin/ttp/context"; +import { useTTP } from "@tensamin/ttp/context"; export const context = createContext(undefined); @@ -29,7 +29,7 @@ export default function Provider(props: { children: ReactNode }) { const { getSharedSecret } = useCrypto(); const { get } = useUser(); const { load } = useStorage(); - const { send, subscribePush } = useSocket(); + const { send, subscribePush } = useTTP(); const [liveMessagesState, setLiveMessagesState] = useState([]); const [currentSharedSecret, setCurrentSharedSecret] = useState(""); diff --git a/packages/chat/src/values.ts b/packages/chat/src/values.ts index 9bfc328..e0f6dec 100644 --- a/packages/chat/src/values.ts +++ b/packages/chat/src/values.ts @@ -1,8 +1,8 @@ import { z } from "zod"; -import { socket } from "@tensamin/shared/data"; +import { ttp } from "@tensamin/shared/data"; export type RawMessages = z.infer< - typeof socket.messages_get.response + typeof ttp.messages_get.response >["messages"]; export type RawMessage = RawMessages[number]; diff --git a/packages/shared/src/data.ts b/packages/shared/src/data.ts index 1580cdc..5143412 100644 --- a/packages/shared/src/data.ts +++ b/packages/shared/src/data.ts @@ -32,10 +32,10 @@ export const failedUser = { sub_level: 0, user_id: 0, username: "unknown", -} as z.infer; +} as z.infer; -// Socket -export const socket = { +// TTP +export const ttp = { identification: { request: z .object({ @@ -162,7 +162,7 @@ export const socket = { }, } satisfies Record; -export type Socket = typeof socket; +export type TTP = typeof ttp; // Storage export interface Storage { diff --git a/packages/shared/src/log.tsx b/packages/shared/src/log.tsx index e3726a0..571c9b8 100644 --- a/packages/shared/src/log.tsx +++ b/packages/shared/src/log.tsx @@ -11,7 +11,16 @@ import { Ban, Check, Info, TriangleAlert } from "lucide-react"; export function log( logLevel: number, logger: string, - color: "red" | "green" | "yellow" | "purple" | "blue", + color: + | "red" + | "green" + | "yellow" + | "purple" + | "blue" + | "cyan" + | "white" + | "black" + | "gray", ...args: unknown[] ) { const currentLogLevel = Number(localStorage.getItem("log_level") || 0); @@ -24,6 +33,10 @@ export function log( yellow: "\x1b[33m", purple: "\x1b[35m", blue: "\x1b[34m", + cyan: "\x1b[36m", + white: "\x1b[37m", + black: "\x1b[30m", + gray: "\x1b[90m", }; const resetCode = "\x1b[0m"; console.log(`${colorCodes[color]}${logger}${resetCode}`, ...args); diff --git a/packages/ttp/src/context.tsx b/packages/ttp/src/context.tsx index 003c0a3..4b3c821 100644 --- a/packages/ttp/src/context.tsx +++ b/packages/ttp/src/context.tsx @@ -21,8 +21,8 @@ import { TRANSPORT_URL, } from "./values"; import { - socket as schemas, - type Socket as Schemas, + ttp as schemas, + type TTP as Schemas, } from "@tensamin/shared/data"; import Loading from "@tensamin/ui/screens/loading"; import ErrorScreen from "@tensamin/ui/screens/error"; @@ -140,10 +140,10 @@ type ContextType = { identified: () => boolean; }; -const socketContext = createContext(undefined); +const TTPContext = createContext(undefined); /** - * Provides socket transport state and authenticated send operations to children. + * Provides ttp transport state and authenticated send operations to children. * @param props Component props with children. * @returns Loading, error, or provider-wrapped JSX. */ @@ -186,7 +186,7 @@ export default function Provider(props: { const client = clientRef.current; if (!client) { - return Promise.reject(new Error("Socket is not connected")); + return Promise.reject(new Error("ttp is not connected")); } if (options?.noResponse) { @@ -240,7 +240,7 @@ export default function Provider(props: { setIotaPing(remotePing); } } catch (intervalError) { - log(1, "Socket", "yellow", "Ping failed", intervalError); + log(1, "ttp", "yellow", "Ping failed", intervalError); } }, PING_INTERVAL); @@ -310,7 +310,7 @@ export default function Provider(props: { setErrorDescription( "Unable to connect to the server after multiple attempts. Please check your internet connection or try again later.", ); - log(0, "Socket", "red", "Reconnection attempts exhausted", reason); + log(0, "ttp", "red", "Reconnection attempts exhausted", reason); return; } @@ -355,7 +355,7 @@ export default function Provider(props: { return; } - log(0, "Socket", "red", "Disconnected", closeError, { + log(0, "ttp", "red", "Disconnected", closeError, { stopSending: isStopSendingError(closeError), }); scheduleReconnect(closeError); @@ -381,7 +381,7 @@ export default function Provider(props: { return; } - log(0, "Socket", "red", "Connection attempt failed", connectError); + log(0, "ttp", "red", "Connection attempt failed", connectError); scheduleReconnect(connectError); } } @@ -490,7 +490,7 @@ export default function Provider(props: { log( isFatal ? 0 : 1, - "Socket", + "ttp", isFatal ? "red" : "yellow", "Identification handshake failed", protocolErrorDetails ?? identificationError, @@ -578,20 +578,20 @@ export default function Provider(props: { } return ( - + {props.children} - + ); } /** - * Returns the active socket context and enforces provider usage. - * @returns Socket context API for transport operations and connection state. + * Returns the active ttp context and enforces provider usage. + * @returns ttp context API for transport operations and connection state. */ -export function useSocket(): ContextType { - const context = useContext(socketContext); +export function useTTP(): ContextType { + const context = useContext(TTPContext); if (!context) { - throw new Error("useSocket must be used within a SocketProvider"); + throw new Error("useTTP must be used within a TTPProvider"); } return context; } diff --git a/packages/ttp/src/core.ts b/packages/ttp/src/core.ts index d6a4838..a5afccd 100644 --- a/packages/ttp/src/core.ts +++ b/packages/ttp/src/core.ts @@ -199,7 +199,7 @@ export function createTransportClient( */ const handleIncomingMessage = (message: TypedMessage) => { if (message.type !== "pong") { - log(2, "ttp", "blue", "Received:", message.type, message.data, { + log(2, "ttp", "cyan", "Received:", message.type, message.data, { id: message.id, }); } @@ -563,7 +563,7 @@ export function createTransportClient( } if (type !== "ping") { - log(2, "ttp", "purple", "Sent:", type, payload, { id: options.id }); + log(2, "ttp", "gray", "Sent:", type, payload, { id: options.id }); } const expectsResponse = !options?.noResponse; diff --git a/packages/user/src/context.tsx b/packages/user/src/context.tsx index 6b22bce..2f05106 100644 --- a/packages/user/src/context.tsx +++ b/packages/user/src/context.tsx @@ -1,7 +1,7 @@ import * as React from "react"; -import { useSocket } from "@tensamin/ttp/context"; +import { useTTP } from "@tensamin/ttp/context"; -import { socket as schemas } from "@tensamin/shared/data"; +import { ttp as schemas } from "@tensamin/shared/data"; import type z from "zod"; export type User = z.infer; @@ -20,7 +20,7 @@ const UserContext = React.createContext(undefined); export default function UserProvider(props: { children: React.ReactNode }) { const storageRef = React.useRef>({}); - const { send } = useSocket(); + const { send } = useTTP(); /** * Executes get.