Skip to content

I can't get the tracks actual mute state #1391

Description

@iozgurkaplan

Describe the problem

When I mute a user from backend by updating permissions, I can't get their actual mute state.
Because in this code "publication" becomes undefined.

const trackMicPub = {
participant: participant,
publication: micPub,
source: Track.Source.Microphone
}
participant: ....,
publication:undefined,
source: "microphone"

if I don't connect a microphone it is also undefined. Therefore, I can't distinguish wheter the device is not connected or user doesn't have permission to publish. I looked for hooks but I couldn't find a hook to distinguish.

Describe the proposed solution

I wrote this but I am not sure if this is a good aproach or is there better alternative exists.

import { TrackSource } from '@livekit/protocol';
import { useParticipantPermissions } from "@livekit/components-react";
import type { Participant } from "livekit-client";

export const usePublishPermissionState = (participant: Participant) => {

const permissions = useParticipantPermissions({ participant: participant });

const canPublish = permissions?.canPublish ?? false;
const canPublishSources = permissions?.canPublishSources ?? [];

if (canPublish && canPublishSources.length === 0) {

return {
  canPublishCamera: true,
  canPublishMicrophone: true,
  canPublishScreenShare: true,
  canPublishScreenShareAudio: true
}

}

return {
canPublishCamera: canPublish && canPublishSources.includes(TrackSource.CAMERA),
canPublishMicrophone: canPublish && canPublishSources.includes(TrackSource.MICROPHONE),
canPublishScreenShare: canPublish && canPublishSources.includes(TrackSource.SCREEN_SHARE),
canPublishScreenShareAudio: canPublish && canPublishSources.includes(TrackSource.SCREEN_SHARE_AUDIO)
}

} ,

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions