|
1 | 1 | # OWT SDK with WebRTC APIs
|
2 | 2 | ## Introduction
|
3 | 3 | OWT(Open WebRTC Toolkit) Client SDKs provide convenient APIs to create, publish, and subscribe streams. Most of these APIs are wrappers of WebRTC APIs with signaling support. It helps WebRTC beginners easily involve WebRTC technology into their applications without too much knowledge of WebRTC evolution and browser differences. As WebRTC 1.0 is moving to PR, which means it is quite stable, we are planning to expose more WebRTC APIs to developers to enable advanced and custom usages with OWT.
|
4 |
| -## WebRTC APIs |
5 |
| -### RTCRtpTransceiver, RTCRtpSender, RTCRtpReceiver |
6 |
| -#### Potential Usages |
| 4 | +## Potential Usages |
7 | 5 | - Replace a track in the middle of a call.
|
8 | 6 | - Set custom encoding parameters, perhaps for simulcast.
|
9 | 7 | - Set preferred codecs.
|
10 | 8 | - Disable or enable RTX / RED / FEC.
|
11 |
| -#### API Changes |
| 9 | +## API Changes |
12 | 10 | - A new member `rtpTransceivers` will be added to `TransportSettings`. It returns an array `RTCRtpReceiver`s for RTP transport.
|
13 | 11 | - A new member `transport` will be added to `Publication` and `Subscription`. Developers could get `RTPTransceiver`s from its `rtpTransceivers` property.
|
14 |
| -- A new method `addTransceiver(DOMString trackKind, sequence<RTCRtpEncodingParameters> sendEncodings)` will be added to `ConferenceClient`. It invokes `RTCPeerConnection.addTransceiver(trackKind, {direction:inactive, sendEncodings:sendEncodings})`, returns an `RTCRtpTransceiver`. Please note that direction is `inactive` until a `publish` with return transceiver is called. |
15 |
| -- The second parameter of `ConferenceClient.publish` accepts an `RTCRtpTransceiver` created by `RTCPeerConnection.addTransceiver`. When this method is called, certain `RTCRtpTransceiver`'s direction is changed to `sendonly`, and its sender's `setStreams` is called with the first parameter's `mediaStream`. |
16 |
| -#### Server Requirements |
| 12 | +- A new member `peerConnection` will be added to `ConferenceClient` for developers to get the `PeerConnection`. |
| 13 | +- The second parameter of `ConferenceClient.publish` accepts an `RTCRtpTransceiver` created by `RTCPeerConnection.addTransceiver`. `RTCRtpTransceiver`s' direction must be `sendonly`, and its sender's `setStreams` is called with the first parameter's `mediaStream`. |
| 14 | +## Server Requirements |
17 | 15 | - `addTransceiver` and new `publish` needs renegotiation support.
|
18 |
| -#### Remarks |
19 |
| -- Every transceiver could be associated with at most one `Publication` or one `Subscription`. |
| 16 | +## Remarks |
| 17 | +- Every transceiver could be associated with at most one `Publication` or one `Subscription`. |
| 18 | +## Examples |
| 19 | +### Replace a video track |
| 20 | +``` |
| 21 | +const transceivers = publication.transport.rtpTransceivers; |
| 22 | +for (const transceiver of transceivers) { |
| 23 | + if (transceiver.sender.track?.kind === 'video'){ |
| 24 | + transceiver.sender.replaceTrack(newTrack); |
| 25 | + } |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +### Publish a stream with codec preferences |
| 30 | +``` |
| 31 | +const codecCapabilities = RTCRtpSender.getCapabilities('video').codecs; |
| 32 | +// Reorder codecCapabilities or remove some items. |
| 33 | +const transceivers = []; |
| 34 | +for (const track of mediaStream.getTracks()) { |
| 35 | + const transceiver = |
| 36 | + conference.peerConnection.addTransceiver(track, { |
| 37 | + direction: 'sendonly', |
| 38 | + streams: [stream], |
| 39 | + }); |
| 40 | + if (track.kind==='video'){ |
| 41 | + transceiver.setCodecPreferences(codecCapabilities); |
| 42 | + } |
| 43 | + transceivers.push(transceiver); |
| 44 | +} |
| 45 | +const publication = await conference.publish(localStream, transceivers); |
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | +### Publish with a codec supports SVC. |
| 50 | +This example uses some WebRTC APIs may not be supported by all browsers. |
| 51 | +``` |
| 52 | +const transceiver = |
| 53 | + conference.peerConnection.addTransceiver(track, { |
| 54 | + direction: 'sendonly', |
| 55 | + streams: [stream], |
| 56 | + sendEncodings: [ |
| 57 | + { |
| 58 | + rid: 'q', |
| 59 | + scaleResolutionDownBy: 4.0, |
| 60 | + scalabilityMode: 'L1T3' |
| 61 | + }, |
| 62 | + { |
| 63 | + rid: 'h', |
| 64 | + scaleResolutionDownBy: 2.0, |
| 65 | + scalabilityMode: 'L1T3' |
| 66 | + }, |
| 67 | + {rid: 'f', scalabilityMode: 'L1T3'} |
| 68 | + ], |
| 69 | + }); |
| 70 | +const publication = await conference.publish(localStream, [transceiver])); |
| 71 | +``` |
0 commit comments