diegogurgel/react-webrtc

Changing input and output device functions

Karthikdb opened this issue · 8 comments

I am trying to change the IP and OP devices by deviceid but its not reflecting to the client
@diegogurgel can u add a function for that

changedevice(videoinput,audioinput) {
  this.setState({
  videoinput:videoinput,
  audioinput:audioinput
  });
  alert(this.state.videoinput);

  console.log(this.state.videoinput,this.state.audioinput);
      const op = {
        video: {
          width: { min: 160, ideal: 640, max: 1280 },
          height: { min: 170, ideal: 360, max: 720 },
          facingMode:this.state.videoinput
          
        },
        audio:{echoCancellation: true,
          deviceId: this.state.audioinput} 
      };
      navigator.getUserMedia(
        op,
        stream => {
      
          stream.oninactive = () => {
            Object.keys(this.state.peers).forEach((key)=>{
              this.state.peers[key].removeStream(this.state.localStream);
            })
            this.getUserMedia().then(() => {
              Object.keys(this.state.peers).forEach((key)=>{
                this.state.peers[key].addStream(this.state.localStream);
              })
            });
          };
          this.setState({ streamUrl: stream, localStream: stream });
          this.localVideo.srcObject = stream;
          Object.keys(this.state.peers).forEach((key)=>{
            this.state.peers[key].addStream(this.state.localStream);
          })
        
        },
        () => { }
      );

    
    }

This is what I am trying but the video is getting an update. What is wrong with this code?? @diegogurgel @kevinjpuscan

Could you please help me with this?? @diegogurgel @kevinjpuscan

Are you saying that you have multiple devices connected to the computer and want to select them? Did I get it right?

Yeah I am trying on smart phone also I can't switch between front and rear camera

Do u have any solution?? @diegogurgel

Maybe this piece of code can help you with selecting different sources https://github.com/samdutton/simpl/blob/gh-pages/getusermedia/sources/js/main.js

This is basically listing all devices available setting one as a source when you select.

I can get the stream by device Id but i cannot set that to localstream and also not able to peer

I can get the stream by device Id but i cannot set that to localstream and also not able to peer

Solved !!