diegogurgel / react-webrtc

Video chat using webRTC and react
https://react-webrtc-example.herokuapp.com
260 stars 75 forks source link

Changing input and output device functions #19

Closed Karthikdb closed 4 years ago

Karthikdb commented 4 years ago

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

Karthikdb commented 4 years ago
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

Karthikdb commented 4 years ago

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

diegogurgel commented 4 years ago

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

Karthikdb commented 4 years ago

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

Karthikdb commented 4 years ago

Do u have any solution?? @diegogurgel

diegogurgel commented 4 years ago

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.

Karthikdb commented 4 years ago

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

Karthikdb commented 4 years ago

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

Solved !!