How to store or add data in socket object?

I have a socket id based on this I need to get user details. So can I store user details in the socket object? How can I add user details in the socket object? Here, I can store this socket id in Database but I need to update it every time when a user connects… Read More How to store or add data in socket object?

Socket.io data spamming the console until the Payload is too large

The following code is part of a chat application build with react native which is working via a socket.io server. const Message = ({text, isSent}) => { return ( <View style={[styles.messageContainer, isSent ? styles.sentMessage : styles.receivedMessage]}> <Text style={styles.messageText}>{text}</Text> </View> ) } export const ChatScreen = ({ route }) => { const {control, handleSubmit, reset} =… Read More Socket.io data spamming the console until the Payload is too large

socket.io remove object from array and ensure array update correctly if function ran twice the same time

I need to remove an object from an array. The issue is that there could be a case where this function is ran at the same time. In that case how can I ensure the array is updated correctly as the function my be called by two different users the same time const rooms =… Read More socket.io remove object from array and ensure array update correctly if function ran twice the same time

Socket event is resetting state array in react

On server side I have this nodejs app: io.use((socket, next) => { socket.name = socket.handshake.headers.name; socket.room = socket.handshake.headers.room; socket.user_id = socket.handshake.headers.user_id; return next(); }); let all_sockets = []; io.on("connection", (socket) => { const ob = { id: socket.id, room: socket.room, name: socket.name, user_id: socket.user_id }; all_sockets = all_sockets.filter(el => el.user_id !== socket.user_id); all_sockets.push(ob); socket.on("message", (data)… Read More Socket event is resetting state array in react

How do I send a nested list/array through socket.emit()

The code is: //i want to send this matrix across to server const [matrix, setMatrix] = useState([ [”, ”, ”], [”, ”, ”], [”, ”, ”], ]); //fn handler whr matrix is sent to server through socket.emit const updateGameMatrix = (column, row, symbol) => { const newMatrix = […matrix]; if (newMatrix[row][column] === "" || newMatrix[row][column]… Read More How do I send a nested list/array through socket.emit()

socket.io origin set but anyways getting errors

i’m making a website for a school project where there is a live updating table with data about how many rounds player have ran. It’s almost done, but i’m getting one error, i can’t solve: ccess to XMLHttpRequest at ‘https://creeperhd.de:8443/socket.io/?EIO=4&transport=polling&t=O88eQ0_&#8217; from origin ‘https://creeperhd.de&#8217; has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on… Read More socket.io origin set but anyways getting errors

Trying to figure out how to use socket.io the correct way in a useEffect that is using an axios get request to fetch messages

So far i’m stuck on my useEffect that fetches all the current messages and renders the state accordingly. as of right now it doesn’t render the new state until page is refreshed. const Home = ({ user, logout }) => { const history = useHistory(); const socket = useContext(SocketContext); const [conversations, setConversations] = useState([]); const… Read More Trying to figure out how to use socket.io the correct way in a useEffect that is using an axios get request to fetch messages