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.。

4.1 Receiving one-to-one messages

Receiving the one-to-one message through a callback function passed in during the login process;

function callBack(data,status) {
switch (status){
...
case "onVoipMessage":
//Received the voip message
switch(data.type)
{
case "voipCall":
//Received a voip call message
break;
case "voipRefuse":
//Received a voip rejection message
break;

}
break;
case "onSingleMessage":
//data结构
//data = {
// "fromId": message source
// "digest":
// "msg": Message structure
//}
//msg structure
//msg = {
// "fromId": Message source
// "targetId": Message receiver
// "time": Timestamp
// "msgIndex": Message sequence number
// "type": type
// "code": Message control type code
// "contentData": Message content
//};
break;
}
}

//Login to the SDK
var starSDK = new StarRtc.StarSDK();
starSDK.login(appID,userId,authKey,callBack);

4.2 Send 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.

Example:

/**
* Send one-to-one messages
* @param _targetId target userId
* @param _digest digest
* @param _txt text
* @param _type message type
*/
StarRtc.StarSDK.sendSingleMsg(_targetId,_digest,_txt, _type);