Skip to content

Commit 38a20f7

Browse files
Merge pull request #246615 from chengyuanlai-msft/dc-quickstart
Data Channel QuickStart for ACS Calling Native SDK
2 parents 84bde84 + 5084e8c commit 38a20f7

File tree

5 files changed

+342
-7
lines changed

5 files changed

+342
-7
lines changed

articles/communication-services/concepts/voice-video-calling/data-channel.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ The Data Channel API enables real-time messaging during audio and video calls. W
3232

3333
## Common use cases
3434

35-
These are two common use cases:
35+
The Data Channel feature has two common use cases:
3636

3737
### Messaging between participants in a call
3838

3939
The Data Channel API enables the transmission of binary type messages among call participants.
4040
With appropriate serialization in the application, it can deliver various message types for different purposes.
41-
There are also other liberies or services providing the messaging functionalities.
41+
There are also other libraries or services providing the messaging functionalities.
4242
Each of them has its advantages and disadvantages. You should choose the suitable one for your usage scenario.
43-
For example, the Data Channel API offers the advantage of low-latency communication, and simplifies user management as there is no need to maintain a separate participant list.
43+
For example, the Data Channel API offers the advantage of low-latency communication, and simplifies user management as there's no need to maintain a separate participant list.
4444
However, the data channel feature doesn't provide message persistence and doesn't guarantee that message won't be lost in an end-to-end manner.
4545
If you need the stateful messaging or guaranteed delivery, you may want to consider alternative solutions.
4646

@@ -78,7 +78,7 @@ Upon creation, a channel can be configured to be one of the two Reliability opti
7878

7979
A `lossy` channel means the order of messages isn't guaranteed and a message can be silently dropped when sending fails. It generally affords a faster data transfer speed.
8080

81-
A `durable` channel means the SDK guarantees a lossless and ordered message delivery. In cases when a message can't be delivered, an exception will be thrown by the SDK.
81+
A `durable` channel means the SDK guarantees a lossless and ordered message delivery. In cases when a message can't be delivered, the SDK will throw an exception.
8282
In the Web SDK, the durability of the channel is ensured through a reliable SCTP connection. However, it doesn't imply that message won't be lost in an end-to-end manner.
8383
In the context of a group call, it signifies the prevention of message loss between the sender and server.
8484
In a peer-to-peer call, it denotes reliable transmission between the sender and remote endpoint.
@@ -105,7 +105,7 @@ Upon creating a sender object with a new channelId, the sender object is in open
105105
If the `close()` API is invoked on the sender object, the session becomes closed and can no longer facilitate message sending.
106106
At the same time, the sender object notifies all participants in the call that the session is closed.
107107

108-
If a sender object is created with an already existing channelId, the existing sender object associated with the channelId will be closed and any messages sent from the newly created sender object will be recognized as part of a new session.
108+
If a sender object is created with an already existing channelId, the existing sender object associated with the channelId will be closed and any messages sent from the newly created sender object will be recognized as part of the new session.
109109

110110
From the receiver's perspective, messages coming from different sessions on the sender's side are directed to distinct receiver objects.
111111
If the SDK identifies a new session associated with an existing channelId on the receiver's side, it creates a new receiver object.
@@ -123,7 +123,7 @@ For instance, consider a scenario where a sender sends three messages. Initially
123123
## Limitations
124124

125125
### Message size
126-
The maximum allowable size for a single message is 32 KB. If you need to send data larger than this limit, you'll need to divide the data into multiple messages.
126+
The maximum allowable size for a single message is 32 KB. If you need to send data larger than the limit, you'll need to divide the data into multiple messages.
127127

128128
### Participant list
129129
The maximum number of participants in a list is limited to 64. If you want to specify more participants, you'll need to manage participant list on your own. For example, if you want to send a message to 50 participants, you can create two different channels, each with 25 participants in their recipient lists.

articles/communication-services/quickstarts/voice-video-calling/get-started-data-channel.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,31 @@ ms.date: 05/04/2023
99
ms.topic: quickstart
1010
ms.service: azure-communication-services
1111
ms.subservice: calling
12+
zone_pivot_groups: acs-plat-web-ios-android-windows
1213
ms.custom: mode-other, devx-track-js
1314
---
1415

1516
# Quickstart: Add Data Channel messaging to your calling app
1617

18+
::: zone pivot="platform-web"
1719
[!INCLUDE [Data Channel feature with JavaScript](./includes/data-channel/data-channel-javascript.md)]
20+
::: zone-end
21+
22+
::: zone pivot="platform-android"
23+
[!INCLUDE [Data Channel feature with Android](./includes/data-channel/data-channel-android.md)]
24+
::: zone-end
25+
26+
::: zone pivot="platform-ios"
27+
[!INCLUDE [Data Channel feature with iOS](./includes/data-channel/data-channel-ios.md)]
28+
::: zone-end
29+
30+
::: zone pivot="platform-windows"
31+
[!INCLUDE [Data Channel feature with Windows](./includes/data-channel/data-channel-windows.md)]
32+
::: zone-end
1833

1934
## Next steps
2035

2136
For more information, see the following articles:
2237

2338
- Learn about [Data Channel feature concept document](../../concepts/voice-video-calling/data-channel.md)
24-
- Learn more about [Calling SDK capabilities](./getting-started-with-calling.md?pivots=platform-web)
39+
- Learn more about [Calling SDK capabilities](./getting-started-with-calling.md)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
ms.author: chengyuanlai
3+
title: Quickstart - Add data channel to your Android calling app
4+
titleSuffix: An Azure Communication Services document
5+
description: In this quickstart, you learn how to add data channel messaging to your existing Android calling app using Azure Communication Services.
6+
author: sloanster
7+
services: azure-communication-services
8+
ms.date: 05/04/2023
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
ms.subservice: calling
12+
---
13+
14+
[!INCLUDE [Public Preview](../../../../includes/public-preview-include-document.md)]
15+
>[!IMPORTANT]
16+
> 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.
17+
18+
## Overview
19+
The Data Channel feature API enables real-time data messaging during audio and video calls. In this quickstart guide, we illustrate how to integrate Data Channel feature to your call and use the Data Channel APIs to send and receive data messages through a data channel.
20+
### Prerequisites
21+
Refer to the [Voice Calling Quickstart](../../getting-started-with-calling.md?pivots=platform-android) to set up a sample app with voice calling.
22+
### Classes
23+
| Name | Description |
24+
| - | - |
25+
| DataChannelCallFeature | Used to start and manage data channel feature. |
26+
| DataChannelSender | Used to manage a data channel as a sender and send data. |
27+
| 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`. |
41+
### Enums
42+
| Name | Description |
43+
| - | - |
44+
| DataChannelPriority | Describes the priority options of data channel. Values: { `NORMAL`, `HIGH` }. |
45+
| DataChannelReliability | Describes the reliability options of data channel. Values: { `LOSSY`, `DURABLE` }. |
46+
### Methods
47+
#### Enable Data Channel feature
48+
49+
1. Get the ongoing call object established during the prerequisite steps.
50+
2. Get the Data Channel Feature object.
51+
```java
52+
DataChannelCallFeature dataChannelCallFeature = call.feature(Features.DATA_CHANNEL);
53+
```
54+
#### Receiving data message
55+
1. Define the DataChannelReceiverCreatedListener.
56+
```java
57+
DataChannelReceiverCreatedListener receiverCreatedListener = new DataChannelReceiverCreatedListener() {
58+
@Override
59+
public void onDataChannelReceiverCreated(DataChannelReceiverCreatedEvent e) {
60+
DataChannelReceiver receiver = e.getReceiver(); // get the new data channel receiver
61+
int channelId = receiver.getChannelId(); // get the channel id
62+
CommunicationIdentifier senderId = receiver.getSenderIdentifier(); // get the message sender id
63+
// listen to the message received event and closed event from this receiver
64+
// receiver.addOnMessageReceivedListener(messageReceivedlistener);
65+
// receiver.addOnClosedListener(receiverClosedListener);
66+
}
67+
};
68+
```
69+
2. Register the `receiverCreatedListener`.
70+
```java
71+
dataChannelCallFeature.addOnDataChannelReceiverCreatedListener(receiverCreatedListener);
72+
```
73+
3. Define the DataChannelReceiverMessageReceivedListener.
74+
```java
75+
DataChannelReceiverMessageReceivedListener messageReceivedListener = new DataChannelReceiverMessageReceivedListener() {
76+
@Override
77+
public void onMessageReceived(DataChannelReceiverMessageReceivedEvent e) {
78+
DataChannelMessage message = e.getReceiver().readMessage(); // read the data message from the receiver
79+
int sequence = message.getSequenceNumber(); // get the message sequence number
80+
byte[] data = message.getData(); // get the data content
81+
}
82+
};
83+
```
84+
4. Define the DataChannelReceiverClosedListener.
85+
```java
86+
DataChannelReceiverClosedListener receiverClosedListener = new DataChannelReceiverClosedListener() {
87+
@Override
88+
public void onReceiverClosed(DataChannelReceiverClosedEvent e) {
89+
DataChannelReceiver receiver = e.getReceiver(); // get the data channel receiver to be closed
90+
// clean up resources related to the receiver
91+
}
92+
};
93+
```
94+
5. Register the `messageReceivedListener` and `receiverClosedListener`.
95+
```java
96+
receiver.addOnMessageReceivedListener(messageReceivedlistener);
97+
receiver.addOnClosedListener(receiverClosedListener);
98+
```
99+
#### Sending data message
100+
1. Configure the DataChannelSenderCreateOptions.
101+
```java
102+
DataChannelSenderCreateOptions options = new DataChannelSenderCreateOptions();
103+
options.setChannelId(1000);
104+
options.setBitrateInKbps(32);
105+
options.setPriority(DataChannelPriority.NORMAL);
106+
options.setReliability(DataChannelReliability.LOSSY);
107+
108+
List<CommunicationIdentifier> participants = Arrays.asList( /* identifier1, identifier2, ... */ );
109+
options.setParticipants(participants);
110+
```
111+
2. Define the DataChannelSender and send data message
112+
```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
116+
```
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
ms.author: chengyuanlai
3+
title: Quickstart - Add data channel to your iOS calling app
4+
titleSuffix: An Azure Communication Services document
5+
description: In this quickstart, you learn how to add data channel messaging to your existing iOS calling app using Azure Communication Services.
6+
author: sloanster
7+
services: azure-communication-services
8+
ms.date: 05/04/2023
9+
ms.topic: include
10+
ms.service: azure-communication-services
11+
ms.subservice: calling
12+
---
13+
14+
[!INCLUDE [Public Preview](../../../../includes/public-preview-include-document.md)]
15+
>[!IMPORTANT]
16+
> 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.
17+
18+
## Overview
19+
The Data Channel feature API enables real-time data messaging during audio and video calls. In this quickstart guide, we illustrate how to integrate Data Channel feature to your call and use the Data Channel APIs to send and receive data messages through a data channel.
20+
### Prerequisites
21+
Refer to the [Voice Calling Quickstart](../../getting-started-with-calling.md?pivots=platform-ios) to set up a sample app with voice calling.
22+
### Classes
23+
| Name | Description |
24+
| - | - |
25+
| DataChannelCallFeature | Used to start and manage data channel feature. |
26+
| DataChannelSender | Used to manage a data channel as a sender and send data. |
27+
| 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. |
35+
### Enums
36+
| Name | Description |
37+
| - | - |
38+
| DataChannelPriority | Describes the priority options of data channel. Values: { `normal`, `high` }. |
39+
| DataChannelReliability | Describes the reliability options of data channel. Values: { `lossy`, `durable` }. |
40+
### Methods
41+
#### Enable Data Channel feature
42+
43+
1. Get the ongoing call object established during the prerequisite steps.
44+
2. Get the Data Channel Feature object.
45+
```swift
46+
var dataChannelCallFeature = self.call!.feature(Features.dataChannel)
47+
```
48+
#### Receiving data message
49+
```swift
50+
@State var callObserver:CallObserver?
51+
self.callObserver = CallObserver(view:self)
52+
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;
63+
}
64+
}
65+
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
71+
}
72+
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
76+
}
77+
}
78+
79+
dataChannelCallFeature!.delegate = self.callObserver
80+
```
81+
#### Sending data message
82+
1. Configure the DataChannelSenderCreateOptions.
83+
```swift
84+
let options = new DataChannelSenderCreateOptions()
85+
options.channelId = 1000
86+
options.bitrateInKbps = 32
87+
options.priority = DataChannelPriority.normal
88+
options.reliability = DataChannelReliability.lossy
89+
90+
let communicationIdentifiers: [CommunicationIdentifier] = [ /* identifier1, identifier2, ... */ ]
91+
options.participants = communicationIdentifiers
92+
```
93+
2. Define the DataChannelSender and send data message
94+
```swift
95+
DataChannelSender dataChannelSender = dataChannelCallFeature.createDataChannelSender(options)
96+
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
99+
```

0 commit comments

Comments
 (0)