Class: Uhlive

Constructors

constructor

+ new Uhlive(identifier: string, token: string, options?: UhliveOptions): Uhlive

Create an Uhlive instance by passing your private token and identifier.

example

const uhlive = new Uhlive("my-identifier", "my-token", {
timeout: 3,
});

Parameters:

NameType
identifierstring
tokenstring
options?UhliveOptions

Returns: Uhlive

Events Methods

onClose

onClose(callback: () => void): Uhlive

Subscribe to Uhlive onClose event.

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.onClose(() => {
// Choose what to do when the connection is closed.
});

Parameters:

NameType
callback() => void

Returns: Uhlive


onError

onError(callback: () => void): Uhlive

Subscribe to Uhlive onError event.

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.onError(() => {
// Choose what to do when we encounter an error.
});

Parameters:

NameType
callback() => void

Returns: Uhlive


Other Methods

connect

connect(): Uhlive

Connect to the websocket.

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.connect();

Returns: Uhlive


disconnect

disconnect(): Promise<void>

Disconnect from the websocket.

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.connect();
uhlive.join("my-conversation");
uhlive.disconnect().then(() => {
console.log("Disconnected!");
});

Returns: Promise<void>


getConversation

getConversation(): Conversation | null

Return the current conversation.

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.connect();
const conversation = uhlive.getConversation();
console.log(conversation);

Returns: Conversation | null


join

join(conversationId: string, options: ConversationOptions): Conversation

Join a conversation and start recording immediately.

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.connect();
uhlive.join("my-conversation", {
speaker: "john",
});
uhlive.disconnect();

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.connect();
uhlive.join("my-conversation", {
ignoreEntities: ["NumberFound"],
readonly: true,
wrapper: "my-custom-wrapper",
});
uhlive.disconnect();

Parameters:

NameTypeDefault value
conversationIdstring-
optionsConversationOptions{

country: this.getCountryFromBrowser(), ignoreDecodingEvents: [], ignoreEntities: [], interim_results: true, model: this.getLocaleFromBrowser(), origin: 0, readonly: false, rescoring: true, speaker: Uhlive.generateSpeakerId(), wrapper: "uhlive", } |

Returns: Conversation


leave

leave(): Promise<void>

Leave a conversation.

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.connect();
uhlive.join("my-conversation");
uhlive.leave().then(() => {
console.log("You left the conversation");
}).catch((err) => {
console.error("Error:", err);
});

Returns: Promise<void>


leaveAllConversations

leaveAllConversations(): Promise<void[]>

Leave all conversations at once.

deprecated

example

const uhlive = new Uhlive("my-identifier", "my-token");
uhlive.connect();
uhlive.join("my-conversation1");
uhlive.join("my-conversation2");
uhlive.leaveAllConversations().then((result) => {
result.forEach((msg) => {
console.log("Promise result", msg);
});
});
uhlive.disconnect();

Returns: Promise<void[]>