trpc-sveltekit
Version:
SvelteKit adapter for tRPC.io, working with Node.js, Vercel and Netlify
13 lines (12 loc) • 427 B
JavaScript
import { createTRPCProxyClient, createWSClient, wsLink } from '@trpc/client';
export function createTRPCWebSocketClient() {
if (typeof location === 'undefined')
return;
const uri = `${location.protocol === 'http:' ? 'ws:' : 'wss:'}//${location.host}/trpc`;
const wsClient = createWSClient({
url: uri
});
return createTRPCProxyClient({
links: [wsLink({ client: wsClient })]
});
}