project_video_chat icon indicating copy to clipboard operation
project_video_chat copied to clipboard

Unhandled Rejection (TypeError): myVideo.current is undefined

Open wasim2725 opened this issue 2 years ago • 5 comments

C:/Users/mohdw/Desktop/WebRTC/client/src/SocketContext.js:26

.then((currentStream) => { setStream(currentStream);

        myVideo.current.srcObject = currentStream;
    });

wasim2725 avatar Oct 02 '21 18:10 wasim2725

Did you find any solution?

adarsh-chakraborty avatar Apr 30 '22 16:04 adarsh-chakraborty

Don't know if this is still relevant, but this worked for me:

With the default boilerplate generated by create-react-app I had something like this in my index client file

import ReactDOM from 'react-dom/client';
import './styles/index.css';
import App from './App';
import { ContextProvider } from './Context';

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <ContextProvider>
    <App />
  </ContextProvider>
);

I changed this to match the video and turned it into

import ReactDOM from 'react-dom';
import './styles/index.css';
import App from './App';

import { ContextProvider } from './Context';

ReactDOM.render(
  <ContextProvider>
    <App />
  </ContextProvider>,
  document.getElementById('root') as HTMLElement
);

I am absolutely oblivious as to why this fixes the issue, but it did for me.

dynamo58 avatar Jun 17 '22 04:06 dynamo58

I'm currently facing as issue with this. The project isn't working because of this, I've tried multiple ways, but still haven't gotten a better solution.😤

OkezeKingsley avatar Jun 18 '22 14:06 OkezeKingsley

try this, it may help🫥

` useEffect(()=>{

const getMd = async () => {
    const currentStream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
    setStream(currentStream);
    myVideo.current.srcObject = currentStream;
}

(async ()=> await getMd())();
// getMd()

socket.on("me", (id)=> setMe(id))

socket.on("calluser", ({from, name:callerName, signal})=>{
  setCall({isReceiveCall: true, from, name: callerName, signal})
})

}, []); `

gihev72 avatar Nov 09 '22 21:11 gihev72

Ok, I'd get back to you.

On Wed, Nov 9, 2022, 10:47 PM gihev72 @.***> wrote:

try this, it may help🫥

` useEffect(()=>{

const getMd = async () => {

const currentStream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});

setStream(currentStream);

myVideo.current.srcObject = currentStream;

}

(async ()=> await getMd())();

// getMd()

socket.on("me", (id)=> setMe(id))

socket.on("calluser", ({from, name:callerName, signal})=>{

setCall({isReceiveCall: true, from, name: callerName, signal})

})

}, []); `

— Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/project_video_chat/issues/7#issuecomment-1309418996, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDOLURGO3EYYOO4LLPDZETWHQLXTANCNFSM5FGVH53A . You are receiving this because you commented.Message ID: @.***>

OkezeKingsley avatar Nov 11 '22 10:11 OkezeKingsley