Handles the click event for toggling audio in a media session.

The parameters required for handling the audio click event.

The parameters for toggling audio.

Flag indicating whether to check media permission.

Flag indicating if the user has audio permission.

Flag indicating if audio is paused.

Flag indicating if audio is already turned on.

Flag indicating if the room is audio-only.

Flag indicating if recording has started.

Flag indicating if recording has resumed.

Flag indicating if recording is paused.

Flag indicating if recording is stopped.

Media options for recording (e.g., "video", "audio").

User's level in the application.

Flag indicating if the user is a co-host.

Flag indicating if admin restrictions are set.

Current state of the audio request.

Timestamp of the audio request.

Current member's name.

The socket instance for communication.

The local socket instance for communication.

The name of the room.

The default audio input device for the user.

Flag indicating if the microphone action is in progress.

The user's local media stream.

Current audio setting.

Current video setting.

Current screenshare setting.

Current chat setting.

Interval for updating request states.

List of participants in the room.

Flag indicating if the transport has been created.

Flag indicating if audio transport has been created.

A promise that resolves when the audio click event has been handled.

This function performs the following actions:

  • If the event is audio-only, it shows an alert and exits.
  • If the audio is already on, it handles the logic for turning it off, including checking recording states and permissions.
  • If the audio is off, it checks for admin restrictions, user permissions, and handles the logic for turning the audio on.
  • It updates various states and emits socket events as necessary.
const options: ClickAudioOptions = {
parameters: {
checkMediaPermission: true,
hasAudioPermission: false,
audioPaused: false,
audioAlreadyOn: false,
audioOnlyRoom: false,
recordStarted: false,
recordResumed: false,
recordPaused: false,
recordStopped: false,
recordingMediaOptions: 'audio',
islevel: '1',
youAreCoHost: false,
adminRestrictSetting: false,
audioRequestState: null,
audioRequestTime: 0,
member: 'John Doe',
socket: socketInstance,
localSocket: socketInstance,
roomName: 'exampleRoom',
userDefaultAudioInputDevice: 'default',
micAction: false,
localStream: null,
audioSetting: 'enabled',
videoSetting: 'disabled',
screenshareSetting: 'disabled',
chatSetting: 'enabled',
updateRequestIntervalSeconds: 30,
participants: [],
transportCreated: false,
transportCreatedAudio: false,
updateAudioAlreadyOn: (status) => console.log(status),
updateAudioRequestState: (state) => console.log(state),
updateAudioPaused: (status) => console.log(status),
updateLocalStream: (stream) => console.log(stream),
updateParticipants: (participants) => console.log(participants),
updateTransportCreated: (status) => console.log(status),
updateTransportCreatedAudio: (status) => console.log(status),
updateMicAction: (action) => console.log(action),
checkPermission: async () => 'granted',
streamSuccessAudio: async () => console.log('Audio streaming success'),
disconnectSendTransportAudio: async () => console.log('Audio transport disconnected'),
requestPermissionAudio: async () => 'granted',
resumeSendTransportAudio: async () => console.log('Audio transport resumed'),
},
};

const clickAudioService = new ClickAudio();
await clickAudioService.clickAudio(options);

Constructors

Methods

Constructors

Methods

  • Handles the click event for toggling audio in a media session.

    Parameters

    • parameters: ClickAudioOptions

      The parameters required for handling the audio click event.

    Returns Promise<void>

    A promise that resolves when the audio click event has been handled.

    The function performs the following actions:

    • If the event is audio-only, it shows an alert and exits.
    • If the audio is already on, it handles the logic for turning it off, including checking recording states and permissions.
    • If the audio is off, it checks for admin restrictions, user permissions, and handles the logic for turning the audio on.
    • It updates various states and emits socket events as necessary.

    The function makes use of several helper functions and state update functions passed in through the parameters.