import { createTRPCProxyClient, httpLink, createWSClient, wsLink, splitLink } from "@trpc/client" import type { AppRouter } from "../backend" const wsUrl = new URL(location.href) wsUrl.protocol = wsUrl.protocol.replace("http", "ws") wsUrl.pathname = "/ws" wsUrl.hash = "" const wsClient = createWSClient({ url: wsUrl.href }) export const trpcClient = createTRPCProxyClient({ links: [ splitLink({ condition: o => o.type === "subscription", true: wsLink({ client: wsClient }), false: httpLink({ url: "/trpc" }) }) ] })