One-to-one message

It takes ordinary text messages as an example in the document. If there are other data format requirements, the text can be replaced with the JSON data defined by yourself

For example, if you want to send a picture, you can upload it to your own server or use a 3rd party image storage (such as Qi Niuyun, Alibaba Cloud OSS, etc.) to upload the image and send the URL.

3.1 Receiving one-to-one messages

Create a CChatManager object, and pass in user configuration information and the callback pointer.

Sample:

The class which the object belongs to needs to implement the IStarIMC2CListener interface to receive message callbacks.
m_pChatManager = new CChatManager(pUserManager, this);

3.2 Sending one-to-one messages

The messages are divided into ordinary message(sendMessage) and online message(sendOnLineMessage).

“Normal message” refers to a normal chat message, which is cached when the user is offline, and it will be took all offline messages when they go online again.

“Online messages” are only received when the receiver is online, which are not cached.

Sample:

bool CChatManager::sendOnlineMessage(char* toUserId, char* msgStr)
{
CIMMessage* pIMMessage = StarIMMessageBuilder::getC2CMessage(m_pStarRtcCore->m_pUserManager->m_ServiceParam.m_strUserId, toUserId, msgStr);
if (pIMMessage != NULL)
{
addMessageToMap(pIMMessage);
m_pStarRtcCore->sendOnlineMessage(pIMMessage);
}
return true;
}

bool CChatManager::sendVoipOnlineMessage(char* fromId, char* targetId, int code, char* data)
{
CIMMessage* pIMMessage = StarIMMessageBuilder::getVoipMessage(fromId, targetId, code, data);
if (pIMMessage != NULL)
{
m_pStarRtcCore->sendOnlineMessage(pIMMessage);
}
return true;
}