opentok / opentok-react

React components for OpenTok.js
https://www.npmjs.com/package/opentok-react
MIT License
107 stars 105 forks source link

cycleVideo OT_HARDWARE_UNAVAILABLE #55

Closed julien-meichelbeck closed 5 years ago

julien-meichelbeck commented 5 years ago

Sometimes, when calling cycleVideo, the OTPublisher unmounts and an error is thrown.

Example:

<>
  <OTPublisher
    eventHandlers={{
      streamCreated: event => {
        this.publisher = event.target
      },
    }}
  />
  <button
    onClick={event => {
      event.preventDefault()
      if (this.publisher) this.publisher.cycleVideo()
    }}
  >
    Switch camera
  </button>
</>

Error :

OpenTok:Publisher:error onStreamAvailableError OT_HARDWARE_UNAVAILABLE: The selected voice or video devices are unavailable. Verify that the chosen devices are not in use by another application. (getUserMedia error: NotReadableError)
OpenTok:Publisher:warn Received connectivity event: "Failure" without "Attempt"
OpenTok:GlobalExceptionHandler:error OT.exception :: title: Unable to Publish (1500) msg: GetUserMedia

This issue can be seen on Android and iOS.

msach22 commented 5 years ago

@julien-meichelbeck The cycleVideo method returns a promise so I recommend checking to see if the promise resolves or rejects. Please make sure you are running this on a device with multiple cameras. I also recommend using the ref prop to get access to the publisher. You can the getPublisher method of the OTPublisher component to get the publisher object like so:

class MyComponent extends Component {
  constructor(props) {
    super(props);
    this.otPublisher = React.createRef();
  }
  cycleVideo = () => { 
   if (this.otPublisher) { 
    publisher = this.otPublisher.current.getPublisher();
    publisher.cycleVideo().then().catch() // implement custom logic here
   } 
  } 
  render() {
    return ( 
      <div>
        <OTPublisher ref={this.otPublisher} />;
        <button onClick={this.cycleVideo}> Cycle Video </button>
      </div>
    )
  }
}
julien-meichelbeck commented 5 years ago

Hello, thank you for your answer.

returns a promise so I recommend checking to see if the promise resolves or rejects.

Yes, sure we can handle the promise, but it will not fix the issue.

Please make sure you are running this on a device with multiple cameras.

Yes, this button is only displayed if there is more than one video device (following a navigator.mediaDevices.enumerateDevices call).

I also recommend using the ref prop to get access to the publisher.

Thanks, this is looks better, but it doesn't actually fix anything, right ?

msach22 commented 5 years ago

@julien-meichelbeck I believe the team had an offline chat with you about this and it was related to a specific device. I'm going to go ahead and close the issue, but please feel free to re-open if the issue still persists.

satyanarayanaAmzur commented 4 years ago

this issue was not closed brother msach22,still there are some glitches are pending like you know when we got and error from publisher.cycleVideo(),the current ot-publisher was gots disturbed and disappeared,if you some able to provide a solution if the promise returns catch block error then we are able use the current camera and providing some alert to user other device was being busy like wise ,if any dude implemented please do help me on this situation ,hope brother msach22 respond back with good solution for this,thanks in advance

msach22 commented 4 years ago

@satyanarayanaAmzur If I understand correctly, you're saying that there's a glitch in the publisher even when there's an OT_HARDWARE_UNAVAILABLE error?

satyanarayanaAmzur commented 4 years ago

yes bro it was disappeared when we got an error,i mean the communication with current publisher was disturbed and publisher window was hidden from room

bjrb20 commented 4 years ago

Sorry to revive this but I'm having the same issue with a oneplus 7 pro.

WhatsApp Image 2020-04-02 at 14 13 50

When i call cycleVideo I get this error, but for some reason on this demo site https://opentokdemo.tokbox.com/ it works without any problems.

kulttuuri commented 4 years ago

Same error here on Galaxy A40 when trying to use cycleVideo. Works well on my iPhone. Could this be of any fix here?

kulttuuri commented 4 years ago

FYI; It seems like by calling stream.getTracks().forEach(track => track.stop()); before changing video device (aka. calling cycleDevice()) it prevented the error and is now working :)

Can you confirm @BenRedmondBenham

enricop89 commented 4 years ago

Hi guys, I tried to reproduce using "@opentok/client": "^2.17.0" and "opentok-react": "0.10.0" and is working perfectly.

I am using VDF 900 phone with Android 6.0.1 and Chrome 80

@kulttuuri can you share the library version you're using?

kulttuuri commented 4 years ago

I am using 2.17.0. I also tried with 2.15.0 to see if that is the problem. I believe that the issue only arises on some Android devices as the linked PR commit states.

enricop89 commented 4 years ago

@kulttuuri would mind trying on https://opentokdemo.tokbox.com/ with your Galaxy A40? 👍

warren32 commented 4 years ago

Galaxy S20+ cycle video fails on the demo https://opentok.github.io/opentok-web-samples/Publish-Devices/ it also fails https://opentokdemo.tokbox.com/

kulttuuri commented 4 years ago

@enricop89 Weird - Now both demos worked on my Android, I am certain that they did not in the last week.

weshamoh commented 4 years ago

am almost giving up on this ..am trying to pass the session,so that subscriber can also view ,but i dont seem to get it am kinda of new am learning

janosvajda commented 4 years ago

Hi, there is the same issue if we use Tokbox in Electron.js app on Mac. We use the 2.17.7 version of Tokbox JS API.

gbrocha commented 3 years ago

Same issue here