Same global context of socket client instance not listening to events from server

I am building a podcast app in which all Rooms are rendered in Rooms.jsx FE_URL/rooms and individual rooms are rendered in Room.jsx in FE_URL/rooms/:roomname

I am using a SocketContext and wrapping it on top of the Component tree.

After user creates a podcast he is redirected to FE_URL/rooms/:roomname where inside of a useEffect function i am emitting room-created event , there is a socket listening to the same event emitted from the server on FE_URL/rooms , the thing is i am not able to log the data on FE_URL/rooms despite the it being successfully emitted from the server , now i know what the problem is , the socket instances in both the URLs are different which is causing the error because when i put the socket listening to room-created in Room.jsx in FE_URL/rooms/:roomname it was receiving the data

Room.jsx

import React, { useEffect, useState, useRef , useContext } from "react";
import { useParams } from "react-router-dom";
import "./Room.css";
import { SocketContext } from "../context/socketContext";
import SimplePeer from "simple-peer";

export const Room = () => {
  const { roomname } = useParams();

  const socket = useContext(SocketContext);



  const [myAudioStream, setMyAudioStream] = useState(null);
  const [peers, setPeers] = useState([]);
  const userAudio = useRef();
  const peersRef = useRef();
  const roomID = roomname;

  useEffect(() => {
    socket.on("connect", () => {
      console.log(socket.id);
    });

    // FIRST JOIN A ROOM AT THE SERVER

    navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
      userAudio.current.srcObject = stream;
      socket.emit("room-created", {
        podcastTopic: window.sessionStorage.getItem("podcastTopic"),
        hostName: window.sessionStorage.getItem("name"),
        hostProfilePic: window.sessionStorage.getItem("profilePic"),
        roomID: roomID,
      });
    });

    return () => {
      socket.off("connect");
    };
  }, []);

  return (
    <div id="Room-Main">
      <div id="Room-Card">
        <div id="Speakers">
          This Will Have Speakers....
          <audio ref={userAudio}></audio>
        </div>
        <div id="Listeners">This Will Have Listeners....</div>
      </div>
    </div>
  );
};

Rooms.jsx

import React, { useEffect, useState, useContext } from "react";
import { SocketContext } from "../context/socketContext";
import "./Rooms.css";

export const Rooms = () => {
  const socket = useContext(SocketContext);
  const [arrayOfLivePodcasts, setArrayOfLivePodcasts] = useState([]);

  useEffect(() => {
    //need to get info on how to reach the host

    console.log("inside useEffect in Rooms.jsx");

    //not being logged
    socket.on("connect", () => {
      console.log(socket.id, "in Rooms.jsx");
    });

    //not being logged
    socket.on("room-created", (data) => {
      console.log(
        `${JSON.stringify(data)} -- listening to room-created  in Rooms.jsx`
      );
      setArrayOfLivePodcasts((prevArrayOfLivePodcasts) => [...prevArrayOfLivePodcasts , data])
    });
  }, []);

  return (
    <div id="Rooms-Main">
      <div id="Rooms-Heading">
        <h1>JOIN ANY ROOM</h1>
      </div>
      <div id="All-Active-Rooms">
        { Array.isArray(arrayOfLivePodcasts) ? arrayOfLivePodcasts.map((podcast) => {
          return (
            <div id="Podcast-Card" key={podcast.roomID}  >
              <div id="HostProfilePic-Div">
                <img
                  src={podcast.hostProfilePic}
                  alt="HostProfilePic"
                  id="HostProfilePic"
                />
              </div>
              <div id="HostName">{podcast.hostName}</div>
              <div id="PodcastTopic">{podcast.podcastTopic}</div>
            </div>
          );
        }) : <div style={{ color: "white"}} >NO PODCASTS LIVE RIGHT NOW... </div> }
      </div>
    </div>
  );
};

socketContext.jsx

import React, { createContext } from "react";
import { io, Socket } from "socket.io-client";

const apiUrl =
  import.meta.env.VITE_ENV === "development"
    ? import.meta.env.VITE_API_DEV
    : import.meta.env.VITE_API_PROD;

const socket = io(apiUrl);
const SocketContext = createContext(socket);

const SocketProvider = ({ children }) => {
  return (
    <SocketContext.Provider value={socket}>{children}</SocketContext.Provider>
  );
};
export { SocketContext, SocketProvider };

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật