You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone, my bug is easy to understand. I want to send from my next api a message to a socketIO server running with nodejs.
When I try to send a message including an object with 2 or less properties, it's working. But when I send an object with more than 2 properties, the socketIO server don't receive the message
To Reproduce
"socket.io-client": "^4.7.5" for the nextjs Api
"socket.io": "^4.7.5" for the socketio server
SocketIO server
consthttp=require('http');const{ Server }=require('socket.io');constserver=http.createServer();constio=newServer(server,{cors: {origin: '*',}});io.on('connection',(socket)=>{console.log('A user connected:',socket.id,socket.username);socket.on("mytest",({ first, second, third })=>{console.log("Received message: ",{ first, second, third });});socket.on('disconnect',()=>{console.log('A user disconnected:',socket.id,socket.username);});});server.listen(5000,()=>{console.log('Server is running on port 5000');});
NEXTJS API
"use server";import{io}from'socket.io-client';import{NextApiRequest}from'next';import{NextResponse}from'next/server';importprismafrom'@/lib/prisma';constSOCKET_URL='ws://localhost:5000';// URL du serveur Socket.ioconstnewSocket=io(SOCKET_URL);newSocket.on('connect',()=>{console.log("Connected with id: ",newSocket.id);});asyncfunctiongetMessagesToSend(visibility_date: Date){try{constnow=newDate();now.setMinutes(now.getMinutes()-30);constmessages=awaitprisma.messages.findMany({where: {visibility_date: {gte: now,lte: visibility_date}},select: {sender_id: true,receiver_id: true,content: true,}});returnmessages;}catch(error){console.error('Erreur lors de la récupération des messages :',error);thrownewError('Erreur Interne du Serveur');}}asyncfunctionhandleScheduleMessage(){try{constnow=newDate();constmessagesToSend=awaitgetMessagesToSend(now);messagesToSend.forEach((message)=>{newSocket.emit("mytest",{first: "first",second: "second",third: "third"});});returnmessagesToSend;}catch(error){console.error('Erreur lors de la gestion des messages programmés :',error);thrownewError('Erreur Interne du Serveur');}}asyncfunctionGET(req: NextApiRequest){try{constresponse=awaithandleScheduleMessage();returnNextResponse.json({message: response},{status: 200});}catch(error){console.error('Erreur lors de la gestion de la requête GET :',error);returnNextResponse.json({message: 'Une erreur s\'est produite lors de la gestion de la requête GET.'},{status: 500});}}module.exports={GET};
Expected behavior
If I run this code, the Socket io server don't console.log the received message (because it's probably not received). But if I remove the "third" property in the next api and in the socketio server, the message is displayed in my terminal
The text was updated successfully, but these errors were encountered:
The bug
Hi everyone, my bug is easy to understand. I want to send from my next api a message to a socketIO server running with nodejs.
When I try to send a message including an object with 2 or less properties, it's working. But when I send an object with more than 2 properties, the socketIO server don't receive the message
To Reproduce
"socket.io-client": "^4.7.5" for the nextjs Api
"socket.io": "^4.7.5" for the socketio server
SocketIO server
NEXTJS API
Expected behavior
If I run this code, the Socket io server don't console.log the received message (because it's probably not received). But if I remove the "third" property in the next api and in the socketio server, the message is displayed in my terminal
The text was updated successfully, but these errors were encountered: