Methods and Properties
An instance of the HTApi class has several methods that allow you to interact with the library. Using these methods, you have full control over translations, settings, and interactions with internal components, enabling you to create your own use cases and control flows.
To better understand the available methods in the class, consider the following example class:
class HTApi {
// Properties
isLoaded: boolean;
// Methods
pause(): void;
active(): void;
resume(): void;
minimize(): void;
maximize(): void;
openRate(): void;
closeRate(): void;
getZoom(): number;
getConfig(): IConfig;
stop(): Promise<void>;
repeat(): Promise<void>;
disable(): Promise<void>;
zoom(step: number): void;
rate(like: boolean): void;
getRotationAngle(): number;
rotate(angle: number): void;
setConfig(config: PatchConfig): void;
getApplicationState(): IApplicationState;
translate(sentence: string): Promise<void>;
changeAnimationSpeed(speed: CoreSpeed): void;
onConfigChange(callback: (config: IConfig) => void): () => void;
observeRotationAngle(callback: (angle: number) => void): () => void;
observeZoomQuantity(callback: (quantity: number) => void): () => void;
onApplicationStateChange(callback: (applicationState: IApplicationState) => void): () => void;
}Properties
isLoaded
- type:
boolean - default:
false
Property that indicates whether the library is loaded.
ATTENTION
This property does not refer to the library's deactivation state, but rather indicates that all necessary data for the library's initialization has been loaded correctly.
Methods
General Application Controls
active()
- returns:
void
Method that initializes the library and allows interactions with the SDK. Without calling this method, no other method will have any effect. We recommend executing this method using a button of your choice.
disable()
- returns:
Promise<void>
Method that deactivates the SDK, preventing interactions with it. This method is also called by the interface when the user clicks the close button in either the Translation Window or the Widget.
setConfig(config: PatchConfig)
- returns:
void - prop:
PatchConfig:
Method that sets the library's configurations. This method is useful for changing settings after instantiating HTApi and modifying the properties passed to the constructor. All properties, regardless of their level, are optional, allowing for a high degree of flexibility in configuring the library.
Recommended use cases:
- Changing the theme;
- Changing the language;
- Changing the token;
- Changing the sign language.
To see the available configurations, refer to Configurations.
getConfig()
- returns:
void - prop:
IConfig:
Method that returns the current settings of the library.
To see the available settings, refer to Configurations.
onConfigChange(callback: (config: IConfig) => void)
- returns:
() => void - prop:
(config: IConfig) => void
Similar to getConfig, but it receives a callback function to observe changes in the configurations. This method returns a function that, when executed, stops observing the changes.
getApplicationState()
- returns:
IApplicationState
Method that returns the current state of the application. Our SDK has a state flow that indicates the current situation of the application. This is helpful for cases where we want to change the interface or execute certain actions depending on the current state.
See more in State Flow
onApplicationStateChange(callback: (applicationState: IApplicationState) => void)
- returns:
() => void - prop:
(applicationState: IApplicationState) => void
Similar to getApplicationState, but it receives a callback function to observe changes in the application state. This method returns a function that, when executed, stops observing changes.
See more in State Flow
Translation Controls
translate(sentence: string)
- returns:
Promise<void> - prop:
string
Method that initiates a new translation. This method is related to the Translation functionality.
WARNING
Method only available when the application is in the ready state.
pause()
- returns:
void
Method that pauses an ongoing translation. This method is also called when the user clicks the pause button in the translation window.
WARNING
Method only available when the application is in the translating state and the current translation is not already paused.
changeAnimationSpeed(speed: CoreSpeed);
- returns:
void - prop:
CoreSpeed
type CoreSpeed = "normal" | "slow" | "fast";Method that changes the translation speed. This method is also called when the user clicks the change speed button in the translation window.
resume()
- returns:
void
Method that resumes an ongoing translation. This method is also called when the user clicks the play button in the translation window.
WARNING
Method only available when the application is in the translating state and the current translation must be paused.
repeat()
- returns:
Promise<void>
Method that repeats the last translation made. This method is also called when the user clicks the repeat button in the translation window.
WARNING
Method only available when the application is in the ready, minimized, or rating state and only when there is a cached translation.
stop()
- returns:
Promise<void>
Method that cancels an ongoing translation. This method is also called when the user clicks the stop button in the translation window.
WARNING
Method only available when the application is in the translating state.
Hiding Controls
minimize()
- returns:
void
Method that minimizes the translation window if it is visible. There is no component to interact with this functionality, but you can see its operation here.
WARNING
Method only available when the application is in the ready state.
maximize()
- returns:
void
Method that maximizes the translation window if it is minimized. There is no component to interact with this functionality, but you can see its operation here.
WARNING
Method only available when the application is in the minimized state.
Rating Controls
The methods in this category are related to the Translation Rating functionality.
openRate()
- returns:
void
Method that opens the rating window. This method is also called when the user clicks the Rate button.
WARNING
Method only available when the application is in the ready or minimized state.
closeRate()
- returns:
void
Method that closes the rating window. This method is also called when the user clicks the Back button in the rating window.
WARNING
Method only available when the application is in the rating state.
rate(like: boolean)
- returns:
void - prop:
boolean
Method that sends a rating to our server. This method is also called when the user clicks the Confirm button in the rating window.
WARNING
Method only available when the application is in the rating state.
3D Avatar Controls
The methods in this category are related to the Zoom and Rotation functionalities.
zoom(step: number)
- returns:
void - prop:
0 | 1 | 2 | 3 - default:
0
Method that changes the avatar's zoom level. This method is triggered when the user uses mouse scroll + CTRL or a pinch gesture on a touchscreen.
WARNING
Any number can be passed, but only numbers within the range 0 | 1 | 2 | 3 will be accepted.
getZoom(): number
- returns:
0 | 1 | 2 | 3
Method that returns the current zoom level of the avatar.
observeZoomQuantity(callback: (quantity: number) => void);
- returns:
() => void - prop:
(quantity: number) => void
Method that receives a callback function to observe changes in the avatar's zoom level. It returns a function that, when executed, stops observing changes.
rotate(angle: number)
- returns:
void - prop:
number
Method that changes the avatar's rotation. This method is triggered when the user holds and drags the mouse over the 3D avatar or uses a touchscreen.
WARNING
The angle property can accept any numeric value, but it represents a rotation in degrees. For example, 0 is the initial position, values above this will rotate the 3D avatar to the right, and values below will rotate it to the left.
The value is not cumulative; it represents the exact position the 3D avatar should be in. For example, calling rotate(10) and then rotate(20) is not the same as calling rotate(30).
To rotate the 3D avatar completely on its own axis, simply pass -360° or 360° as the parameter, as these values are the limits of rotation.
If values above 360° or below -360° are passed, the 3D avatar will rotate up to the limit plus the excess. For example, rotating 400° is equivalent to rotating 40° (360° + 40° = 400), and rotating -400° is equivalent to rotating -40° (-360° - 40° = -400).
getRotationAngle();
- returns:
number
Method that returns the current rotation of the avatar.
observeRotationAngle(callback: (angle: number) => void)
- returns:
() => void - prop:
(angle: number) => void
Method that receives a callback function to observe changes in the avatar's rotation. It returns a function that, when executed, stops observing changes.