Skip to content

Commit f036ec3

Browse files
authored
Merge pull request #224417 from sharifrahaman/acs-live-stream
ACS Live Stream
2 parents 5475be5 + 9bb2a94 commit f036ec3

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Quickstart - Add live stream to your app
3+
titleSuffix: An Azure Communication Services quickstart
4+
description: In this quickstart, you'll learn how to add live stream calling capabilities to your app using Azure Communication Services.
5+
author: sharifrahaman
6+
services: azure-communication-services
7+
8+
ms.author: srahaman
9+
ms.date: 06/30/2022
10+
ms.topic: quickstart
11+
ms.service: azure-communication-services
12+
ms.subservice: calling
13+
ms.custom: mode-other
14+
---
15+
16+
# Live stream quick start
17+
18+
Live streaming will empower Contoso to engage thousands of online attendees by adding interactive live audio and video streaming functionality into their web and
19+
mobile applications that their audiences will love, no matter where they are. Interactive Live Streaming is the ability to broadcast media content to thousands of online
20+
attendees while enabling some attendees to share their live audio and video, interact via chat, and engage with metadata content such as reactions, polls, quizzes, ads, etc.
21+
22+
## Prerequisites
23+
[!INCLUDE [Public Preview](../../includes/private-preview-include-section.md)]
24+
25+
- [Rooms](../rooms/get-started-rooms.md) meeting will be needed for role-based streaming.
26+
- The quick start examples here are available with the private preview version [1.11.0-alpha.20230124.1](https://www.npmjs.com/package/@azure/communication-calling/v/1.11.0-alpha.20230124.1) of the calling Web SDK. Make sure to use that or higher version when trying this quick start.
27+
28+
## Live streaming with Rooms
29+
Room participants can be assigned one of the following roles: **Presenter**, **Attendee** and **Consumer**. By default, a user is assigned an **Consumer** role, if no other role is assigned.
30+
31+
Participants with `Consumer` role will be receiving only the live stream. They won't be able to speak or share video or screen. Developers shouldn't show the unmute, share video, and screen option to end users/consumers. Live stream supports both open and closed Rooms. In Open Rooms the default role is `Consumer`.
32+
On the other hand, Participants with other roles receive both real-time and live stream. Developers can choose either stream to play.
33+
Check [participant roles and permissions](../../concepts/rooms/room-concept.md#predefined-participant-roles-and-permissions) to know more about the roles capabilities.
34+
35+
### Place a Rooms call (start live streaming)
36+
Live streaming will start when the Rooms call starts.
37+
38+
```js
39+
const context = { roomId: '<RoomId>' }
40+
41+
const call = callAgent.join(context);
42+
```
43+
44+
### Receive live stream
45+
Contoso can use the `Features.LiveStream` to get the live stream and play it.
46+
47+
```typescript
48+
call.feature(Features.LiveStream).on('liveStreamsUpdated', e => {
49+
// Subscribe to new live video streams that were added.
50+
e.added.forEach(liveVideoStream => {
51+
subscribeToLiveVideoStream(liveVideoStream)
52+
});
53+
// Unsubscribe from live video streams that were removed.
54+
e.removed.forEach(liveVideoStream => {
55+
console.log('Live video stream was removed.');
56+
}
57+
);
58+
59+
const subscribeToLiveVideoStream = async (liveVideoStream) => {
60+
// Create a video stream renderer for the live video stream.
61+
let videoStreamRenderer = new VideoStreamRenderer(liveVideoStream);
62+
let view;
63+
const renderVideo = async () => {
64+
try {
65+
// Create a renderer view for the live video stream.
66+
view = await videoStreamRenderer.createView();
67+
// Attach the renderer view to the UI.
68+
liveVideoContainer.hidden = false;
69+
liveVideoContainer.appendChild(view.target);
70+
} catch (e) {
71+
console.warn(`Failed to createView, reason=${e.message}, code=${e.code}`);
72+
}
73+
}
74+
75+
// Live video stream is available during initialization.
76+
await renderVideo();
77+
};
78+
79+
```
80+
81+
### Count participants in both real-time and streaming media lane
82+
Web SDK already exposes `Call.totalParticipantCount` (available in beta release) which includes all participants count (Presenter, Attendee, Consumer, Participants in the lobby etc.). We've added a new API `Call.feature(Features.LiveStream).participantCount` under the `LiveStream` feature to have the count of streaming participants. `Call.feature(Features.LiveStream).participantCount` represents the number of participants receiving the streaming media only.
83+
84+
```typescript
85+
call.feature(Features.LiveStream).on('participantCountChanged', e => {
86+
// Get current streaming participant count.
87+
Call.feature(Features.LiveStream).participantCount;
88+
);
89+
```
90+
91+
`call.feature(Features.LiveStream).participantCount` represents the total count of participants in streaming media lane. Contoso can find out the count of participants in real-time media lane by subtracting from the total participants. So, number of real-time media participants = `call.totalParticipantCount` - `call.feature(Features.LiveStream).participantCount`.
92+
93+
## Next steps
94+
For more information, see the following articles:
95+
96+
- Check out our [calling hero sample](../../samples/calling-hero-sample.md)
97+
- Get started with the [UI Library](https://aka.ms/acsstorybook)
98+
- Learn about [Calling SDK capabilities](./getting-started-with-calling.md?pivots=platform-web)
99+
- Learn more about [how calling works](../../concepts/voice-video-calling/about-call-types.md)

0 commit comments

Comments
 (0)