opentok / opentok-react

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

OTPublisher remount issue #80

Open ber8749 opened 5 years ago

ber8749 commented 5 years ago

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 (

OTPublisher Test

{ this.state.showPublisher ? : Please Grant the Browser Access to your Camera and Microphone }
);

} }

const rootElement = document.getElementById("root"); ReactDOM.render(, rootElement);


Direct Link to app in CodeSandbox:
[![Edit OTPublisher Mounting Error](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/otpublisher-mounting-error-1fkb8?fontsize=14&hidenavigation=1&theme=dark)

2. 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](https://user-images.githubusercontent.com/2344085/66867729-ea1ec380-ef69-11e9-8172-2f781d9f25c8.png)
3. Reload your page
4. "Allow" the page to access your camera and microphone:
![Screen Shot 2019-10-15 at 4 37 55 PM](https://user-images.githubusercontent.com/2344085/66867869-2fdb8c00-ef6a-11e9-89ae-2c50155b7667.png)
5. 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!
ramiel commented 4 years ago

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

enricop89 commented 4 years ago

@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

ramiel commented 4 years ago

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

Ganesh-grandy commented 4 years ago

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

ttraenkler commented 4 years ago

@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.

ber8749 commented 4 years ago

@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?

ramiel commented 4 years ago

@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

ttraenkler commented 4 years ago

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

enricop89 commented 4 years ago

@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>
        );
    }
}