UNPKG

mediasfu-reactnative-expo

Version:

mediasfu-reactnative-expo – Expo-managed React Native WebRTC SDK for video conferencing, webinars, live streaming, broadcast, screen sharing, whiteboard, chat, recording, live subtitles, translation, and AI agent rooms on iOS, Android, and web. Prebuilt r

88 lines 3.56 kB
/** * Sends a message to the specified room. * * @param {Object} options - The options for sending the message. * @param {string} options.member - The member sending the message. * @param {string} options.islevel - The level of the member. * @param {Function} options.showAlert - Function to show alert messages. * @param {Array} options.coHostResponsibility - List of co-host responsibilities. * @param {string} options.coHost - The co-host of the room. * @param {boolean} options.chatSetting - Chat setting for the room. * @param {string} options.message - The message to be sent. * @param {string} options.roomName - The name of the room. * @param {number} options.messagesLength - The current number of messages in the room. * @param {Array} options.receivers - List of receivers for the message. * @param {boolean} options.group - Indicates if the message is for a group. * @param {string} options.sender - The sender of the message. * @param {Object} options.socket - The socket instance for communication. * * @returns {Promise<void>} A promise that resolves when the message is sent. * * @throws Will throw an error if the message count limit is exceeded. * @throws Will throw an error if the message, sender, or receivers are not valid. * @throws Will throw an error if the user is not allowed to send a message in the event room. * * @example * ```typescript * launchMessages({ * updateIsMessagesModalVisible: (visible) => console.log("Modal visibility:", visible), * isMessagesModalVisible: false, * }); * ``` */ export const sendMessage = async ({ message, receivers, group, messagesLength, member, sender, islevel, showAlert, coHostResponsibility, coHost, roomName, socket, chatSetting, }) => { let chatValue = false; const normalizedReceivers = (receivers ?? []).filter((receiver) => typeof receiver === 'string' && receiver.trim().length > 0); if ((messagesLength > 100 && roomName.startsWith('d')) || (messagesLength > 500 && roomName.startsWith('s')) || (messagesLength > 100000 && roomName.startsWith('p'))) { showAlert?.({ message: 'You have reached the maximum number of messages allowed.', type: 'danger', duration: 3000, }); return; } if (!message || message === '') { showAlert?.({ message: 'Message is not valid.', type: 'danger', duration: 3000, }); return; } if (normalizedReceivers.length < 1 && group === false && islevel === '2') { showAlert?.({ message: 'Please select a message to reply to', type: 'danger', duration: 3000, }); return; } const messageObject = { sender: sender ? sender : member, receivers: normalizedReceivers, message, timestamp: new Date().toLocaleTimeString(), group: group !== undefined && group !== null ? group : false, }; try { chatValue = coHostResponsibility.find((item) => item.name === 'chat')?.value ?? false; } catch (error) { console.error(error); } if (!(islevel === '2' || (coHost === member && chatValue === true)) && !chatSetting) { showAlert?.({ message: 'You are not allowed to send a message in this event room', type: 'danger', duration: 3000, }); return; } socket.emit('sendMessage', { messageObject, roomName, }); }; //# sourceMappingURL=sendMessage.js.map