Skip to content

Commit 50e7866

Browse files
authored
Merge pull request #266794 from chengyuanlai-msft/patch-3
Update ACS Calling Native SDK Data Channel docs
2 parents 751bbbb + 2c32c66 commit 50e7866

File tree

6 files changed

+95
-97
lines changed

6 files changed

+95
-97
lines changed

articles/communication-services/quickstarts/voice-video-calling/includes/data-channel/data-channel-android.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ titleSuffix: An Azure Communication Services document
55
description: In this quickstart, you learn how to add data channel messaging to your existing Android calling app using Azure Communication Services.
66
author: sloanster
77
services: azure-communication-services
8-
ms.date: 05/04/2023
8+
ms.date: 03/01/2024
99
ms.topic: include
1010
ms.service: azure-communication-services
1111
ms.subservice: calling
1212
---
13-
1413
[!INCLUDE [Public Preview](../../../../includes/public-preview-include-document.md)]
1514
>[!IMPORTANT]
1615
> Please be aware that the current Data Channel feature API doesn't support direct messaging between a web browser and a native app in a peer-to-peer call scenario.
@@ -25,24 +24,21 @@ Refer to the [Voice Calling Quickstart](../../getting-started-with-calling.md?pi
2524
| DataChannelCallFeature | Used to start and manage data channel feature. |
2625
| DataChannelSender | Used to manage a data channel as a sender and send data. |
2726
| DataChannelReceiver | Used to manage a data channel as a receiver and receive data. |
28-
| DataChannelSenderCreateOptions | Used for representing options to create a data channel sender. |
29-
### Events
30-
| Name | Description |
31-
| - | - |
32-
| DataChannelReceiverCreatedEvent | Describes the event when a receiver is created. A new receiver is created when receiving a data message from another endpoint through a new data channel for the first time. |
33-
| DataChannelReceiverMessageReceivedEvent | Describes the event when a data message is received and ready to be fetched. |
34-
| DataChannelReceiverClosedEvent | Describes the event when a data channel receiver is to be closed. |
35-
### Listeners
36-
| Name | Description |
37-
| - | - |
38-
| DataChannelReceiverCreatedListener | Used to handle `DataChannelReceiverCreatedEvent`. |
39-
| DataChannelReceiverMessageReceivedListener | Used to handle `DataChannelReceiverMessageReceivedEvent`. |
40-
| DataChannelReceiverClosedListener | Used to handle `DataChannelReceiverClosedEvent`. |
27+
| DataChannelSenderOptions | Used for representing options to create a data channel sender. |
4128
### Enums
4229
| Name | Description |
4330
| - | - |
4431
| DataChannelPriority | Describes the priority options of data channel. Values: { `NORMAL`, `HIGH` }. |
4532
| DataChannelReliability | Describes the reliability options of data channel. Values: { `LOSSY`, `DURABLE` }. |
33+
### Error Code
34+
| Name | Description |
35+
| - | - |
36+
| _DATA_CHANNEL_FAILED_TO_START_ | `getDataChannelSender()` can fail with this error code, indicating underlying Data Channel is not ready to be used. |
37+
| _DATA_CHANNEL_RANDOM_ID_NOT_AVAILABLE_ | `getDataChannelSender()` can fail with this error code, indicating all available random channel IDs have already been used. |
38+
| _DATA_CHANNEL_SENDER_CLOSED_ | `sendMessage()` can fail with this error code, indicating the sender has already been closed previously. |
39+
| _DATA_CHANNEL_MESSAGE_SIZE_OVER_LIMIT_ | `sendMessage()` can fail with this error code, indicating the message data size exceeds the limit. You can get the message size limit using `getMaxMessageSizeInBytes()` in `DataChannelSender`. |
40+
| _DATA_CHANNEL_MESSAGE_FAILURE_FOR_BANDWIDTH_ | `sendMessage()` can fail with this error code, indicating a failure in sending the message due to not enough bandwidth. |
41+
| _DATA_CHANNEL_MESSAGE_FAILURE_FOR_TRAFFIC_LIMIT_ | `sendMessage()` can fail with this error code, indicating a failure in sending the message due to the overall usage of Data Channel not in compliance with the traffic limit rules. Refer to [Data Channel Concept Document](../../../../concepts/voice-video-calling/data-channel.md) for details of the traffic limit. |
4642
### Methods
4743
#### Enable Data Channel feature
4844

@@ -56,7 +52,7 @@ DataChannelCallFeature dataChannelCallFeature = call.feature(Features.DATA_CHANN
5652
```java
5753
DataChannelReceiverCreatedListener receiverCreatedListener = new DataChannelReceiverCreatedListener() {
5854
@Override
59-
public void onDataChannelReceiverCreated(DataChannelReceiverCreatedEvent e) {
55+
public void onReceiverCreated(DataChannelReceiverCreatedEvent e) {
6056
DataChannelReceiver receiver = e.getReceiver(); // get the new data channel receiver
6157
int channelId = receiver.getChannelId(); // get the channel id
6258
CommunicationIdentifier senderId = receiver.getSenderIdentifier(); // get the message sender id
@@ -68,26 +64,25 @@ DataChannelReceiverCreatedListener receiverCreatedListener = new DataChannelRece
6864
```
6965
2. Register the `receiverCreatedListener`.
7066
```java
71-
dataChannelCallFeature.addOnDataChannelReceiverCreatedListener(receiverCreatedListener);
67+
dataChannelCallFeature.addOnReceiverCreatedListener(receiverCreatedListener);
7268
```
73-
3. Define the DataChannelReceiverMessageReceivedListener.
69+
3. Define the MessageReceivedListener.
7470
```java
75-
DataChannelReceiverMessageReceivedListener messageReceivedListener = new DataChannelReceiverMessageReceivedListener() {
71+
MessageReceivedListener messageReceivedListener = new MessageReceivedListener() {
7672
@Override
77-
public void onMessageReceived(DataChannelReceiverMessageReceivedEvent e) {
78-
DataChannelMessage message = e.getReceiver().readMessage(); // read the data message from the receiver
73+
public void onMessageReceived(PropertyChangedEvent e) {
74+
DataChannelMessage message = e.getReceiver().popMessage(); // read the data message from the receiver
7975
int sequence = message.getSequenceNumber(); // get the message sequence number
8076
byte[] data = message.getData(); // get the data content
8177
}
8278
};
8379
```
84-
4. Define the DataChannelReceiverClosedListener.
80+
4. Define the ReceiverClosedListener.
8581
```java
86-
DataChannelReceiverClosedListener receiverClosedListener = new DataChannelReceiverClosedListener() {
82+
ReceiverClosedListener receiverClosedListener = new ReceiverClosedListener() {
8783
@Override
88-
public void onReceiverClosed(DataChannelReceiverClosedEvent e) {
84+
public void onReceiverClosed(PropertyChangedEvent e) {
8985
DataChannelReceiver receiver = e.getReceiver(); // get the data channel receiver to be closed
90-
// clean up resources related to the receiver
9186
}
9287
};
9388
```
@@ -97,9 +92,9 @@ receiver.addOnMessageReceivedListener(messageReceivedlistener);
9792
receiver.addOnClosedListener(receiverClosedListener);
9893
```
9994
#### Sending data message
100-
1. Configure the DataChannelSenderCreateOptions.
95+
1. Configure the DataChannelSenderOptions.
10196
```java
102-
DataChannelSenderCreateOptions options = new DataChannelSenderCreateOptions();
97+
DataChannelSenderOptions options = new DataChannelSenderOptions();
10398
options.setChannelId(1000);
10499
options.setBitrateInKbps(32);
105100
options.setPriority(DataChannelPriority.NORMAL);
@@ -108,9 +103,13 @@ options.setReliability(DataChannelReliability.LOSSY);
108103
List<CommunicationIdentifier> participants = Arrays.asList( /* identifier1, identifier2, ... */ );
109104
options.setParticipants(participants);
110105
```
111-
2. Define the DataChannelSender and send data message
106+
2. Get the DataChannelSender and send data message
112107
```java
113-
DataChannelSender dataChannelSender = dataChannelCallFeature.createDataChannelSender(options);
114-
dataChannelSender.setParticipants(new ArrayList<CommunicationIdentifier>()); // change participants in the channel if needed
115-
dataChannelSender.sendMessage(msgData); // msgData contains the byte[] data to be sent
108+
DataChannelSender dataChannelSender = dataChannelCallFeature.getDataChannelSender(options);
109+
110+
// msgData contains the byte[] data to be sent
111+
dataChannelSender.sendMessage(msgData);
112+
113+
// change participants in the channel if needed
114+
dataChannelSender.setParticipants(new ArrayList<CommunicationIdentifier>());
116115
```

articles/communication-services/quickstarts/voice-video-calling/includes/data-channel/data-channel-ios.md

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ titleSuffix: An Azure Communication Services document
55
description: In this quickstart, you learn how to add data channel messaging to your existing iOS calling app using Azure Communication Services.
66
author: sloanster
77
services: azure-communication-services
8-
ms.date: 05/04/2023
8+
ms.date: 03/01/2024
99
ms.topic: include
1010
ms.service: azure-communication-services
1111
ms.subservice: calling
@@ -25,18 +25,21 @@ Refer to the [Voice Calling Quickstart](../../getting-started-with-calling.md?pi
2525
| DataChannelCallFeature | Used to start and manage data channel feature. |
2626
| DataChannelSender | Used to manage a data channel as a sender and send data. |
2727
| DataChannelReceiver | Used to manage a data channel as a receiver and receive data. |
28-
| DataChannelSenderCreateOptions | Used for representing options to create a data channel sender. |
29-
### Delegates
30-
| Name | Description |
31-
| - | - |
32-
| didCreateDataChannelReceiver | Handles the event when a receiver is created. A new receiver is created when receiving a data message from another endpoint through a new data channel for the first time. |
33-
| didReceiveMessage | Handles the event when a data message is received and ready to be fetched. |
34-
| didClose | Handles the event when a data channel receiver is to be closed. |
28+
| DataChannelSenderOptions | Used for representing options to create a data channel sender. |
3529
### Enums
3630
| Name | Description |
3731
| - | - |
3832
| DataChannelPriority | Describes the priority options of data channel. Values: { `normal`, `high` }. |
3933
| DataChannelReliability | Describes the reliability options of data channel. Values: { `lossy`, `durable` }. |
34+
### Error Code
35+
| Name | Description |
36+
| - | - |
37+
| _dataChannelFailedToStart_ | `getDataChannelSender()` can fail with this error code, indicating underlying Data Channel is not ready to be used. |
38+
| _dataChannelRandomIdNotAvailable_ | `getDataChannelSender()` can fail with this error code, indicating all available random channel IDs have already been used. |
39+
| _dataChannelSenderClosed_ | `sendMessage()` can fail with this error code, indicating the sender has already been closed previously. |
40+
| _dataChannelMessageSizeOverLimit_ | `sendMessage()` can fail with this error code, indicating the message data size exceeds the limit. You can get the message size limit using `maxMessageSizeInBytes` in `DataChannelSender`. |
41+
| _dataChannelMessageFailureForBandwidth_ | `sendMessage()` can fail with this error code, indicating a failure in sending the message due to not enough bandwidth. |
42+
| _dataChannelMessageFailureForTrafficLimit_ | `sendMessage()` can fail with this error code, indicating a failure in sending the message due to the overall usage of Data Channel not in compliance with the traffic limit rules. Refer to [Data Channel Concept Document](../../../../concepts/voice-video-calling/data-channel.md) for details of the traffic limit. |
4043
### Methods
4144
#### Enable Data Channel feature
4245

@@ -47,41 +50,36 @@ var dataChannelCallFeature = self.call!.feature(Features.dataChannel)
4750
```
4851
#### Receiving data message
4952
```swift
50-
@State var callObserver:CallObserver?
51-
self.callObserver = CallObserver(view:self)
53+
let featureDelegate = new FeatureDelegate()
54+
let receiverDelegate = new ReceiverDelegate()
55+
dataChannelCallFeature!.delegate = featureDelegate
5256

53-
extension CallObserver: DataChannelCallFeatureDelegate {
54-
init(view:<nameOfView>) {
55-
owner = view
56-
super.init()
57-
}
58-
public func dataChannelCallFeature(_ dataChannelCallFeature: DataChannelCallFeature, didCreateDataChannelReceiver args: DataChannelReceiverCreatedEventArgs) {
59-
let dataChannelReceiver = e.receiver // get the new data channel receiver
60-
let channelId = dataChannelReceiver.channelId // get the channel id
61-
let senderId = dataChannelReceiver.senderIdentifier // get the message sender id
62-
dataChannelReceiver!.delegate = self;
57+
class FeatureDelegate: NSObject, DataChannelCallFeatureDelegate {
58+
func onReceiverCreated(_ dataChannelCallFeature: DataChannelCallFeature, didCreateReceiver args: DataChannelReceiverCreatedEventArgs) {
59+
let receiver = args.receiver // get the new data channel receiver
60+
let channelId = receiver.channelId // get the channel id
61+
let senderId = receiver.senderIdentifier // get the message sender id
62+
63+
receiver.delegate = receiverDelegate
6364
}
6465
}
6566

66-
extension CallObserver: DataChannelReceiverDelegate {
67-
public func dataChannelReceiver(_ dataChannelReceiver: DataChannelReceiver, didReceiveMessage args: DataChannelReceiverMessageReceivedEventArgs) {
68-
let message = args.receiver.readMessage() // read the data message from the receiver
69-
let sequence = message.sequenceNumber // get the message sequence number
70-
let data = message.data // get the data content
67+
class ReceiverDelegate: NSObject, DataChannelReceiverDelegate {
68+
func onMessageReceived(_ dataChannelReceiver: DataChannelReceiver, didReceiveMessage args: PropertyChangedEventArgs) {
69+
let message = dataChannelReceiver.popMessage() // read the data message from the receiver
70+
let sequence = message?.sequenceNumber // get the message sequence number
71+
let data = message?.data // get the data content
7172
}
7273

73-
public func dataChannelReceiver(_ dataChannelReceiver: DataChannelReceiver, didClose args: DataChannelReceiverClosedEventArgs) {
74-
let receiver = args.receiver // get the data channel receiver to be closed
75-
// clean up resources related to the receiver
74+
func onClosed(_ dataChannelReceiver: DataChannelReceiver, didClose args: PropertyChangedEventArgs) {
75+
let channelId = dataChannelReceiver.channelId // get the data channel id to be closed
7676
}
7777
}
78-
79-
dataChannelCallFeature!.delegate = self.callObserver
8078
```
8179
#### Sending data message
82-
1. Configure the DataChannelSenderCreateOptions.
80+
1. Configure the DataChannelSenderOptions.
8381
```swift
84-
let options = new DataChannelSenderCreateOptions()
82+
let options = new DataChannelSenderOptions()
8583
options.channelId = 1000
8684
options.bitrateInKbps = 32
8785
options.priority = DataChannelPriority.normal
@@ -92,8 +90,12 @@ options.participants = communicationIdentifiers
9290
```
9391
2. Define the DataChannelSender and send data message
9492
```swift
95-
DataChannelSender dataChannelSender = dataChannelCallFeature.createDataChannelSender(options)
93+
DataChannelSender sender = dataChannelCallFeature.getDataChannelSender(options)
94+
95+
// msgData contains the data to be sent
96+
sender.sendMessage(msgData)
97+
98+
// change participants in the channel if needed
9699
let participants: [CommunicationIdentifier] = []
97-
dataChannelSender.setParticipants(participants: participants) // change participants in the channel if needed
98-
dataChannelSender.sendMessage(msgData) // msgData contains the data to be sent
100+
dataChannelSender.setParticipants(participants: participants)
99101
```

0 commit comments

Comments
 (0)