setMicrophoneState method

dynamic setMicrophoneState(
  1. bool isOn
)

Implementation

setMicrophoneState(bool isOn) async {
  if (_room != null) {
    _isMicOn = isOn;
    await _room?.localParticipant?.setMicrophoneEnabled(isOn);

    // update the mic status of the client to others
    final localAddress = getCachedWallet()!.address!;

    final spaceData = data;
    final speakers = data.liveSpaceData.speakers.toList();

    if (spaceData.liveSpaceData.host.address == localAddress) {
      spaceData.liveSpaceData.host.audio = isOn;
    }

    for (var speaker in speakers) {
      if (speaker.address == localAddress) {
        speaker.audio = isOn;
        break;
      }
    }

    spaceData.liveSpaceData.speakers = speakers;

    String metaMessageContent =
        isOn == true ? CHAT.UA_SPEAKER_MIC_ON : CHAT.UA_SPEAKER_MIC_OFF;

    sendLiveSpaceData(
      messageType: MessageType.USER_ACTIVITY,
      updatedLiveSpaceData: spaceData.liveSpaceData,
      content: metaMessageContent,
      affectedAddresses: [localAddress],
      spaceId: spaceData.spaceId,
    );

    data = spaceData;
    notifyListeners();
  }
}