A double-edged sword — experience and guide of using custom message in rongyun instant messaging SDK

Time:2021-5-3

A double-edged sword — experience and guide of using custom message in rongyun instant messaging SDK

Background:

Recently, the new app of the company needs to add instant messaging function. It is impossible to realize it quickly. (deadline also can’t resist wow). It is chosen from every mature SDK manufacturer. Each has its own advantages and disadvantages. Finally, the SDK will be selected by the point soldiers, who has the final say.

His family’s official website and document address:
Official website:https://www.rongcloud.cn/
file:https://docs.rongcloud.cn/v4

This task of course still falls on me. I use their home SDK with UI (their home has two kinds of SDKs with UI and without UI. The SDK without UI only has instant messaging capability. All the UI needs to be customized by the developer. The SDK with UI encapsulates some basic interfaces, such as session list and conversation interface for chatting with others)

Demand:

There are only 9 default message types in the system of cloud integration

function describe
Text message It is used to send text messages, including expressions and hyperlinks (which will be automatically recognized). After receiving the message, the client will count the number of unread messages and store them.
Voice message Send high-quality short voice messages, and store the recorded voice files to the rongyun server. The voice file format is AAC, and the maximum duration is 60 seconds. After receiving the message, the client will count the number of unread messages and store them.
Picture message It is used to send picture messages. After receiving the message, the client counts the number of unread messages and stores them. The format of image thumbnail is JPG, and the recommended size is no more than 100k.
Gif picture message It is used to send GIF dynamic picture messages. After receiving the message, the client counts the number of unread messages and stores them.
Graphic message It is used to send text messages, including a title, a piece of text content and a picture. After receiving the message, the client counts the number of unread messages and stores them.
File message It is used to send file messages. After receiving the messages, the client counts the number of unread messages and stores them.
Location message It is used to send geographic location messages. After receiving the messages, the client counts the number of unread messages and stores them.
Small video message It is used to send small video messages. It supports two ways: recording and sending, and selecting local video file to send. The recording time is no more than 10 seconds. The local video file selection time is no more than 2 minutes. The small video message small video file format is. MP4. After receiving the message, the client counts the number of unread messages and stores them.
Merge and forward messages In the imkit SDK, multiple messages can be merged into one message for sending. The merged message is stored in the form of HTML file to the cloud server. After receiving the message, the client will count the number of unread messages and store them.

In fact, these nine kinds of messages have met most of the instant chat scenarios, whether it’s the most common text messages of typing chat, or voice messages sent by long press recording, as well as picture messages and location sharing messages. Basically, some scenarios of wechat are covered

But because each product is different, some people need a chat tool that is more concise than wechat, while others need a chat tool that is as powerful as QQ. There are always many different needs. For example, our app is like this, There are always scenarios that cannot be satisfied here. For example, QQ can put pictures and text messages into the same message bubble (similar to rich text messages). In this case, the default types of messages are not enough

However, rongyun has done a good job in this area, exposing classes and interfaces, allowing users to customize messages. Basically, it can define messages as they want

Experience (1)

Here are some custom messages, tips and guidelines that I use when developing our company’s app

Time limited reward notification to current online users only

We only send messages to the current online users. We have a kind of game reward that is only given to the users who are online in a special period. Only the current online users can receive this kind of message to receive the reward. Other users who are not online in this period can not receive it, and can not receive the reserved offline message after logging in again
This requirement is realized by making a custom message
Set the flag value in the message tag of the custom message class to message tag. Status. This message type is the status message. The status message is not stored or counted. When the receiver is not online, the message will be discarded directly, and the user will not receive the message when he is online again.

Students in need can see their own documents about custom messageshttps://docs.rongcloud.cn/im/…

After sending a custom message, the message will be recalled, and the message will fail to be recalled

I have accumulated an experience here, which can be regarded as helping people step on their family’s pit
This error occurs when sending a customization using the following methods:

After sending a custom message, there is no response when withdrawing the message. You can withdraw the message normally after exiting the session interface and entering it again. Recallmessage errorcode = 25101 is displayed in the log.

public Message sendMessage(ConversationType type, String targetId, MessageContent content, String pushContent, String pushData, final SendMessageCallback callback) {

You must use this method to send

public void sendMessage(Message message, String pushContent, String pushData, final ISendMessageCallback callback) 

This problem is also very dangerous. It took a little effort to find out the technical support of their family. I hope you can find my experience quickly when you encounter this kind of problem

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]