opentok / opentok-react-native

OpenTok React Native - a library for OpenTok iOS and Android SDKs
https://tokbox.com/
MIT License
210 stars 155 forks source link

Separate session connection and Publish,Subscribe timing. #582

Closed kazama-wip closed 1 month ago

kazama-wip commented 2 years ago

Feature Request

Description

We want to mount each item at any given time. Currently implementation with the code below is not possible and will result in an error.

       <OTSession
          apiKey={apiKey}
          sessionId={sessionId}
          token={token}
          eventHandlers={sessionEventHandlers}
          >
          {status === 'AcceptCall' && (
            <>
              <OTPublisher
                eventHandlers={OTPublisherEventHandlers}
                properties={{
                  videoTrack: false,
                  audioTrack: true,
                  publishVideo: false,
                  publishAudio: true,
                  audioFallbackEnabled: true
                }}
              />
              <OTSubscriber
                properties={{
                  subscribeToVideo: false,
                  subscribeToAudio: true
                }}
              />
            </>
          )}
        </OTSession>

`` Warning: Failed prop type: Invalid prop `children` supplied to `OTSession`. ``

The only way to achieve accurate call functionality is to subscribe to the call status on another server or to cancel or terminate the call by specifying the number of seconds.

Also, the current documentation, which does not explain these features, caused me a lot of trouble when implementing basic call features such as accepting and rejecting calls.

Please let me know if this is a rudimentary question or if I'm doing something wrong.

enricop89 commented 2 years ago

Why do you need to only connect and not publish or subscribe? Can you elaborate your use case please?

kazama-wip commented 2 years ago

Thanks for the reply.

The only way to achieve accurate call functionality is to subscribe to the call status on another server or to cancel or terminate the call by specifying the number of seconds.

One of the basic functions of a call is that the party initiating the call may wish to cancel it for some reason. In such a case, the party receiving the incoming call will receive this information.

jeffswartz commented 1 month ago

Try using a ternary:

  {status === 'AcceptCall' ? (
    <>
      <OTPublisher
        eventHandlers={OTPublisherEventHandlers}
        properties={{
          videoTrack: false,
          audioTrack: true,
          publishVideo: false,
          publishAudio: true,
          audioFallbackEnabled: true
        }}
      />
      <OTSubscriber
        properties={{
          subscribeToVideo: false,
          subscribeToAudio: true
        }}
      />
    </>
  ) : (
    <></>
  )}

Also, you can conditionally render subscribers. See https://tokbox.com/developer/guides/subscribe-stream/react-native/#custom_rendering.