|
2 | 2 | title: Quickstart - Add RAW media access to your app (Web)
|
3 | 3 | titleSuffix: An Azure Communication Services quickstart
|
4 | 4 | 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 |
6 | 6 |
|
7 |
| -ms.author: fizampou |
8 |
| -ms.date: 07/05/2022 |
| 7 | +ms.author: micahvivion |
| 8 | +ms.date: 1/17/2023 |
9 | 9 | ms.topic: quickstart
|
10 | 10 | ms.service: azure-communication-services
|
11 | 11 | ms.subservice: calling
|
12 | 12 | ms.custom: mode-other
|
13 | 13 | ---
|
14 | 14 |
|
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. |
16 | 16 |
|
17 |
| -## Place a call with custom audio stream |
| 17 | +## Prerequisites |
| 18 | +[!INCLUDE [Public Preview](../../../../includes/public-preview-include-document.md)] |
18 | 19 |
|
| 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 |
19 | 27 | Developers can start a call with a custom audio stream instead of using user's microphone device.
|
20 | 28 |
|
21 | 29 | ```js
|
@@ -44,8 +52,7 @@ const callOptions = {
|
44 | 52 | callAgent.startCall(userId, callOptions);
|
45 | 53 | ```
|
46 | 54 |
|
47 |
| -## Switch to custom audio stream during a call |
48 |
| - |
| 55 | +### How to switch to a custom audio stream during a call |
49 | 56 | Developers can switch input device to a custom audio stream instead of using user's microphone device during a call.
|
50 | 57 |
|
51 | 58 | ```js
|
@@ -78,26 +85,139 @@ callStateChangedHandler();
|
78 | 85 | call.on('stateChanged', callStateChangedHandler);
|
79 | 86 | ```
|
80 | 87 |
|
81 |
| -## Stop custom audio stream |
82 |
| - |
| 88 | +### Stopping the custom audio stream |
83 | 89 | Developers can stop sending the custom audio stream after it has been set during a call.
|
84 | 90 |
|
85 | 91 | ```js
|
86 | 92 | call.stopAudio();
|
87 | 93 | ```
|
88 | 94 |
|
89 |
| -## Incoming audio stream |
90 |
| - |
| 95 | +### Accessing the incoming raw audio stream |
91 | 96 | Developers can access the incoming call audio stream.
|
92 | 97 |
|
93 | 98 | ```js
|
94 | 99 | const call = callAgent.startCall(userId);
|
95 | 100 | 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 | + } |
101 | 221 | };
|
102 | 222 |
|
103 | 223 | callStateChangedHandler();
|
|
0 commit comments