React Api Reference
    Preparing search index...

    Class useParticipant

    useParticipant provides reactive access to a participant’s state, streams, controls, statistics, and related events within a meeting.

    Index
    displayName: string

    This represents display name of the participant.

    isActiveSpeaker: boolean

    This represents whether the participant is the active speaker.

    isLocal: boolean

    This represents whether the participant is the local participant.

    isMainParticipant: boolean

    This represents whether the participant is the main participant.

    micOn: boolean

    This represents whether the participant’s microphone is enabled.

    micStream: Stream

    This represents the microphone audio Stream of the participant.

    mode: "SEND_AND_RECV" | "SIGNALLING_ONLY" | "RECV_ONLY"

    This represents the current mode of the participant.

    participant: Participant

    This represents the underlying Participant instance.

    pinState: any

    This represents the current pin state of the participant.

    screenShareAudioOn: boolean

    This represents whether the participant’s screen-share audio is enabled.

    screenShareAudioStream: Stream

    This represents the screen-share audio Stream of the participant.

    screenShareOn: boolean

    This represents whether the participant is currently sharing their screen.

    screenShareStream: Stream

    This represents the screen-share video Stream of the participant.

    webcamOn: boolean

    This represents whether the participant’s webcam is enabled.

    webcamStream: Stream

    This represents the webcam video Stream of the participant.

      • This method can be used to capture an image from the participant’s current video stream.
      • The captured image is returned as a Base64-encoded string.

      Parameters

      • options: { height?: number; width?: number }
        • Optionalheight?: number

          Desired height of the captured image.

        • Optionalwidth?: number

          Desired width of the captured image.

      Returns Promise<string>

      A Base64-encoded string representing the captured image.

      • Errors.ERROR_CAPTURE_IMAGE_FAILED — the image could not be captured. This happens when the participant's webcam is off, the video is not playing, the webcam is turned off during the capture, or the video does not load in time. The error message describes the cause.
      const { captureImage } = useParticipant(participantId);

      async function grabImage() {
      try {
      const image = await captureImage({
      width: 640,
      height: 360,
      });
      } catch (err) {
      console.log("captureImage failed", err);
      }
      }
      • This method can be used to get detailed statistics about the participant’s audio stream.
      • These metrics provide insights into stream quality, network conditions, and transmission performance at the time the method is called.

      Returns Promise<
          {
              bitrate: number;
              codec: string;
              jitter: number;
              network: string;
              packetsLost: number;
              rtt: number;
              totalPackets: number;
          }[],
      >

      An array of objects containing the following metrics:

      • jitter – Represents variation in packet arrival time (stream instability).
      • bitrate – The bitrate at which the audio stream is being transmitted.
      • totalPackets – Total number of packets transmitted for the stream.
      • packetsLost – Total number of packets lost during transmission.
      • rtt – Round-trip time (in milliseconds) between the client and server.
      • codec – Codec used for encoding the audio stream.
      • network – Network type used for transmitting the stream.

      Info

      If the rtt value exceeds 300ms, consider switching to a region closer to the user for improved performance. Learn more visit here.

      const { getAudioStats } = useParticipant(participantId);

      async function fetchAudioStats() {
      try {
      const audioStats = await getAudioStats();
      } catch (err) {
      console.log("getAudioStats failed", err);
      }
      }
      • This method can be used to get detailed statistics about the participant’s screen share audio stream.
      • These metrics provide insights into stream quality, network conditions, and transmission performance at the time the method is called.

      Returns Promise<
          {
              bitrate: number;
              codec: string;
              jitter: number;
              network: string;
              packetsLost: number;
              rtt: number;
              totalPackets: number;
          }[],
      >

      An array of objects containing the following metrics:

      • jitter – Represents variation in packet arrival time (stream instability).
      • bitrate – The bitrate at which the audio stream is being transmitted.
      • totalPackets – Total number of packets transmitted for the stream.
      • packetsLost – Total number of packets lost during transmission.
      • rtt – Round-trip time (in milliseconds) between the client and server.
      • codec – Codec used for encoding the audio stream.
      • network – Network type used for transmitting the stream.

      Info

      If the rtt value exceeds 300ms, consider switching to a region closer to the user for improved performance. Learn more visit here.

      const { getShareAudioStats } = useParticipant(participantId);

      async function fetchShareAudioStats() {
      try {
      const shareAudioStats = await getShareAudioStats();
      } catch (err) {
      console.log("getShareAudioStats failed", err);
      }
      }
      • This method can be used to get detailed statistics about the participant’s screen share video stream.
      • These metrics provide insights into stream quality, network conditions, and transmission performance at the time the method is called.

      Returns Promise<
          {
              bitrate: number;
              codec: string;
              currentSpatialLayer: number;
              currentTemporalLayer: number;
              jitter: number;
              limitation: any;
              network: string;
              packetsLost: number;
              preferredSpatialLayer: number;
              preferredTemporalLayer: number;
              rtt: number;
              size: any;
              totalPackets: number;
          }[],
      >

      An array of objects containing the following metrics:

      • jitter – Represents variation in packet arrival time (stream instability).
      • bitrate – The bitrate at which the video stream is being transmitted.
      • totalPackets – Total number of packets transmitted for the stream.
      • packetsLost – Total number of packets lost during transmission.
      • rtt – Round-trip time (in milliseconds) between the client and server.
      • codec – Codec used for encoding the video stream.
      • network – Network type used for transmitting the stream.
      • limitation – Indicates any limitations affecting stream quality.
      • size – Resolution or size information related to the stream.

      Info

      If the rtt value exceeds 300ms, consider switching to a region closer to the user for improved performance. Learn more visit here.

      const { getShareStats } = useParticipant(participantId);

      async function fetchShareStats() {
      try {
      const shareStats = await getShareStats();
      } catch (err) {
      console.log("getShareStats failed", err);
      }
      }
      • This method can be used to get the transport-level statistics for this participant.
      • These metrics provide an overview of the total bandwidth and bytes transferred for sending and receiving media at the transport layer.

      Returns Promise<
          {
              receive: { incomingBitrate: number; totalReceivedBytes: number };
              send: { outgoingBitrate: number; totalSentBytes: number };
          },
      >

      An object with two nested objects, or null:

      • send.outgoingBitrate – The total outgoing bitrate (in kbps) across all media streams sent by this participant. Returns 0 or null when the value is unavailable.
      • send.totalSentBytes – The total number of bytes sent by this participant across all media streams. Returns 0 or null when the value is unavailable.
      • receive.incomingBitrate – The total incoming bitrate (in kbps) across all media streams received by this participant. Returns 0 or null when the value is unavailable.
      • receive.totalReceivedBytes – The total number of bytes received by this participant across all media streams. Returns 0 or null when the value is unavailable.
      const { getTransportStats } = useParticipant(participantId);

      async function fetchTransportStats() {
      try {
      const transportStats = await getTransportStats();
      } catch (err) {
      console.log("getTransportStats failed", err);
      }
      }
      • This method can be used to get detailed statistics about the participant’s video stream.
      • These metrics provide insights into stream quality, network conditions, and transmission performance at the time the method is called.

      Returns Promise<
          {
              bitrate: number;
              codec: string;
              currentSpatialLayer: number;
              currentTemporalLayer: number;
              jitter: number;
              limitation: any;
              network: string;
              packetsLost: number;
              preferredSpatialLayer: number;
              preferredTemporalLayer: number;
              rtt: number;
              size: any;
              totalPackets: number;
          }[],
      >

      An array of objects containing the following metrics:

      • jitter – Represents variation in packet arrival time (stream instability).
      • bitrate – The bitrate at which the video stream is being transmitted.
      • totalPackets – Total number of packets transmitted for the stream.
      • packetsLost – Total number of packets lost during transmission.
      • rtt – Round-trip time (in milliseconds) between the client and server.
      • codec – Codec used for encoding the video stream.
      • network – Network type used for transmitting the stream.
      • limitation – Indicates any limitations affecting stream quality.
      • size – Resolution or size information related to the stream.

      Info

      If the rtt value exceeds 300ms, consider switching to a region closer to the user for improved performance. Learn more visit here.

      const { getVideoStats } = useParticipant(participantId);

      async function fetchVideoStats() {
      try {
      const videoStats = await getVideoStats();
      } catch (err) {
      console.log("getVideoStats failed", err);
      }
      }
      • This method can be used to pin the participant’s camera, screen share, or both.

      • Every participant receives a onPinStateChanged event when the pin state is updated.

      Parameters

      • type: "SHARE_AND_CAM" | "CAM" | "SHARE"

        Specifies which stream to pin.

        Allowed values:

        • "SHARE_AND_CAM" – Pins both screen share and camera streams.
        • "CAM" – Pins only the camera stream.
        • "SHARE" – Pins only the screen-share stream.
        SHARE_AND_CAM
        

      Returns Promise<void>

      const { pin } = useParticipant(participantId);

      async function pinCamera() {
      try {
      await pin("CAM");
      } catch (err) {
      console.log("pin failed", err);
      }
      }
      • This method can be used to adjust the video quality of the remote participant based on the specified viewport dimensions.

      Parameters

      • width: number

        The width of the viewport used to determine the video quality.

      • height: number

        The height of the viewport used to determine the video quality.

      Returns void

      const { setViewPort } = useParticipant(participantId);

      setViewPort(480, 360);
      • This method can be used to unpin the participant’s camera, screen share, or both.

      • Every participant receives a onPinStateChanged event when the pin state is updated.

      Parameters

      • type: "SHARE_AND_CAM" | "CAM" | "SHARE"

        Specifies which stream to unpin.

        Allowed values:

        • "SHARE_AND_CAM" – Unpins both screen share and camera streams.
        • "CAM" – Unpins only the camera stream.
        • "SHARE" – Unpins only the screen-share stream.
        "SHARE_AND_CAM"
        

      Returns Promise<void>

      const { unpin } = useParticipant(participantId);

      async function unpinCamera() {
      try {
      await unpin("CAM");
      } catch (err) {
      console.log("unpin failed", err);
      }
      }
    • Triggered when the media status of a participant changes (for example, when audio or video is enabled or disabled).

      Parameters

      • data: { kind: "audio" | "video" | "share" | "shareAudio"; newStatus: boolean }
        • kind: "audio" | "video" | "share" | "shareAudio"

          Type of stream whose status changed.

        • newStatus: boolean

          The updated status of the stream.

      Returns void

      function onMediaStatusChanged(data) {
      const { kind, newStatus} = data;
      }

      const {
      displayName
      ...
      } = useParticipant(participantId,{
      onMediaStatusChanged,
      ...
      });
    • Triggered when a participant’s audio, video, or screen-share stream is disabled.

      Parameters

      • stream: Stream

        The Stream that was disabled.

      Returns void

      function onStreamDisabled(stream) {
      console.log("onStreamDisabled", stream);
      }

      const {
      displayName
      ...
      } = useParticipant(participantId,{
      onStreamDisabled,
      ...
      });
    • Triggered when a participant’s audio, video, or screen-share stream is enabled.

      Parameters

      • stream: Stream

        The Stream that was enabled.

      Returns void

      function onStreamEnabled(stream) {
      console.log("onStreamEnabled", stream);
      }

      const {
      displayName
      ...
      } = useParticipant(participantId,{
      onStreamEnabled,
      ...
      });
      • Triggered when a participant’s video, audio, or screen-share stream is paused.

      • This event is triggered only when the Subscription Manager is enabled by calling the enableAdaptiveSubscription() method.

      Parameters

      • data: { kind: "video"; reason: string }
        • kind: "video"

          Type of stream that was paused.

        • reason: string

          Reason why the stream was paused.

          Possible values:

          • "muted" – Stream was paused because it was muted.
          • "leastDominance" – Stream was paused due to bandwidth or dominance rules.

      Returns void

      function onStreamPaused({ kind, reason }) {
      console.log(kind, reason);
      }

      const {
      displayName
      ...
      } = useParticipant(participantId,{
      onStreamPaused,
      ...
      });
      • Triggered when a participant’s video, audio, or screen-share stream is resumed.

      • This event is triggered only when the Subscription Manager is enabled by calling the enableAdaptiveSubscription() method.

      Parameters

      • data: { kind: "video"; reason: string }
        • kind: "video"

          Type of stream that was resumed.

        • reason: string

          Reason why the stream was resumed.

          Possible values:

          • "adaptiveSubscriptionsDisabled" – Stream resumed after adaptive subscriptions were disabled.
          • "networkStable" – Stream resumed due to stable network conditions.

      Returns void

      function onStreamResumed({ kind, reason }) {
      console.log(kind, reason);
      }

      const {
      displayName
      ...
      } = useParticipant(participantId,{
      onStreamResumed,
      ...
      });
      • Triggered when the video quality of a participant changes.

      • The currentQuality and prevQuality values can be HIGH, MEDIUM, or LOW.

      Parameters

      • data: { currentQuality: "low" | "med" | "high"; prevQuality: "low" | "med" | "high" }
        • currentQuality: "low" | "med" | "high"

          The updated video quality level.

        • prevQuality: "low" | "med" | "high"

          The previous video quality level.

      Returns void

      function onVideoQualityChanged(data) {
      const { currentQuality, prevQuality } = data;
      }

      const {
      displayName
      ...
      } = useParticipant(participantId,{
      onVideoQualityChanged,
      ...
      });