Skip to main content
Version: 7.0

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 typeSupported SDK version
1-to-1 call, group callAll 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.

func sendShortDataExample(call: PlanetKitCall, type: String, data: String) {
guard let byteData = data.data(using: .utf8) else {
print("Failed to convert string to data")
return
}

call.sendShortData(type: type, data: byteData) { reason in
guard reason == .none else {
print("sendShortData failed: \(reason)")
return
}
print("sendShortData succeeded: type=\(type), data=\(data)")
}
}

Handling received short data

The peer can receive the short data through didReceiveShortData of PlanetKitCallDelegate.

extension CallDelegateExample : PlanetKitCallDelegate {
...

func didReceiveShortData(_ call: PlanetKitCall, dataType: String, data: Data) {
// This is called when short data is received from the peer.
if let receivedData = String(data: data, encoding: .utf8) {
print("Received short data: type=\(dataType), 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(peerId:type:data:completion:) of PlanetKitConference.

func sendShortDataToSpecificPeerExample(conference: PlanetKitConference, peerId: PlanetKitUserId, type: String, data: String) {
guard let byteData = data.data(using: .utf8) else {
print("Failed to convert string to data")
return
}

conference.sendShortData(peerId: peerId, type: type, data: byteData) { reason in
guard reason == .none else {
print("sendShortData failed: \(reason)")
return
}
print("sendShortData to \(peerId) succeeded: type=\(type), data=\(data)")
}
}

Sending short data to all peers

To send short data to all peers, use sendShortData(type:data:completion:) of PlanetKitConference.

func sendShortDataToAllPeersExample(conference: PlanetKitConference, type: String, data: String) {
guard let byteData = data.data(using: .utf8) else {
print("Failed to convert string to data")
return
}

conference.sendShortData(type: type, data: byteData) { reason in
guard reason == .none else {
print("sendShortData failed: \(reason)")
return
}
print("sendShortData to all peers succeeded: type=\(type), data=\(data)")
}
}

Handling received short data

The peers can receive the short data through didReceiveShortData of PlanetKitConferenceDelegate.

extension ConferenceDelegateExample : PlanetKitConferenceDelegate {
...

func didReceiveShortData(_ conference: PlanetKitConference, senderId: PlanetKitUserId, dataType: String, data: Data) {
// This is called when short data is received from a peer in the conference.
if let receivedData = String(data: data, encoding: .utf8) {
print("Received short data from \(senderId): type=\(dataType), 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:

ValueDescription
noneThe short data was sent successfully.
invalidParameterOne or more input parameters are invalid (e.g., data size is 0).
tooLongDataTypeThe data type exceeds the maximum allowed length (over 100 bytes including the null terminator).
tooLongDataThe data payload exceeds the maximum allowed size (over 800 bytes).
tooFrequentThe short data was sent more frequently than allowed (rate limit exceeded). Only one sending operation is allowed per second.
timeoutThe sending operation failed due to a timeout.
internalErrorThe sending operation failed due to an internal error.

APIs related to sending short data are as follows.

Common

Enums

1-to-1 call

Methods

Events

Group call

Methods

Events