Sending short data
LINE Planet provides APIs that let you send a limited size of data ("short data") to peers during communications. This page describes how to send and receive short data by call type.
| Supported call type | Supported SDK version |
|---|---|
| 1-to-1 call, group call | All versions |
Common features
The following applies to sending short data regardless of call types.
Size limitation
The methods to send short data accept the type of the data along with the data itself. The maximum sizes for the data type and the data are as follows:
- Data type: 100 bytes (including the null termination character)
- Data: 800 bytes
Rate limit
Only one sending operation is allowed per second.
Retrieving the result of sending short data
Sometimes data transfer might fail even after several retries by LINE Planet. You can find out the result of data transfer asynchronously with the result handler callback.
1-to-1 call
In 1-to-1 calls, you can send and receive short data as follows.
Sending short data
To send short data to the call peer, use sendShortData() of PlanetKitCall.
fun sendShortDataExample(call: PlanetKitCall, type: String, data: String) {
val byteArray = data.toByteArray(Charsets.UTF_8)
call.sendShortData(type, byteArray, object : PlanetKitSendShortDataResultCallback {
override fun onResult(isSuccess: Boolean, failReason: PlanetKitSendShortDataFailReason, userdata: Any?) {
if (isSuccess) {
Log.d(TAG, "sendShortData succeeded: type=$type, data=$data")
} else {
Log.e(TAG, "sendShortData failed: $failReason")
}
}
})
}
Handling received short data
The peer can receive the short data through onShortDataReceived of CallListener.
// Implement related callbacks of the CallListener interface
// MakeCallListener for caller and AcceptCallListener for callee
private val makeAcceptCallListener = object : MakeCallListener, AcceptCallListener {
...
override fun onShortDataReceived(call: PlanetKitCall, shortData: PlanetKitShortData) {
// This is called when short data is received from the peer.
val receivedData = String(shortData.data, Charsets.UTF_8)
Log.d(TAG, "Received short data: type=${shortData.type}, data=$receivedData")
// Write your own code here to handle the received data.
}
}
Group call
In group calls, you can send short data to a specific peer or all peers.
Sending short data to a specific peer
To send short data to a specific peer, use sendShortData(PlanetKitUser, String, ByteArray, Any?, PlanetKitSendShortDataResultCallback?) of PlanetKitConference.
fun sendShortDataToSpecificPeerExample(conference: PlanetKitConference, targetUser: PlanetKitUser, type: String, data: String) {
val byteArray = data.toByteArray(Charsets.UTF_8)
conference.sendShortData(targetUser, type, byteArray, object : PlanetKitSendShortDataResultCallback {
override fun onResult(isSuccess: Boolean, failReason: PlanetKitSendShortDataFailReason, userdata: Any?) {
if (isSuccess) {
Log.d(TAG, "sendShortData to ${targetUser.serviceId}@${targetUser.userId} succeeded: type=$type, data=$data")
} else {
Log.e(TAG, "sendShortData failed: $failReason")
}
}
})
}
Sending short data to all peers
To send short data to all peers, use sendShortData(String, ByteArray, Any?, PlanetKitSendShortDataResultCallback?) of PlanetKitConference.
fun sendShortDataToAllPeersExample(conference: PlanetKitConference, type: String, data: String) {
val byteArray = data.toByteArray(Charsets.UTF_8)
conference.sendShortData(type, byteArray, object : PlanetKitSendShortDataResultCallback {
override fun onResult(isSuccess: Boolean, failReason: PlanetKitSendShortDataFailReason, userdata: Any?) {
if (isSuccess) {
Log.d(TAG, "sendShortData to all peers succeeded: type=$type, data=$data")
} else {
Log.e(TAG, "sendShortData failed: $failReason")
}
}
})
}
Handling received short data
The peers can receive the short data through onShortDataReceived of ConferenceListener.
// Implement related callbacks of the ConferenceListener interface
private val conferenceListener = object : ConferenceListener {
...
override fun onShortDataReceived(conference: PlanetKitConference, sender: PlanetKitUser, shortData: PlanetKitShortData) {
// This is called when short data is received from a peer in the conference.
val receivedData = String(shortData.data, Charsets.UTF_8)
Log.d(TAG, "Received short data from ${sender.serviceId}@${sender.userId}: type=${shortData.type}, data=$receivedData")
// Write your own code here to handle the received data.
}
}
Failure reasons for sending short data
The PlanetKitSendShortDataFailReason enum delivered by the result handler callback lets you determine the result of sending short data and its failure reason. The possible failure reasons are as follows:
| Value | Description |
|---|---|
NONE | The short data was sent successfully. |
INVALID_PARAMETER | One or more input parameters are invalid (e.g., data size is 0). |
TOO_LONG_DATA_TYPE | The data type exceeds the maximum allowed length (over 100 bytes including the null terminator). |
TOO_LONG_DATA | The data payload exceeds the maximum allowed size (over 800 bytes). |
TOO_FREQUENT | The short data was sent more frequently than allowed (rate limit exceeded). Only one sending operation is allowed per second. |
TIMEOUT | The sending operation failed due to a timeout. |
Related APIs
APIs related to sending short data are as follows.