Idk, quick backup

This commit is contained in:
Alois 2026-03-28 22:10:27 +01:00
commit 396defef64
19 changed files with 519 additions and 108 deletions

View file

@ -0,0 +1,32 @@
{
"name": "@tensamin/call",
"private": true,
"version": "0.0.0",
"type": "module",
"exports": {
"./context": "./src/context.tsx",
"./screen": "./src/screen.tsx",
"./utils": "./src/utils.ts"
},
"scripts": {
"format": "bunx prettier --write .",
"lint": "eslint src",
"build": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@tanstack/react-query": "^5.0.0",
"@tanstack/react-router": "^1.0.0",
"@tanstack/react-virtual": "^3.0.0",
"@tensamin/crypto": "workspace:*",
"@tensamin/ttp": "workspace:*",
"@tensamin/storage": "workspace:*",
"@tensamin/user": "workspace:*",
"@tensamin/markdown": "workspace:*",
"@tensamin/shared": "workspace:*",
"@tensamin/ui": "workspace:*",
"lucide-react": "^0.564.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"zod": "^4.3.6"
}
}

View file

@ -0,0 +1,76 @@
import { createContext, useContext, useEffect, useState } from "react";
import { log } from "@tensamin/shared/log";
import { useNavigate } from "@tanstack/react-router";
export const context = createContext<contextType | undefined>(undefined);
export default function Provider(props: { children: React.ReactNode }) {
const navigate = useNavigate();
const [state, setState] = useState<"closed" | "connecting" | "open">(
"closed",
);
const [callId, setCallId] = useState<string | null>(null);
const [callSecret, setCallSecret] = useState<string | null>(null);
function connect(callId: string, callSecret: string) {
setState("connecting");
setCallId(callId);
setCallSecret(callSecret);
log(2, "Call", "purple", "Connecting to call", { callId, callSecret });
}
// Master reset function
function disconnect() {
setState("closed");
setCallId(null);
setCallSecret(null);
}
// Utils
function joinCall(userId: number, callId?: string) {
// get/generate e2ee secret
// go into convs and find call id
// generate shared secret and decrypt enc call secret
// check if user is already in call
// connect to call
connect("", "");
// navigate to call page
navigate({ to: "/call", search: { userId: userId, callId: callId } });
}
// Event listener for incoming calls
useEffect(() => {}, []);
return (
<context.Provider
value={{
state,
connect,
disconnect,
joinCall,
}}
>
{props.children}
</context.Provider>
);
}
type contextType = {
state: "closed" | "connecting" | "open";
connect: (callId: string, callSecret: string) => void;
disconnect: () => void;
joinCall: (userId: number, callId?: string) => void;
};
export function useCall(): contextType {
const ctx = useContext(context);
if (!ctx) {
throw new Error("useCall must be used within a CallProvider");
}
return ctx;
}

View file

@ -0,0 +1,3 @@
export default function Screen() {
return <div></div>;
}

View file

@ -0,0 +1,3 @@
export function displayCallId(callId: string) {
return callId.slice(0, 4) + "..." + callId.slice(-4);
}

View file

@ -0,0 +1,13 @@
import { z } from "zod";
import { socket } from "@tensamin/shared/data";
export type RawMessages = z.infer<
typeof socket.messages_get.response
>["messages"];
export type RawMessage = RawMessages[number];
export type LiveMessage = RawMessage & {
failed?: boolean;
localId: string;
};

View file

@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"noEmit": true
},
"include": ["src"]
}