# Chat Chat is is designed to support in-session text communication. Zoom truncates messages exceeding a binary size of 10,000 bytes. As a best practice, we recommend a limit of 1000 characters per message. While in a session, users can send chat messages to each other. The following two main components within the SDK will help you implement in-session message features: - An instance of `IZoomVideoSDKChatHelper` provides methods for sending and receiving messages in a session running on your app. - The `onChatNewMessageNotify` callback from your `IZoomVideoSDKDelegate` confirms the delivery of the message. ## Send message Messages can be sent to a single user or the whole session. ### Send a private chat message ```cpp // Get the IZoomVideoSDKChatHelper to perform chat actions. IZoomVideoSDKChatHelper* pChatHelper = m_pVideoSDK->getChatHelper(); // Check if chat is enabled in this session. if (pChatHelper->isChatDisabled() == false && pChatHelper->isPrivateChatDisabled() == false) { // Send message to User. pChatHelper->sendChatToUser(pUser, strMessage); } ``` ### Send a public chat message to all users in session ```cpp // Get the IZoomVideoSDKChatHelper to perform chat actions. IZoomVideoSDKChatHelper* pChatHelper = m_pVideoSDK->getChatHelper(); // Check if chat is enabled in this session. if (pChatHelper->isChatDisabled() == false) { // Send message to all users in this session. pChatHelper->sendChatToAll(strMessage); } ``` ## Receive message To be notified when a message is received use `onChatNewMessageNotify` within `IZoomVideoSDKDelegate`. The parameter `messageItem` contains information about the message including a `IZoomVideoSDKUser` object for both the sender and recipient. ```cpp void CExampleListener::onChatNewMessageNotify(IZoomVideoSDKChatHelper* pChatHelper, IZoomVideoSDKChatMessage* messageItem) { if (!messageItem) return; CString strInfo; const zchar_t* szMessageContent = messageItem->getContent(); IZoomVideoSDKUser* pRecievingUser = messageItem->getReceiveUser(); IZoomVideoSDKUser* pSendingUser = messageItem->getSendUser(); const zchar_t* sendUserName =pSendingUser->getUserName(); const zchar_t* recUserName="all"; if (pRecievingUser){ recUserName=pRecievingUser->getUserName(); } printf("New message from %s to %s %s\n", sendUserName, recUserName, szMessageContent); } ``` For more information on using the `IZoomVideoSDKUser` object, see [Sessions](/docs/video-sdk/linux/sessions). ## Chat message details The following may be helpful methods in managing messages using the `IZoomVideoSDKChatMessage` object: ```cpp messageItem->isChatToAll(); // Returns false for private messages. messageItem->isSelfSend(); // Returns true if the current user sent the message. messageItem->getTimeStamp(); // The time at which the message was sent. messageItem->getReceiveUser(); // The recipient of a private message. ``` ## Send files in chat Users can transfer files in chat during the session. > Zoom deletes files sent via in-session chat when the session ends. Enable [send files via in-session chat](/docs/build/account/#in-session-advanced) in your Video SDK account portal settings and configure the following settings. - **Only allow specified file types** - Select to allow only specific file types and enter the file extensions in the text box, separated by commas. - **Maximum file size** - Select to limit the file size to 2048 MB. Check if the file transfer feature is enabled. ```cpp // Get the ZoomVideoSDK instance IZoomVideoSDK* pVideoSDK = IZoomVideoSDK::getInstance(); if (!pVideoSDK) return; // Get the session object IZoomVideoSDKSession* pSession = pVideoSDK->getSession(); if (!pSession) return; // Check if file transfer is enabled bool isFileTransferEnabled = pSession->isFileTransferEnable(); if (isFileTransferEnabled) { // File Transfer is enabled. } ``` Get the list of allowed file types that you can transfer. ```cpp // Get the ZoomVideoSDK instance IZoomVideoSDK* pVideoSDK = IZoomVideoSDK::getInstance(); if (!pVideoSDK) return; // Get the session object IZoomVideoSDKSession* pSession = pVideoSDK->getSession(); if (!pSession) return; // Get the string value of the allowed file types const char* fileType = pSession->getTransferFileTypeWhiteList(); // Check if fileType is not null or empty if (fileType && strlen(fileType) > 0) { // fileType is a standard character string (const char*) consisting of the allowed file types, // multiple values are separated by a comma (e.g., "pdf,jpg,png"). } ``` Get the maximum file size to transfer. ```cpp // Get the ZoomVideoSDK instance IZoomVideoSDK* pVideoSDK = IZoomVideoSDK::getInstance(); if (!pVideoSDK) return; // Get the session object IZoomVideoSDKSession* pSession = pVideoSDK->getSession(); if (!pSession) return; // Retrieve the maximum allowed file size long maxSize = pSession->getMaxTransferFileSize(); // In C++, the value is directly available. We can check if it's greater than 0 // or just proceed with the value, as the function itself handles the retrieval. // An "if" check in C++ might be used to ensure a valid or expected size. if (maxSize > 0) { // maxSize is a long value representing the maximum allowed file size (in bytes). } ``` Send files to all users in the current session. ```cpp #include "zoom_videosdk_def.h" // Necessary for ZoomVideoSDKError and other definitions // Get the ZoomVideoSDK instance IZoomVideoSDK* pVideoSDK = IZoomVideoSDK::getInstance(); if (!pVideoSDK) return; // Get the session object IZoomVideoSDKSession* pSession = pVideoSDK->getSession(); // The C++ equivalent of 'if let session = ...' is checking the pointer if (pSession) { // The C++ API for strings (like file paths) often uses wide-character strings (const wchar_t*) const char* filePath = "/path/to/your/file.pdf"; // Call the transferFile method (assuming it exists on IZoomVideoSDKSession) // Note: The actual SDK method might be on a dedicated file transfer helper. // Assuming a method like this for direct translation: ZoomVideoSDKErrors error = pSession->transferFile(filePath); if (error == ZoomVideoSDKErrors::Errors_Success) { // Transfer successfully } else { // Failed to transfer. The 'error' variable holds the specific failure code. } } ``` Send files to a certain user in the session. ```cpp #include "zoom_videosdk_def.h" // Necessary for ZoomVideoSDKErrors and other definitions // Assuming 'pUserToReceiveFile' is an already retrieved and valid pointer // to the target user's object (IZoomVideoSDKUser*). IZoomVideoSDKUser* pUserToReceiveFile = nullptr; // Initialize or retrieve this pointer first // --- Example of how you might retrieve the user (from a user list) --- // IZoomVideoSDKUser* pTargetUser = userList->GetItem(some_index); // pUserToReceiveFile = pTargetUser; // ---------------------------------------------------------------------- if (pUserToReceiveFile) { // Define the file path using a wide-character string (const wchar_t*), common in Windows C++ SDKs. const char* filePath = "/path/to/your/document.txt"; // Call the transferFile method on the IZoomVideoSDKUser object. ZoomVideoSDKErrors error = pUserToReceiveFile->transferFile(filePath); if (error == ZoomVideoSDKErrors::Errors_Success) { // Transfer successfully } else { // Failed to transfer. The 'error' variable holds the specific failure code. } } else { // Handle the case where the user object is not valid or was not found. } ``` Cancel sending files. ```cpp #include "zoom_videosdk_def.h" // Necessary for ZoomVideoSDKSendFile and ZoomVideoSDKFileTransferStatus // Implementation of the onSendFileStatus callback method within your C++ listener class void CExampleListener::onSendFileStatus(IZoomVideoSDKSendFile* pFile, ZoomVideoSDKFileTransferStatus status) { // Check if the status is NOT FileTransferState_TransferDone AND the file object pointer is valid. if (status != ZoomVideoSDKFileTransferStatus::FileTransferState_TransferDone && pFile) { // Call the cancelSend method on the IZoomVideoSDKSendFile object. ZoomVideoSDKErrors error = pFile->cancelSend(); if (error != ZoomVideoSDKErrors::Errors_Success) { // Handle cancellation failure (optional) } } } ``` Start receiving files. ```cpp #include "zoom_videosdk_def.h" // Necessary for ZoomVideoSDKReceiveFile and ZoomVideoSDKFileTransferStatus // Define the local path where the file should be saved const char* filePath = "/home/user/Downloads/ZoomFile.dat"; // Implementation of the onReceiveFileStatus callback method within your C++ listener class void CExampleListener::onReceiveFileStatus(IZoomVideoSDKReceiveFile* pFile, ZoomVideoSDKFileTransferStatus status) { // The C++ equivalent of 'guard let receiveFile = file else { return }' // is a simple pointer check at the start of the function. if (!pFile) { return; } // NOTE: In a real application, you would check the 'status' here (e.g., if the file is ready to receive) // before calling startReceive(). However, for a direct translation: // Call the startReceive method on the IZoomVideoSDKReceiveFile object. ZoomVideoSDKErrors error = pFile->startReceive(filePath); if (error != ZoomVideoSDKErrors::Errors_Success) { // Handle failure to start receiving the file (optional) } } ``` Cancel receiving files. ```cpp #include "zoom_videosdk_def.h" // Include necessary definitions // Implementation of the onReceiveFileStatus callback method within your C++ listener class void CExampleListener::onReceiveFileStatus(IZoomVideoSDKReceiveFile* pFile, ZoomVideoSDKFileTransferStatus status) { // The C++ equivalent of 'guard let receiveFile = file else { return }' // is a simple pointer check at the start of the function. if (!pFile) { return; } // Call the cancelReceive method on the IZoomVideoSDKReceiveFile object. ZoomVideoSDKErrors error = pFile->cancelReceive(); if (error != ZoomVideoSDKErrors::Errors_Success) { // Handle failure to cancel the receive operation (optional) } } ``` ### File transfer callbacks Be sure that you have [set up a delegate for callback events](/docs/video-sdk/linux/integrate/#implement-a-delegate) to receive file transfer callbacks. Get notified when you transfer a file. ```cpp #include "zoom_videosdk_def.h" // Include necessary definitions for types // Implementation of the onSendFileStatus callback method within your C++ listener class void CExampleListener::onSendFileStatus(IZoomVideoSDKSendFile* pFile, ZoomVideoSDKFileTransferStatus status) { // This is the C++ callback function body, currently empty, // waiting for implementation logic based on the file and status. // Example: Check if the file transfer is complete if (status == ZoomVideoSDKFileTransferStatus::FileTransferState_TransferDone) { // The file has been successfully sent. } } ``` Get notified when you receive a file from other users. ```cpp #include "zoom_videosdk_def.h" // Include necessary definitions for types // Implementation of the onReceiveFileStatus callback method within your C++ listener class void CExampleListener::onReceiveFileStatus(IZoomVideoSDKReceiveFile* pFile, ZoomVideoSDKFileTransferStatus status) { // This is the C++ callback function body, currently empty. // In a real application, you would implement logic here to handle // different transfer statuses (e.g., FileTransferState_ReadyToReceive, FileTransferState_TransferDone, etc.). } ```