Skip to content

Commit 20429f7

Browse files
authored
Merge pull request #224260 from sloanster/patch-13
Update raw-media-access-javascript.md
2 parents f743a37 + 6d77cd3 commit 20429f7

File tree

1 file changed

+136
-16
lines changed

1 file changed

+136
-16
lines changed

articles/communication-services/quickstarts/voice-video-calling/includes/raw-media/raw-media-access-javascript.md

Lines changed: 136 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@
22
title: Quickstart - Add RAW media access to your app (Web)
33
titleSuffix: An Azure Communication Services quickstart
44
description: In this quickstart, you'll learn how to add raw media access calling capabilities to your app using Azure Communication Services.
5-
author: Filippos Zampounis
5+
author: sloanster
66

7-
ms.author: fizampou
8-
ms.date: 07/05/2022
7+
ms.author: micahvivion
8+
ms.date: 1/17/2023
99
ms.topic: quickstart
1010
ms.service: azure-communication-services
1111
ms.subservice: calling
1212
ms.custom: mode-other
1313
---
1414

15-
Raw audio media gives access to the incoming call audio stream and send custom outgoing audio stream during a call.
15+
As a developer you can access the raw media for incoming and outgoing audio and video media content during a call. Access to ACS client side Raw audio and video enables developers an almost unlimited array of ability to view and edit audio and video content that happens within the ACS calling SDK. In this quickstart, you'll learn how to implement raw media access using the Azure Communication Services calling SDK for WebJS.
1616

17-
## Place a call with custom audio stream
17+
## Prerequisites
18+
[!INCLUDE [Public Preview](../../../../includes/public-preview-include-document.md)]
1819

20+
>[!IMPORTANT]
21+
> The quick start examples here are available starting on the public preview version [1.9.1-beta.1](https://www.npmjs.com/package/@azure/communication-calling/v/1.9.1-beta.1) of the calling Web SDK. Make sure to use that version or newer when trying this quickstart.
22+
23+
## Accessing Raw audio
24+
Accessing Raw audio media gives access to the incoming call audio stream and the ability to view and send custom outgoing audio stream during a call.
25+
26+
### Place a call with custom audio stream
1927
Developers can start a call with a custom audio stream instead of using user's microphone device.
2028

2129
```js
@@ -44,8 +52,7 @@ const callOptions = {
4452
callAgent.startCall(userId, callOptions);
4553
```
4654

47-
## Switch to custom audio stream during a call
48-
55+
### How to switch to a custom audio stream during a call
4956
Developers can switch input device to a custom audio stream instead of using user's microphone device during a call.
5057

5158
```js
@@ -78,26 +85,139 @@ callStateChangedHandler();
7885
call.on('stateChanged', callStateChangedHandler);
7986
```
8087

81-
## Stop custom audio stream
82-
88+
### Stopping the custom audio stream
8389
Developers can stop sending the custom audio stream after it has been set during a call.
8490

8591
```js
8692
call.stopAudio();
8793
```
8894

89-
## Incoming audio stream
90-
95+
### Accessing the incoming raw audio stream
9196
Developers can access the incoming call audio stream.
9297

9398
```js
9499
const call = callAgent.startCall(userId);
95100
const callStateChangedHandler = () => {
96-
if (call.state === "Connected") {
97-
const remoteAudioStream = call.remoteAudioStreams[0];
98-
const mediaStreamTrack = remoteAudioStream.getMediaStreamTrack();
99-
// process the incoming call audio media stream track
100-
}
101+
if (call.state === "Connected") {
102+
const remoteAudioStream = call.remoteAudioStreams[0];
103+
const mediaStreamTrack = remoteAudioStream.getMediaStreamTrack();
104+
// process the incoming call audio media stream track
105+
}
106+
};
107+
108+
callStateChangedHandler();
109+
call.on("stateChanged", callStateChangedHandler);
110+
```
111+
112+
## Accessing Raw video
113+
Raw video media gives you the instance of MediaStream object (See JavaScript documentation for further reference). Raw video media gives access specifically to incoming and outgoing call MediaStream object. For Raw Video, developers can use the incoming and outgoing raw MediaStream to apply filters by using Machine Learning to process frames of the video.
114+
115+
Processed Raw outgoing video frames can be sent as an outgoing video of the sender. Processed Raw incoming video frames can be rendered on receiver side.
116+
117+
### Place a call with custom video stream
118+
119+
Developers can access the raw outgoing call video stream. Developers have access to MediaStream of the outgoing raw video stream on which they can process frames using Machine Learning and apply filters.
120+
The processed outgoing video can then be sent as sender video stream.
121+
122+
In this example a user is sent canvas data as outgoing video.
123+
124+
```js
125+
const createVideoMediaStreamToSend = () => {
126+
const canvas = document.createElement('canvas');
127+
const ctx = canvas.getContext('2d');
128+
canvas.width = 1500;
129+
canvas.height = 845;
130+
ctx.fillStyle = 'blue';
131+
ctx.fillRect(0, 0, canvas.width, canvas.height);
132+
133+
const colors = ['red', 'yellow', 'green'];
134+
window.setInterval(() => {
135+
if (ctx) {
136+
ctx.fillStyle = colors[Math.floor(Math.random() * colors.length)];
137+
const x = Math.floor(Math.random() * canvas.width);
138+
const y = Math.floor(Math.random() * canvas.height);
139+
const size = 100;
140+
ctx.fillRect(x, y, size, size);
141+
}
142+
}, 1000 / 30);
143+
144+
return canvas.captureStream(30);
145+
};
146+
147+
...
148+
const userId = 'acs_user_id';
149+
const mediaStream = createVideoMediaStreamToSend();
150+
const localVideoStream = new LocalVideoStream(mediaStream);
151+
const callOptions = {
152+
videoOptions: {
153+
localVideoStreams: [localVideoStream]
154+
}
155+
};
156+
callAgent.startCall(userId, callOptions);
157+
```
158+
159+
### Switch to custom video stream during a call
160+
Developers can switch input device to a custom video stream instead of using user's camera device during a call.
161+
162+
```js
163+
const createVideoMediaStreamToSend = () => {
164+
const canvas = document.createElement('canvas');
165+
const ctx = canvas.getContext('2d');
166+
canvas.width = 1500;
167+
canvas.height = 845;
168+
ctx.fillStyle = 'blue';
169+
ctx.fillRect(0, 0, canvas.width, canvas.height);
170+
171+
const colors = ['red', 'yellow', 'green'];
172+
window.setInterval(() => {
173+
if (ctx) {
174+
ctx.fillStyle = colors[Math.floor(Math.random() * colors.length)];
175+
const x = Math.floor(Math.random() * canvas.width);
176+
const y = Math.floor(Math.random() * canvas.height);
177+
const size = 100;
178+
ctx.fillRect(x, y, size, size);
179+
}
180+
}, 1000 / 30);
181+
182+
return canvas.captureStream(30);
183+
};
184+
185+
...
186+
187+
const userId = 'acs_user_id';
188+
const call = callAgent.startCall(userId);
189+
const callStateChangedHandler = () => {
190+
if (call.state === 'Connected') {
191+
const mediaStream = createVideoMediaStreamToSend();
192+
const localVideoStream = this.call.localVideoStreams[0];
193+
localVideoStream.setMediaStream(mediaStream);
194+
}
195+
};
196+
197+
callStateChangedHandler();
198+
call.on('stateChanged', callStateChangedHandler);
199+
```
200+
201+
### Stop custom video stream
202+
Developers can stop sending the custom video stream after it has been set during a call.
203+
204+
```js
205+
call.stopVideo();
206+
```
207+
208+
### Incoming video stream
209+
Developers can access the raw incoming call video stream. Developers can also access the MediaStream of the incoming raw video stream and process frames using Machine Learning and apply filters.
210+
The processed incoming video can then be rendered on receiver side.
211+
212+
```js
213+
const userId = 'acs_user_id';
214+
const call = callAgent.startCall(userId);
215+
const callStateChangedHandler = () => {
216+
if (call.state === "Connected") {
217+
const remoteVideoStream = remoteParticipants[0].videoStreams[0];
218+
const mediaStream = remoteVideoStream.getMediaStream();
219+
// process the incoming call video media stream
220+
}
101221
};
102222

103223
callStateChangedHandler();

0 commit comments

Comments
 (0)