opentok / opentok-react

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

Option to mute microphone of the publisher through a button #232

Open prabhat13528 opened 2 years ago

prabhat13528 commented 2 years ago

Currently, I can hover over the video and mute the mic but is there any other way to access the function/method to mute the microphone through a button?

I am using the window.OT.initsession to create the session and the below code is used to create the publisher stream:

this.sessionHelper = createSessionHelper({
      apiKey: session.apiKey,
      sessionId: session.sessionId,
      token: session.token,
      onStreamsUpdated: (streams) => {
        this.setState({ streams });
      },
      onConnect: function () {
        setTimeout(function () {
          const publisherOptions = {
            frameRate: 15,
            resolution: "1280x720",
            showControls: true,
            facingMode: "environment",
            fitMode: "contain",
            height: "100%",
            width: "100%",
            mirror: false,
            publishAudio: me.state.demo,
          };
          me.publisherHelper = new Publisher();
          me.publisherHelper
            .publish(publisherOptions, null, true)
            .then(function publishThen(publisher) {
              me.sessionHelper.session.publish(publisher, me.handleError);
              me.publisher = publisher;
            })
            .catch(me.handleError);
        }, 100);
      },
      onIncomingSignal: function (data) {
        me.handleIncomingSignal(data);
      },
    });

I know that the publishAudio can be used to mute but once the publisher stream has started, changing the state variable it's being assigned to doesn't update the publisher property.

Is there any way to update the publisher property once the stream is published or access the mute method/function outside of the video?