# muteUserAudioLocally alternative in iOS

**URL:** <https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861>\
**Category:** Web\
**Tags:** phone, video-sdk\
**Created:** [August 2, 2024, 7:35am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861 "2024-08-02T07:35:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/thomas1/32/49720_2.png) [@thomas1](https://devforum.zoom.us/u/thomas1)\
**Post date:** [August 2, 2024, 7:35am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/1 "2024-08-02T07:35:17Z")

</div>

**Description**  
As I saw in another post it’s currently not possible to use `muteUserAudioLocally` in Safari on a iOS device. IS there any alternative? We have implemented a custom solution using the video-sdk. There are specific users which should only be heard by the moderator and know one else. Currently we are setting this in the `active-speaker` event, but it’s useless as long as there is no solution for this in iOS

**Which Web Video SDK version?**  
1.11.10

**Video SDK Code Snippets**

```auto
export async function useActiveSpeaker(payload: ActiveSpeaker[]) {
    const zoomStore = useZoomStore()
    const { room } = useRoomStore()
    if (room.key_role === 'user') {
        for (const user of payload) {
            if (user.displayName?.includes('coach|')) {
                console.log('mute user audio locally', user.userId, user.displayName)
                await zoomStore.client!.getMediaStream().muteUserAudioLocally(user.userId)
            }
        }
    }

    highlightActiveSpeaker(payload.map(user => user.userId).filter(userId => userId !== zoomStore.localUserId))
}

```

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [August 3, 2024, 5:34am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/2 "2024-08-03T05:34:14Z")

</div>

Hey @thomas1

Thanks for your feedback.

It’s the browser’s limitation that the `stream. muteUserAudioLocally` doesn’t work on iOS Safari.

> **[HTMLMediaElement: volume property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/volume)**
>
> The HTMLMediaElement.volume property sets the volume at
> which the media will be played.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![thomas1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/thomas1/32/49720_2.png) [@thomas1](https://devforum.zoom.us/u/thomas1)\
**Post date:** [August 5, 2024, 7:57am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/3 "2024-08-05T07:57:46Z")

</div>

Hello @vic.yang ,  
yes I saw that already - but my questions is if there is any other way to prevent a audio output on an iPhone for specific users.

---

<div class="post-metadata">

**Author:** ![thomas1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/thomas1/32/49720_2.png) [@thomas1](https://devforum.zoom.us/u/thomas1)\
**Post date:** [August 14, 2024, 12:06pm UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/4 "2024-08-14T12:06:04Z")

</div>

Any news @vic.yang ?

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [August 15, 2024, 5:19am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/5 "2024-08-15T05:19:48Z")

</div>

Hey @thomas1

Sorry for the late reply.

If you just want to prevent iPhone users from hearing any sound, you can simply call `stream.stopAudio`. However, if you’re aiming to mute a specific user’s audio, that’s currently not possible.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![thomas1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/thomas1/32/49720_2.png) [@thomas1](https://devforum.zoom.us/u/thomas1)\
**Post date:** [August 21, 2024, 8:01am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/6 "2024-08-21T08:01:22Z")

</div>

Thanks for the reply. @vic.yang

Would it be possible to stop the user Audio OR muteAll users locally in safari dynamically when the active speaker changes? So something like this:

```auto
export async function useActiveSpeaker(payload: ActiveSpeaker[]) {
    const zoomStore = useZoomStore()
    const currentUser = zoomStore.client?.getCurrentUserInfo()
    const isSafari = window.safari !== undefined;

    if (currentUser?.displayName.includes('user|') ?? true) {
        for (const user of payload) {
            if (user.displayName?.includes('coach|')) {
                await zoomStore.client!.getMediaStream().muteUserAudioLocally(user.userId)
                
                // fix for safari?
                if (isSafari) {
                    await zoomStore.client!.getMediaStream().muteAllUserAudioLocally() // or
                    await zoomStore.client!.getMediaStream().stopAudio()
                }
            }
        }

        if (isSafari && !payload.find(user => user.displayName?.includes('coach|'))) {
            await zoomStore.startAudio(false) // or
            await zoomStore.client?.getMediaStream().unmuteAllUserAudioLocally()
        }
    }

    highlightActiveSpeaker(payload.map(user => user.userId).filter(userId => userId !== zoomStore.localUserId))
}

```

`muteAllUserAudioLocally ` works in Safari right? So what would be the better option here and can you say if this is reliable enough? As far as I remember there are sometimes issues with safari when starting the user audio again right?

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [August 21, 2024, 8:46am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/7 "2024-08-21T08:46:29Z")

</div>

Hey @thomas1

> [@thomas1](#):
>
> `muteAllUserAudioLocally ` works in Safari right?

Yes. `muteAllUserAudioLocally` is available on all platforms. Under the hood, we use the `muted` attribute to control the local audio, which is widely supported across browsers.

However, please note the difference between `muteUserAudioLocally` and `muteAllUserAudioLocally`. The latter will mute the audio for all users.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![thomas1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/thomas1/32/49720_2.png) [@thomas1](https://devforum.zoom.us/u/thomas1)\
**Post date:** [August 21, 2024, 8:59am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/8 "2024-08-21T08:59:23Z")

</div>

Ok thanks for the clarification. Yes, that’s why the function above will mute all users as soon as the coach speaks and unmute them when any other user starts speaking. My question is whether the active-speaker-change event is reliable enough to manage this, or if you have a better suggestion for addressing this issue. @vic.yang

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [August 21, 2024, 9:30am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/9 "2024-08-21T09:30:59Z")

</div>

Hey @thomas1

In Video SDK Web, we provide two types of events for the active user. The `active-speaker` event will populate the three loudest users based on volume, including the current user, while the `video-active-change` event will provide the only one active user (based on audio volume) excluding the current user.

Based on your requirement, it’s better to use `active-speaker` event to handle the situation.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![vic.yang](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/vic.yang/32/24656_2.png) [@vic.yang](https://devforum.zoom.us/u/vic.yang)\
**Post date:** [August 21, 2024, 9:49am UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/10 "2024-08-21T09:49:44Z")

</div>

Hey @thomas1

Another approach is to use the command channel to send control commands to precisely manage when to mute local audio, especially when there is a need to whisper to the moderator.

```javascript
// someone want to send whisper
commandChannel.send("mute local audio start");

client.on("command-channel-message", async (value) => {
  const { text, senderId } = value;
  if (text === "mute local audio start") {
    await zoomStore.client
      ?.getMediaStream()
      .muteUserAudioLocally(Number(senderId));
    if (isIOSSafari) {
      await zoomStore.client?.getMediaStream().muteAllUserAudioLocally(); 
    }
  } else if (text === "unmute local audio end") {
    await zoomStore.client
      ?.getMediaStream()
      .unmuteUserAudioLocally(Number(senderId));
    if (isIOSSafari) {
      await zoomStore.client?.getMediaStream().unmuteAllUserAudioLocally(); // or
    }
  }
});

```

> **[Video SDK - web - Command channel](https://developers.zoom.us/docs/video-sdk/web/command-channel/)**
>
> The Zoom Developer Platform is an open platform that allows third-party developers to build applications and integrations upon Zoom’s video-first unified communications platform.

Thanks  
Vic

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [September 20, 2024, 7:50pm UTC](https://devforum.zoom.us/t/muteuseraudiolocally-alternative-in-ios/114861/11 "2024-09-20T19:50:28Z")

</div>

Closed on September 20, 2024, 7:50pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
