-
Notifications
You must be signed in to change notification settings - Fork 2
DataChannel
Lejla Solak edited this page Oct 26, 2023
·
1 revision
void send(String text, SendTextListener sendTextListener)
void send(String text, Endpoint to, SendTextListener sendTextListener)
void setEventListener(DataChannelEventListener dataChannelEventListener)
DataChannelEventListener getEventListener()
Sends data through the data channel to all other call participants who also have data channel enabled.
-
text
:String
- Data to be sent through the data channel. -
sendTextListener
:SendTextListener
- Listener to handle success and failure of sending data.
N/A
InfobipRTC infobipRTC = InfobipRTC.getInstance();
ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();
DataChannel dataChannel = applicationCall.dataChannel();
dataChannel.send("Hello World!", new SendTextListener() {
@Override
public void onSendSuccess(String id) {
Log.d("WebRTC", String.format("Successfully sent text with id: %s", id));
}
@Override
public void onSendFailure(ErrorCode errorCode) {
Log.e("WebRTC", String.format("Error occurred when sending text: %s.", errorCode.getDescription()));
}
});
Sends data through the data channel directly to a chosen endpoint participating in the call. This method ensures that the text is only sent to the chosen recipient and therefore is not received by any other call participants.
-
text
:String
- Data to be sent through the data channel. -
to
:Endpoint
- Endpoint to send data directly to. -
sendTextListener
:SendTextListener
- Listener to handle success and failure of sending data.
N/A
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
DataChannel dataChannel = webrtcCall.dataChannel();
dataChannel.send("Hello World!", webrtcCall.counterpart(), new SendTextListener() {
@Override
public void onSendSuccess(String id) {
Log.d("WebRTC", String.format("Successfully sent text with id: %s", id));
}
@Override
public void onSendFailure(ErrorCode errorCode) {
Log.e("WebRTC", String.format("Error occurred when sending text: %s.", errorCode.getDescription()));
}
});
Configures event handler for data channel events.
-
dataChannelEventListener
:DataChannelEventListener
- An interface that should be implemented in order to properly handle data channel events.
N/A
InfobipRTC infobipRTC = InfobipRTC.getInstance();
ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();
DataChannel dataChannel = applicationCall.dataChannel();
dataChannel.setEventListener(new DataChannelEventListener() {
@Override
public void onTextDelivered(TextDeliveredEvent textDeliveredEvent) {
if (textDeliveredEvent.isDelivered()) {
Toast.makeText(getApplicationContext(), String.format("Successfully delivered text with id: %s", textDeliveredEvent.getId()), Toast.LENGTH_LONG);
} else {
Toast.makeText(getApplicationContext(), String.format("Failed to deliver text with id: %s", textDeliveredEvent.getId()), Toast.LENGTH_LONG);
}
}
@Override
public void onTextReceived(TextReceivedEvent textReceivedEvent) {
if (textReceivedEvent.isDirect()) {
Toast.makeText(getApplicationContext(), String.format("Received direct text from %s: %s", textReceivedEvent.getFrom().identifier(), textReceivedEvent.getText()), Toast.LENGTH_LONG);
} else {
Toast.makeText(getApplicationContext(), String.format("Received text from %s: %s", textReceivedEvent.getFrom().identifier(), textReceivedEvent.getText()), Toast.LENGTH_LONG);
}
}
});
Returns event handler for data channel events.
none
-
DataChannelEventListener
- An interface that should be implemented in order to properly handle data channel events.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();
DataChannel dataChannel = applicationCall.dataChannel();
DataChannelEventListener dataChannelEventListener = applicationCall.getEventListener();