websocket in nextjs using Elysia
Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
African Slender-snouted CrocodileOP
Tried to create websocket route handlers and sending a request but getting errors although I followed the docs
2 Replies
African Slender-snouted CrocodileOP
.ws('/chat',{
body:t.String(),
response:t.String(),
message(ws,message){
ws.send(message)
}
})Frontend code using Eden treaty
const onSubmit: SubmitHandler<Inputs> = async(data) =>{
setIsLoading(true);
try{
const response = client.api.chat.subscribe();
response.subscribe((message)=>{
console.log('got',message)
})
response.send(data.message)
}catch(error){
toast.error("An error occurred. Please try again later.");
}finally{
setIsLoading(false)
}
}