IMeetingChatController::SendChatMsgTo fails

@seungkoo

I’ve just tried this and it works, however I’m a different implementation to make sure that the sending of message will be definitely in the main thread.

//onChatMessageReceived is a helper method in the main thread, which is passed into this event listener. When there is message received on the event listener, it passes the message back into onChatMessageReceived method in the main thread.

MeetingChatEventListener::MeetingChatEventListener(void(*onChatMessageReceived)(IChatMsgInfo* chatMsg))
{
	onChatMessageReceived_ = onChatMessageReceived;
}


void MeetingChatEventListener::onChatMsgNotifcation(IChatMsgInfo* chatMsg, const zchar_t* content)
{
	std::cout<<"onChatMsgNotifcation: " << chatMsg->GetSenderDisplayName() << " says " << chatMsg->GetContent() << endl;
	if (onChatMessageReceived_)onChatMessageReceived_(chatMsg);
}

.
.
.
//in the main thread

//callback when given receive messages
void onChatMessageReceived(IChatMsgInfo* chatMsg) {
	printf("onChatMessageReceived\n");
	IMeetingChatController* meetingchatcontroller = m_pMeetingService->GetMeetingChatController();


	// Convert std::wstring to std::string (UTF-8)
	std::wstring wstr = L"Reply to user!";
	std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
	std::string str = converter.to_bytes(wstr);

	// Ensure zchar_t is defined as char if not already defined
	typedef char zchar_t;

	char charArray[1024]; // Choose an appropriate size
	std::strncpy(charArray, str.c_str(), sizeof(charArray));

	// Ensure null-termination
	charArray[sizeof(charArray) / sizeof(charArray[0]) - 1] = '\0';

	const zchar_t* constCharArray = charArray;

	IChatMsgInfoBuilder* chatbuilder = meetingchatcontroller->GetChatMessageBuilder();
	chatbuilder->SetReceiver(0);
	chatbuilder->SetMessageType(SDKChatMessageType_To_All);
	chatbuilder->SetContent(constCharArray);
	chatbuilder->Build();

	meetingchatcontroller->SendChatMsgTo(chatbuilder->Build());


}