Skip to content

Commit

Permalink
chore: add docs for customHeaders and preferred_codecs (#387)
Browse files Browse the repository at this point in the history
* chore: add docs for customHeaders and preferred_codecs

* chore: deprecate video methods
  • Loading branch information
farhat-ha authored Oct 16, 2024
1 parent fd87e08 commit e0299f9
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/js/docs/ts/classes/TelnyxRTC.md
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,36 @@ const call = client.newCall().catch(console.error);
// => `destinationNumber is required`
```
### Setting Custom Headers
```js
client.newCall({
destinationNumber: '18004377950',
callerNumber: '155531234567',
customHeaders: [ {name: "X-Header", value: "value" } ]
});
```
### Setting Preferred Codec
You can pass `preferred_codecs` to the `newCall` method to set codec preference during the call.
`preferred_codecs` is a sub-array of the codecs returned by [RTCRtpReceiver.getCapabilities('audio')](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpReceiver/getCapabilities_static#codecs)
```js
const allCodecs = RTCRtpReceiver.getCapabilities('audio').codecs;
const PCMACodec = allCodecs.find((c) => c.mimeType.toLowerCase().includes('pcma'));
client.newCall({
destinationNumber: '123',
preferred_codecs: [PCMACodec],
});
```
#### Overrides
TelnyxRTCClient.newCall
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/Modules/Verto/BaseSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export default abstract class BaseSession {
/**
* Callback when the ws connection is going to close or get an error
* @return void
* @private
*/
public onNetworkClose(): void {
if (this.relayProtocol) {
Expand Down
5 changes: 5 additions & 0 deletions packages/js/src/Modules/Verto/BrowserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export default abstract class BrowserSession extends BaseSession {
* ```
*
* @returns Promise with an array of MediaDeviceInfo
* @deprecated
*/
getVideoDevices(): Promise<MediaDeviceInfo[]> {
return getDevices(DeviceType.Video).catch((error) => {
Expand Down Expand Up @@ -391,6 +392,7 @@ export default abstract class BrowserSession extends BaseSession {
* console.log(result);
* });
* ```
* @deprecated
*/
async getDeviceResolutions(deviceId: string) {
try {
Expand Down Expand Up @@ -545,6 +547,7 @@ export default abstract class BrowserSession extends BaseSession {
* height: 720
* })
* ```
* @deprecated
*/
async setVideoSettings(settings: IVideoSettings) {
if (!settings) {
Expand Down Expand Up @@ -586,6 +589,7 @@ export default abstract class BrowserSession extends BaseSession {
*
* client.disableWebcam();
* ```
* @deprecated
*/
disableWebcam() {
this._videoConstraints = false;
Expand All @@ -604,6 +608,7 @@ export default abstract class BrowserSession extends BaseSession {
*
* client.enableWebcam();
* ```
* @deprecated
*/
enableWebcam() {
this._videoConstraints = true;
Expand Down
4 changes: 4 additions & 0 deletions packages/js/src/Modules/Verto/webrtc/BaseCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ export default abstract class BaseCall implements IWebRTCCall {
* ```js
* call.muteVideo();
* ```
* @deprecated
*/
muteVideo() {
disableVideoTracks(this.options.localStream);
Expand All @@ -604,6 +605,7 @@ export default abstract class BaseCall implements IWebRTCCall {
* ```js
* call.unmuteVideo();
* ```
* @deprecated
*/
unmuteVideo() {
enableVideoTracks(this.options.localStream);
Expand All @@ -617,6 +619,7 @@ export default abstract class BaseCall implements IWebRTCCall {
* ```js
* call.toggleVideoMute();
* ```
* @deprecated
*/
toggleVideoMute() {
toggleVideoTracks(this.options.localStream);
Expand Down Expand Up @@ -653,6 +656,7 @@ export default abstract class BaseCall implements IWebRTCCall {
*
* @param deviceId the target video device ID
* @returns Promise that resolves if the video device has been updated
* @deprecated
*/
async setVideoDevice(deviceId: string): Promise<void> {
const { instance } = this.peer;
Expand Down
9 changes: 8 additions & 1 deletion packages/js/src/Modules/Verto/webrtc/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import { IVertoCallOptions } from './interfaces';
export class Call extends BaseCall {
public screenShare: Call;


private _statsInterval: any = null;

hangup(params: any = {}, execute: boolean = true) {
Expand All @@ -63,6 +62,10 @@ export class Call extends BaseCall {
super.hangup(params, execute);
}

/**
* @deprecated
* @private
*/
async startScreenShare(opts?: IVertoCallOptions) {
const displayStream: MediaStream = await getDisplayMedia({ video: true });
displayStream.getTracks().forEach((t) => {
Expand All @@ -89,6 +92,10 @@ export class Call extends BaseCall {
return this.screenShare;
}

/**
* @deprecated
* @private
*/
stopScreenShare() {
if (this.screenShare instanceof Call) {
this.screenShare.hangup();
Expand Down
34 changes: 34 additions & 0 deletions packages/js/src/Modules/Verto/webrtc/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,41 @@ export interface IStatsBinding {
}

export interface AnswerParams {
/**
* *
* ### Setting Custom Headers
*
* ```js
*
* client.newCall({
* destinationNumber: '18004377950',
*
* callerNumber: '155531234567',
*
* customHeaders: [ {name: "X-Header", value: "value" } ]
* });
* ```
*/
customHeaders?: Array<{ name: string; value: string }>;

/**
*
* ### Setting Preferred Codec
*
* You can pass `preferred_codecs` to the `newCall` method to set codec preference during the call.
*
* `preferred_codecs` is a sub-array of the codecs returned by [RTCRtpReceiver.getCapabilities('audio')](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpReceiver/getCapabilities_static#codecs)
*
* ```js
* const allCodecs = RTCRtpReceiver.getCapabilities('audio').codecs;
*
* const PCMACodec = allCodecs.find((c) => c.mimeType.toLowerCase().includes('pcma'));
*
* client.newCall({
* destinationNumber: '123',
* preferred_codecs: [PCMACodec],
* });
*/
preferred_codecs?: Array<RTCRtpCodecCapability>;
}

Expand Down
30 changes: 30 additions & 0 deletions packages/js/src/TelnyxRTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,36 @@ export class TelnyxRTC extends TelnyxRTCClient {
* const call = client.newCall().catch(console.error);
* // => `destinationNumber is required`
* ```
*
* ### Setting Custom Headers
*
* ```js
*
* client.newCall({
* destinationNumber: '18004377950',
*
* callerNumber: '155531234567',
*
* customHeaders: [ {name: "X-Header", value: "value" } ]
* });
* ```
* ### Setting Preferred Codec
*
* You can pass `preferred_codecs` to the `newCall` method to set codec preference during the call.
*
* `preferred_codecs` is a sub-array of the codecs returned by [RTCRtpReceiver.getCapabilities('audio')](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpReceiver/getCapabilities_static#codecs)
*
* ```js
* const allCodecs = RTCRtpReceiver.getCapabilities('audio').codecs;
*
* const PCMACodec = allCodecs.find((c) => c.mimeType.toLowerCase().includes('pcma'));
*
* client.newCall({
* destinationNumber: '123',
* preferred_codecs: [PCMACodec],
* });
* ```
*/
newCall(options: ICallOptions) {
return super.newCall(options);
Expand Down

0 comments on commit e0299f9

Please sign in to comment.