News Articles socket.io

TypeError: Cannot read properties of null (reading ’emit’)

import { io } from "socket.io-client"; import { useState, useEffect } from "react"; const Game = () => { const [socket, setSocket] = useState(null); const [name, setName] = useState(""); const [room, setRoom] = useState(""); useEffect(() => { setSocket(io(process.env.REACT_APP_BASE_URL)); return () => { socket.emit("disconnect"); }; }, [socket]); const sendMessage = () => { socket.emit("room1", { name, […]

How can I sset react state with response coming from socket.on as Promise?

I’m working on a chat app using NestJs as backend and React as frontend with socket.io. I would like to send ‘conversations’ to frontend with socket. On the backend part : chat.service.ts: getConversationsForCompany(companyId: number){ const conversations = this.conversationsRepository.find({ where: {company: companyId}, order: {lastUpdated: "ASC"}, relations: [‘user’,’company’,’companyMessages’,’userMessages’] }); if(conversations) { return conversations; } throw new WsException(‘No […]

Can’t get the value of a function inside an object using socketIO with redux-toolkit

I am using redux toolkit with socket io but can’t get the value return from the server. I try to assign the value into the res Array but the array length is still 0 let res = [] socket.emit("users") socket.on("users", (users) => { res.concat(users) users.forEach(user => { const { username, userID} = user res.push({ username: […]

Check if user clicks on client besides them

I’m trying to detect if a user clicks on a client besides them. If you try the project (https://multiplayer-movement.stcollier.repl.co/) and open the console, (move with arrow keys) if you click on yourself, the console returns true but this doesn’t work with if you click on any other client. Here’s my JavaScript: var socket = io(); […]

My socket.io set up with express not working

I have an express app running, and I wanted to add socket.io for real time features. So I followed the get started on socket.io. But somehow it is not working. Thanks ! const express = require(‘express’); const app = express(); const http = require(‘http’); const server = http.createServer(app); const { Server } = require("socket.io"); const […]

Uncaught Error: The error you provided does not contain a stack trace. | React JS | NodeJS

I am trying to make a group video call app with the help of a youtube tutorial. I am using react and socket io, But somehow its giving me the above error. Can’t understand what exactly I am doing wrong. Kindly correct me. Attaching the code for reference: Create room page- The homepage import React […]

Blob video stream not showing on iOS when receiving a stream from socket.io (JavaScript and Node.js)

This works perfectly fine on android (every part of it). But when I receive a video stream wrapped in a blob on iOS from android or another iOS device, it does not show any sign of loading the video or displaying it. However, when I show my own video to myself on iOS, it works. […]

person to person video calling chat app in react js,socket/webrtc and firebase [closed]

I am building a person to person video calling chat app based on login system .In this is project, there is a list of users. If I call someone ,then it should go to the browser/device where the user is login .How to send the call request and receive the request. If a user is […]

cannot connect react to socket io server

I wrote a simple hook to connect react and socket.io: import io from ‘socket.io-client’ import { useEffect, useRef } from ‘react’ import { v1 as uuid } from ‘uuid’; import { useParams } from "react-router-dom"; const SERVER_URL = ‘http://localhost:3001’ export const useSocketConnection = () => { const { gameId } = useParams() const userId = […]

reactjs nodejs socketio works in localhost but not when deployed

Posting after much searching, couldn’t figure this out: Below is a working scenario in localhost. The console.log(socketRes) prints a valid socket with socket id. client: useEffect(() => { console.log("setting socket"); const socketRes = io("http://localhost:8700/"); console.log(socketRes); setSocketio(socketRes); return (() => { console.log("socket off"); return socketRes.off; }); }, []); When deployed in a server, it doesnt seem […]

SwiftUI SocketIO will not emit event on backend?

I am unable to send an event to my backend using SocketIO after I have successfully connected to my backend. I cannot figure out why when I emit a "userSearch" event that it is not registering on the backend? At the moment I am only trying to send & log "TEST" on the backend but […]

socket.io in mern app weird error/not error?

I really don’t know and couldn’t find what the problem is. When I open the chat section first and try to send a message, the message itself is saved in the database but it didn’t work synchronously e.g the message don’t show up however after I save the codes related, i mean codes of pages […]

400 error socket.io when trying to connect from client side

I am setting up a little chat feature with socket.io for some reason when I try to connect from client I am getting this error I am initiating my connection in a chatProvider component in a react app. Here is the client side connection function import React, { useState, useEffect} from ‘react’; import io from […]

How do I display the other user’s avatar underneath my message, in real time using socket.io?

Whenever a user opens a chat window, he/she marks any unread messages as read. I’m keeping track of the latest message read by the recipient to display the recipient’s avatar underneath it. I’m achieving this so far, but not in real time. I’ve never worked with sockets or socket.io. Most of the code below was […]

does socket.io server need to be seperate from backend when deploying?

I am building react app. I have my client folder, and my backend folder that contains all my mongo db models, routes, functions etc… I know realize that my app needs to use socket.io My frontend is on localhost:3000 and my backend is on localhost:5000 My understanding is that socket.io needs its own port. Does […]

Node js with express and socket.io -can’t fint socket.io.js

So basically what i am trying to do is build a chat app with a login system but for some reason i cant put it together and i am getting an error when i join to the room the chat.hbs can’t find the socket.io.js file and also the main.js is getting a reference error with […]

React Context doesn’t update inside ReactContext file

I was trying to read UsersState when I got an emmit from socketio. But when I got emmit from socketio, the users state is null. I have a component called AddUser.js, this component is for adding user values to UserState. When I’m using react dev tools chrome, I can see the UsersState value is updated […]

How to make Socket.io work with a CapacitorJS native app?

How do you make Socket.io work with a CapacitorJS native app for iOS or Android (even on emulators)? Source: JavaSript – Stack Overflow

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.