GithubHelp home page GithubHelp logo

Comments (3)

aiham avatar aiham commented on July 29, 2024

Hi @mattwebdev, thanks for your interest in opentok-react!

That depends what you mean by 'Endcall'. Would you like to disconnect the session or stop publishing to the session while keeping the session connected? Remaining connected to the session allows the user to continue viewing other people's videos.

To unpublish your video but remain connected, use the following example. The key thing to note is the OTPublisher component is completely unmounted, triggering session.unpublish() in the process:

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isPublishing: true
    };
  }

  togglePublish = () => {
    this.setState({ isPublishing: !this.state.isPublishing });
  };
  
  render() {
    const { isPublishing } = this.state;
    return (
      <OTSession
        apiKey={this.props.apiKey}
        sessionId={this.props.sessionId}
        token={this.props.token}
      >
        <div>
          <button onClick={this.togglePublish}>{isPublishing ? 'Stop' : 'Start'} Publishing</button>
        </div>
        {isPublishing ? <OTPublisher /> : null}
      </OTSession>
    );
  }
}

You could do the same with OTSession, don't render it at all after the End Call button is pressed, but I appreciate that might be undesirable if a lot of the UI within OTSession needs to remain on screen even after ending the call. If you need to disconnect but keep OTSession on the screen, you could do this:

class App extends React.Component {
  endCall = () => {
    this.otSession.destroySession();
  };

  render() {
    return (
      <OTSession
        apiKey={this.props.apiKey}
        sessionId={this.props.sessionId}
        token={this.props.token}
        ref={instance => (this.otSession = instance)}
      >
        <div>
          <button onClick={this.endCall}>End Call</button>
        </div>
        <OTPublisher />
      </OTSession>
    );
  }
}

This gets the instance of the OTSession component and invokes an undocumented destroySession() function. The problem with this is there's no convenient way to start the call again. You will have make sure OTSession gets remounted, because that's where the connect logic is.

I think I'll make this use case a little easier in the future.

from opentok-react.

mattwebdev avatar mattwebdev commented on July 29, 2024

Thanks for your help! i will give this a shot and see.

from opentok-react.

mattwebdev avatar mattwebdev commented on July 29, 2024

that absolutely worked!
thanks!

from opentok-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.