Skip to content

Commit 72d6153

Browse files
Update acs calling native sdk data channel docs
1 parent e6e63a3 commit 72d6153

File tree

3 files changed

+65
-87
lines changed

3 files changed

+65
-87
lines changed

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

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@ 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-
### 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`. |
28+
| DataChannelSenderOptions | Used for representing options to create a data channel sender. |
4129
### Enums
4230
| Name | Description |
4331
| - | - |
@@ -56,7 +44,7 @@ DataChannelCallFeature dataChannelCallFeature = call.feature(Features.DATA_CHANN
5644
```java
5745
DataChannelReceiverCreatedListener receiverCreatedListener = new DataChannelReceiverCreatedListener() {
5846
@Override
59-
public void onDataChannelReceiverCreated(DataChannelReceiverCreatedEvent e) {
47+
public void onReceiverCreated(DataChannelReceiverCreatedEvent e) {
6048
DataChannelReceiver receiver = e.getReceiver(); // get the new data channel receiver
6149
int channelId = receiver.getChannelId(); // get the channel id
6250
CommunicationIdentifier senderId = receiver.getSenderIdentifier(); // get the message sender id
@@ -68,26 +56,25 @@ DataChannelReceiverCreatedListener receiverCreatedListener = new DataChannelRece
6856
```
6957
2. Register the `receiverCreatedListener`.
7058
```java
71-
dataChannelCallFeature.addOnDataChannelReceiverCreatedListener(receiverCreatedListener);
59+
dataChannelCallFeature.addOnReceiverCreatedListener(receiverCreatedListener);
7260
```
73-
3. Define the DataChannelReceiverMessageReceivedListener.
61+
3. Define the MessageReceivedListener.
7462
```java
75-
DataChannelReceiverMessageReceivedListener messageReceivedListener = new DataChannelReceiverMessageReceivedListener() {
63+
MessageReceivedListener messageReceivedListener = new MessageReceivedListener() {
7664
@Override
77-
public void onMessageReceived(DataChannelReceiverMessageReceivedEvent e) {
78-
DataChannelMessage message = e.getReceiver().readMessage(); // read the data message from the receiver
65+
public void onMessageReceived(PropertyChangedEvent e) {
66+
DataChannelMessage message = e.getReceiver().popMessage(); // read the data message from the receiver
7967
int sequence = message.getSequenceNumber(); // get the message sequence number
8068
byte[] data = message.getData(); // get the data content
8169
}
8270
};
8371
```
84-
4. Define the DataChannelReceiverClosedListener.
72+
4. Define the ReceiverClosedListener.
8573
```java
86-
DataChannelReceiverClosedListener receiverClosedListener = new DataChannelReceiverClosedListener() {
74+
ReceiverClosedListener receiverClosedListener = new ReceiverClosedListener() {
8775
@Override
88-
public void onReceiverClosed(DataChannelReceiverClosedEvent e) {
76+
public void onReceiverClosed(PropertyChangedEvent e) {
8977
DataChannelReceiver receiver = e.getReceiver(); // get the data channel receiver to be closed
90-
// clean up resources related to the receiver
9178
}
9279
};
9380
```
@@ -97,9 +84,9 @@ receiver.addOnMessageReceivedListener(messageReceivedlistener);
9784
receiver.addOnClosedListener(receiverClosedListener);
9885
```
9986
#### Sending data message
100-
1. Configure the DataChannelSenderCreateOptions.
87+
1. Configure the DataChannelSenderOptions.
10188
```java
102-
DataChannelSenderCreateOptions options = new DataChannelSenderCreateOptions();
89+
DataChannelSenderOptions options = new DataChannelSenderOptions();
10390
options.setChannelId(1000);
10491
options.setBitrateInKbps(32);
10592
options.setPriority(DataChannelPriority.NORMAL);
@@ -108,9 +95,13 @@ options.setReliability(DataChannelReliability.LOSSY);
10895
List<CommunicationIdentifier> participants = Arrays.asList( /* identifier1, identifier2, ... */ );
10996
options.setParticipants(participants);
11097
```
111-
2. Define the DataChannelSender and send data message
98+
2. Get the DataChannelSender and send data message
11299
```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
100+
DataChannelSender dataChannelSender = dataChannelCallFeature.getDataChannelSender(options);
101+
102+
// msgData contains the byte[] data to be sent
103+
dataChannelSender.sendMessage(msgData);
104+
105+
// change participants in the channel if needed
106+
dataChannelSender.setParticipants(new ArrayList<CommunicationIdentifier>());
116107
```

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

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ 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
| - | - |
@@ -47,41 +41,36 @@ var dataChannelCallFeature = self.call!.feature(Features.dataChannel)
4741
```
4842
#### Receiving data message
4943
```swift
50-
@State var callObserver:CallObserver?
51-
self.callObserver = CallObserver(view:self)
44+
let featureDelegate = new FeatureDelegate()
45+
let receiverDelegate = new ReceiverDelegate()
46+
dataChannelCallFeature!.delegate = featureDelegate
5247

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;
48+
class FeatureDelegate: NSObject, DataChannelCallFeatureDelegate {
49+
func onReceiverCreated(_ dataChannelCallFeature: DataChannelCallFeature, didCreateReceiver args: DataChannelReceiverCreatedEventArgs) {
50+
let receiver = args.receiver // get the new data channel receiver
51+
let channelId = receiver.channelId // get the channel id
52+
let senderId = receiver.senderIdentifier // get the message sender id
53+
54+
receiver.delegate = receiverDelegate
6355
}
6456
}
6557

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
58+
class ReceiverDelegate: NSObject, DataChannelReceiverDelegate {
59+
func onMessageReceived(_ dataChannelReceiver: DataChannelReceiver, didReceiveMessage args: PropertyChangedEventArgs) {
60+
let message = dataChannelReceiver.popMessage() // read the data message from the receiver
61+
let sequence = message?.sequenceNumber // get the message sequence number
62+
let data = message?.data // get the data content
7163
}
7264

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
65+
func onClosed(_ dataChannelReceiver: DataChannelReceiver, didClose args: PropertyChangedEventArgs) {
66+
let channelId = dataChannelReceiver.channelId // get the data channel id to be closed
7667
}
7768
}
78-
79-
dataChannelCallFeature!.delegate = self.callObserver
8069
```
8170
#### Sending data message
82-
1. Configure the DataChannelSenderCreateOptions.
71+
1. Configure the DataChannelSenderOptions.
8372
```swift
84-
let options = new DataChannelSenderCreateOptions()
73+
let options = new DataChannelSenderOptions()
8574
options.channelId = 1000
8675
options.bitrateInKbps = 32
8776
options.priority = DataChannelPriority.normal
@@ -92,8 +81,12 @@ options.participants = communicationIdentifiers
9281
```
9382
2. Define the DataChannelSender and send data message
9483
```swift
95-
DataChannelSender dataChannelSender = dataChannelCallFeature.createDataChannelSender(options)
84+
DataChannelSender sender = dataChannelCallFeature.getDataChannelSender(options)
85+
86+
// msgData contains the data to be sent
87+
sender.sendMessage(msgData)
88+
89+
// change participants in the channel if needed
9690
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
91+
dataChannelSender.setParticipants(participants: participants)
9992
```

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ 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-
### Events
30-
| Name | Description |
31-
| - | - |
32-
| DataChannelReceiverCreated | 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-
| DataChannelReceiverMessageReceived | Describes the event when a data message is received and ready to be fetched. |
34-
| DataChannelReceiverClosed | Describes 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
| - | - |
@@ -61,23 +55,22 @@ void DataChannelReceiverCreatedHandler(object sender, DataChannelReceiverCreated
6155
```
6256
2. Attach the `DataChannelReceiverCreatedHandler`.
6357
```csharp
64-
dataChannelCallFeature.DataChannelReceiverCreated += DataChannelReceiverCreatedHandler;
58+
dataChannelCallFeature.ReceiverCreated += DataChannelReceiverCreatedHandler;
6559
```
66-
3. Define the DataChannelReceiverMessageReceived event handler.
60+
3. Define the MessageReceived event handler.
6761
```csharp
68-
void MessageReceivedHandler(object sender, DataChannelReceiverMessageReceivedEventArgs args)
62+
void MessageReceivedHandler(object sender, PropertyChangedEventArgs args)
6963
{
70-
DataChannelMessage message = args.Receiver.ReadMessage(); // read the data message from the receiver
71-
uint sequence = message.SequenceNumber; // get the message sequence number
64+
DataChannelMessage message = (sender as DataChannelReceiver).PopMessage(); // read the data message from the receiver
65+
long sequence = message.SequenceNumber; // get the message sequence number
7266
byte[] data = message.Data; // get the data content
7367
}
7468
```
75-
4. Define the DataChannelReceiverClosed event handler.
69+
4. Define the Closed event handler.
7670
```csharp
77-
void ReceiverClosedHandler(object sender, DataChannelReceiverClosedEventArgs args)
71+
void ReceiverClosedHandler(object sender, PropertyChangedEventArgs args)
7872
{
79-
DataChannelReceiver receiver = ergs.Receiver; // get the data channel receiver to be closed
80-
// clean up resources related to the receiver
73+
DataChannelReceiver receiver = sender as DataChannelReceiver; // get the data channel receiver to be closed
8174
};
8275
```
8376
5. Attach the `MessageReceivedHandler` and `ReceiverClosedHandler`.
@@ -86,20 +79,21 @@ receiver.MessageReceived += MessageReceivedHandler;
8679
receiver.Closed += ReceiverClosedHandler;
8780
```
8881
#### Sending data message
89-
1. Configure the DataChannelSenderCreateOptions.
82+
1. Configure the DataChannelSenderOptions.
9083
```csharp
91-
DataChannelSenderCreateOptions options = new DataChannelSenderCreateOptions();
84+
DataChannelSenderOptions options = new DataChannelSenderOptions();
9285
options.ChannelId = 1000;
9386
options.BitrateInKbps = 32;
94-
options.Priority = DataChannelPriority.NORMAL;
95-
options.Reliability = DataChannelReliability.LOSSY;
87+
options.Priority = DataChannelPriority.Normal;
88+
options.Reliability = DataChannelReliability.Lossy;
9689
var participants = new List<CallIdentifier> { /* identifier1, identifier2, ... */ };
9790
options.Participants = participants.AsReadOnly();
9891
```
9992
2. Define the DataChannelSender and send data message
10093
```csharp
101-
DataChannelSender dataChannelSender = dataChannelCallFeature.CreateDataChannelSender(options);
102-
dataChannelSender.SetParticipants(new List<CallIdentifier>().AsReadOnly()); // change participants in the channel if needed
103-
dataChannelSender.SendMessageAsync(msgData); // msgData contains the byte[] data to be sent
104-
94+
DataChannelSender sender = dataChannelCallFeature.GetDataChannelSender(options);
95+
// msgData contains the byte[] data to be sent
96+
sender.SendMessage(msgData);
97+
// change participants in the channel if needed
98+
sender.SetParticipants(new List<CallIdentifier>().AsReadOnly());
10599
```

0 commit comments

Comments
 (0)