opentok-react icon indicating copy to clipboard operation
opentok-react copied to clipboard

OTPublisher remount issue

Open ber8749 opened this issue 5 years ago • 9 comments

Hello,

I am encountering a number of JavaScript console errors when unmounting, then subsequently remounting the OTPublisher component based on browser device permissions.

I am currently using macOS Mojave v.10.14.6 (18G103) and Chrome Version 76.0.3809.132, however I assume any recent version of Chrome will exhibit this behavior.

Reproduction Steps:

  1. Load up the code below in your favorite dev environment (I'm partial to https://codesandbox.io):
import React from "react";
import ReactDOM from "react-dom";
import { OTSession, OTPublisher } from "opentok-react";

class App extends React.Component {
  state = {
    showPublisher: true
  };

  publisherEventHandlers = {
    accessAllowed: event => {
      console.log('accessAllowed called');
      this.setState({ showPublisher: true });
    },
    accessDialogOpened: event => {
      console.log('accessDialogOpened called');
      this.setState({ showPublisher: false });
    }
  };

  componentDidMount() {
    navigator.mediaDevices.getUserMedia({ 
      audio: true,
      video: true 
    }).then(mediaStream => {
      console.log('getUserMedia resolved', mediaStream);
      this.setState({ showPublisher: true });
    }).catch(error => {
      console.log('getUserMedia error', error);
    });
  }

  render() {
    return (
      <div className="App">
        <h1>OTPublisher Test</h1>
        { this.state.showPublisher ? 
          <OTSession
            apiKey="valid-api-key" 
            sessionId="valid-session-id" 
            token="valid-session-token"
          >
            <OTPublisher 
              eventHandlers={ this.publisherEventHandlers }
            />
          </OTSession>
          :
          <span>Please Grant the Browser Access to your Camera and Microphone</span>
        }
      </div>
    );
  }
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Direct Link to app in CodeSandbox: Edit OTPublisher Mounting Error

  1. Reset your browser camera and microphone permissions to "Ask", by clicking the lock symbol to the left of the web address in the address bar: Screen Shot 2019-10-15 at 4 31 52 PM
  2. Reload your page
  3. "Allow" the page to access your camera and microphone: Screen Shot 2019-10-15 at 4 37 55 PM
  4. Check the JavaScript console for the following errors:
  • OpenTok:Publisher:error onStreamAvailableError Error: Did not pass Error as second argument: function(e,t,n){if(-1===a.indexOf(e))return new Error("Attempt to use invalid error name ("+e+"). Original message: "+t.message);if(!(t instanceof Error||/^\[object .*Error\]$/.test(Object.prototype.toString.call(t))))return new Error("Did not pass Error as second argument: "+t);var r=new o(void 0,t.message);if(r.name=e,!t.stack)try{throw t}catch(e){}return r.stack=t.stack,n&&(r.code=n),i.send(r),r}
  • OpenTok:Publisher:error OT.Publisher State Change Failed: 'Destroyed' cannot transition to 'Failed'
  • OpenTok:Publisher:warn Received connectivity event: "Failure" without "Attempt"
  • OpenTok:GlobalExceptionHandler:error OT.exception :: title: Unable to Publish (1500) msg: GetUserMedia

Any insight or advice on how to avoid these errors would be greatly appreciated.

Thank You!

ber8749 avatar Oct 15 '19 20:10 ber8749

I have the same error, even with a different setup but problably always linked to unmounting the component

ramiel avatar Mar 23 '20 15:03 ramiel

@ber8749 is this still reproducible? I am not able too follow your code.

@ramiel Can you post some code to reproduce the issue please?

cheers

enricop89 avatar Mar 25 '20 10:03 enricop89

I changed the implementation and I have not the error anymore. If I'm able to reproduce it again I'll post some code here

ramiel avatar Mar 25 '20 10:03 ramiel

@ramiel How did you change the implementation? I'm currently experiencing a similar issue where the user is not able to unpublish before disconnecting.

Ganesh-grandy avatar Jun 22 '20 06:06 Ganesh-grandy

@Ganesh-grandy Tokbox support about two months back said the issue is specific to screen sharing with Chrome/Windows, hardware acceleration and high video resolutions but should be fixed with Chrome 82.

I was able to work around the issue setting maxResolution: { width: 1920, height: 1080 } for screen sharing which fixed the issue for me and my users at an acceptable tradeoff.

ttraenkler avatar Jun 22 '20 08:06 ttraenkler

@enricop89 Yes, this is still a reproducible issue for me.

@ttraenkler Did Tokbox support address this issue publicly? If so, can you point me to the page where they addressed this issue?

ber8749 avatar Jun 22 '20 12:06 ber8749

@Ganesh-grandy the point is that I don't know what I changed to make it work. Also, I don't use this anymore, sorry

ramiel avatar Jun 22 '20 13:06 ramiel

@ber8749 No, it's not public but has been a support request of mine. Have you tried maxResolution 1920x1080?

ttraenkler avatar Jun 23 '20 12:06 ttraenkler

@ber8749 I tested the code and, to me, the error is in the implementation. You are mounting/unmounting the OTSession and OTPublisher component a lot of time for nothing. The showPublisher state variable is changed in the publisher events and also in the componentDidMount hook. What's the reason behind this behaviour?

You can achieve the result with this simple app:

import React from "react";
import ReactDOM from "react-dom";
import { OTSession, OTPublisher } from "opentok-react";

export default class App extends React.Component {
    state = {
        showPublisher: true
    };

    publisherEventHandlers = {
        accessAllowed: event => {
            console.log('accessAllowed called');
        },
        accessDialogOpened: event => {
            console.log('accessDialogOpened called');
        }
    };

    componentDidMount() {
        
    }

    render() {
        const { apiKey, sessionId, token } = this.props.credentials;
        return (
            <div className="App">
                <h1>OTPublisher Test</h1>
                {this.state.showPublisher ?
                    <OTSession
                        apiKey=""
                        sessionId=""
                        token=""
                    >
                        <OTPublisher
                            eventHandlers={this.publisherEventHandlers}
                        />
                    </OTSession>
                    :
                    <span>Please Grant the Browser Access to your Camera and Microphone</span>
                }
            </div>
        );
    }
}


enricop89 avatar Jun 24 '20 14:06 enricop89