NEO
NEO3y ago

Websockets not sending data

Hi, I have a websocket route that doesn't seem to be sending any data I added a setInterval to test it but it doesn't seem to be working Version: 10.0.0-rc.1
1 Reply
NEO
NEOOP3y ago
Apparently I missed the error "Subscriptions should use wsLink" the fix is to use splitLink function to conditionally handle websocket requests
export const trpcInstance = trpc.createClient({
links: [
splitLink({
condition(op) {
return op.type === 'subscription';
},
true: wsLink({
client: wsClient,
}),
false: httpLink({
url: `http://localhost:3000`,
headers() {
return {
Authorization: store.getState().appState.user.authToken
}
}
})
})
]
})
export const trpcInstance = trpc.createClient({
links: [
splitLink({
condition(op) {
return op.type === 'subscription';
},
true: wsLink({
client: wsClient,
}),
false: httpLink({
url: `http://localhost:3000`,
headers() {
return {
Authorization: store.getState().appState.user.authToken
}
}
})
})
]
})
Hope this helps somebody closing the post now