@4players/odin
Version:
A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects
69 lines (68 loc) • 3.55 kB
TypeScript
import { Backend } from '@4players/odin-common';
import { InputSettings } from '../types';
import DeviceParameters = Backend.DeviceParameters;
import CreateAudioCaptureParameters = Backend.CreateAudioCaptureParameters;
import VadConfig = Backend.VadConfig;
import ApmConfig = Backend.ApmConfig;
import PlaybackVolume = Backend.PlaybackVolume;
/**
* Pauses the execution of asynchronous code for a specified amount of time.
*
* @param {number} ms - The duration to sleep in milliseconds.
* @return {Promise<void>} A promise that resolves after the specified duration.
*/
export declare function sleep(ms: number): Promise<void>;
export declare class OdinError extends Error {
message: string;
readonly name = "OdinError";
constructor(message?: string);
}
/**
* Throws an error if the provided condition is falsy.
*
* @param {unknown} condition - The condition to evaluate. If falsy, an error is thrown.
* @param {string} message - The error message to be included in the thrown error.
* @return {void}
*/
export declare function assert(condition: unknown, message: string): asserts condition;
/**
* Normalizes the given URL by ensuring it starts with "https://".
*
* @param {string} url - The URL to normalize.
* @return {string} The normalized URL that begins with "https://".
*/
export declare function normalizeUrl(url: string): string;
/**
* Updates the voice activity sensitivity range based on the input level.
*
* @param {number} lvl - The input level that defines the current sensitivity adjustment. It is clamped between 0 and 1 if outside of this range.
* @return {Backend.SensitivityRange} An object containing the calculated `releaseThreshold` and `attackThreshold`, both of which are adjusted based on the level.
*/
export declare function updateVoiceActivity(lvl: number): Backend.SensitivityRange;
/**
* Updates the volume gate sensitivity range based on the provided active threshold.
*
* @param {number} goingActive - The desired threshold for activating the volume gate.
* @param {number} [offset=10] - The offset value used to calculate the release threshold. Defaults to 10.
* @return {Backend.SensitivityRange} An object representing the updated sensitivity range with `attackThreshold` and `releaseThreshold`.
*/
export declare function updateVolumeGate(goingActive: number, offset?: number): Backend.SensitivityRange;
/**
* Determines whether the current platform is capable of supporting audio functionality
* by checking the availability of `AudioContext` and `Worker`.
*
* @return {boolean} Returns true if the platform supports audio functionality; otherwise, false.
*/
export declare function isAudioCapable(): boolean;
export declare function generateCaptureParameters(device?: DeviceParameters, settings?: InputSettings): CreateAudioCaptureParameters;
export declare function generateVadConfig(settings?: InputSettings): VadConfig;
export declare function generateApmConfig(settings?: InputSettings): ApmConfig;
/**
* Calculates the playback volume by combining an array of volumes.
*
* @param {PlaybackVolume[]} volumes - An array of volume values. Each value can be a number or the string 'muted'.
* A 'muted' value is treated as 0 during calculation.
* @return {number} The resulting playback volume after combining all provided volumes.
*/
export declare function calcPlaybackVolume(volumes: PlaybackVolume[]): PlaybackVolume;
export declare function calculateBytesPerSeconds(currentBytes: number, lastBytes: number, ms: number): number;