짧은 데이터
LINE Planet은 통신 중에 피어에게 제한된 크기의 데이터("짧은 데이터")를 보낼 수 있는 API를 제공합니다. 이 페이지에서는 통화 유형별로 짧은 데이터를 보내고 받는 방법을 설명합니다.
| 지원 통화 유형 | 지원 SDK 버전 |
|---|---|
| 1대1 통화, 그룹 통화 | 1.2 |
공통 사항
통화 유형에 관계없이 짧은 데이터 전송에는 다음 사항이 적용됩니다.
크기 제한
짧은 데이터를 보내는 메서드는 데이터 자체와 함께 데이터 유형을 인자로 받습니다. 데이터 유형 및 데이터의 최대 크기는 다음과 같습니다.
- 데이터 유형: 100바이트(null 종료 문자 포함)
- 데이터: 800바이트
짧은 데이터 전송 결과 얻기
sendShortData()는 네이티브 SDK에서 전송 요청이 수락되었는지 여부를 나타내는 Future<bool>을 반환합니다. false 결과는 전송 이전에 요청이 거부되었음을 의미합니다(예: 크기가 유효하지 않음). 네트워크 수준의 전달 실패는 별도로 보고되지 않습니다.
1대1 통화
1대1 통화에서는 다음과 같이 짧은 데이터를 보내고 받을 수 있습니다.
짧은 데이터 전송하기
통화 상대방에게 짧은 데이터를 전송하려면 PlanetKitCall의 sendShortData()를 사용하세요.
Future<bool> sendShortDataExample(PlanetKitCall call, String type, String data) async {
final byteData = Uint8List.fromList(utf8.encode(data));
final success = await call.sendShortData(type: type, data: byteData);
if (success) {
print('sendShortData succeeded: type=$type, data=$data');
} else {
print('sendShortData failed');
}
return success;
}
수신한 짧은 데이터 처리하기
상대방은 PlanetKitCallEventHandler의 onShortDataReceived를 통해 짧은 데이터를 수신할 수 있습니다.
final eventHandler = PlanetKitCallEventHandler(
// ... other required callbacks ...
onShortDataReceived: (PlanetKitCall call, String type, Uint8List data) {
// This is called when short data is received from the peer.
final receivedData = utf8.decode(data);
print('Received short data: type=$type, data=$receivedData');
// Write your own code here to handle the received data.
},
);
그룹 통화
그룹 통화에서는 특정 피어 또는 모든 피어에게 짧은 데이터를 보낼 수 있습니다.
특정 피어에게 짧은 데이터 전송하기
특정 피어에게 짧은 데이터를 전송하려면 PlanetKitConference의 sendShortDataToPeer()를 사용하세요.
Future<bool> sendShortDataToSpecificPeerExample(
PlanetKitConference conference,
PlanetKitUserId peerId,
String type,
String data,
) async {
final byteData = Uint8List.fromList(utf8.encode(data));
final success = await conference.sendShortDataToPeer(
peerId: peerId,
type: type,
data: byteData,
);
if (success) {
print('sendShortDataToPeer succeeded: type=$type, data=$data');
} else {
print('sendShortDataToPeer failed');
}
return success;
}
모든 피어에게 짧은 데이터 전송하기
모든 피어에게 짧은 데이터를 전송하려면 PlanetKitConference의 sendShortData()를 사용하세요.
Future<bool> sendShortDataToAllPeersExample(
PlanetKitConference conference,
String type,
String data,
) async {
final byteData = Uint8List.fromList(utf8.encode(data));
final success = await conference.sendShortData(type: type, data: byteData);
if (success) {
print('sendShortData to all peers succeeded: type=$type, data=$data');
} else {
print('sendShortData failed');
}
return success;
}
수신한 짧은 데이터 처리하기
피어는 PlanetKitConferenceEventHandler의 onShortDataReceived를 통해 짧은 데이터를 수신할 수 있습니다.
final eventHandler = PlanetKitConferenceEventHandler(
// ... other required callbacks ...
onShortDataReceived: (
PlanetKitConference conference,
PlanetKitUserId senderId,
String type,
Uint8List data,
) {
// This is called when short data is received from a peer in the conference.
final receivedData = utf8.decode(data);
print('Received short data from ${senderId.userId}: type=$type, data=$receivedData');
// Write your own code here to handle the received data.
},
);
관련 API
짧은 데이터 전송과 관련된 API는 다음과 같습니다.