Skip to content

WidgetClient API reference

WidgetClient is the main class exported by @univerx/client-sdk. It manages the full lifecycle of a visitor session: authentication, queue, video call, and cobrowsing.

new WidgetClient(config: WidgetConfig)

Throws if called outside a browser environment or if widgetKey is not provided. See Configuration for the full WidgetConfig reference.

widget.init(): Promise<void>

Authenticates with the Univerx API, sets up realtime channels, and starts cursor tracking. Must be called before any other method. Emits ready on success and sets state to error on failure.

Throws if called more than once on the same instance.


widget.submitForm(formData: Record<string, unknown>): Promise<void>

Submits pre-call form data (e.g. visitor name, email, issue type) before joining the queue. Call this after init() resolves and before joinQueue().


widget.joinQueue(consents?: Record<string, boolean>): Promise<QueueTicket>

Places the visitor in the support queue. Pass any consent flags collected from your pre-call form (e.g. terms, recording).

Returns a QueueTicket:

interface QueueTicket {
ticket_id: string;
position: number;
}

Throws if the widget is already queued or if the visitor is currently in a call or assigned to an agent.


widget.leaveQueue(): Promise<void>

Removes the visitor from the queue and emits queue:left.


widget.getQueuePosition(): number | null

Returns the current queue position, or null if the visitor is not in a queue.


widget.endSession(): Promise<void>

Ends the active video session. Also stops cobrowsing if it is running.


widget.stopCobrowsing(): Promise<void>

Stops the cobrowsing session without ending the call.


widget.getState(): WidgetState

Returns the current widget state:

type WidgetState =
| "idle"
| "initializing"
| "ready"
| "submitting"
| "queued"
| "assigned"
| "in_call"
| "ended"
| "error";

widget.getCurrentAgent(): Agent | null

Returns the currently assigned agent, or null if none has been assigned.

interface Agent {
id: string;
name: string;
avatar_url?: string;
}

widget.on<K extends keyof EventMap>(event: K, callback: (...args: EventMap[K]) => void): void

Subscribes to a widget event. See Events below for all available events.


widget.off<K extends keyof EventMap>(event: K, callback: (...args: EventMap[K]) => void): void

Removes a previously registered event listener.


widget.executeJitsiCommand(command: string, ...args: any[]): void

Executes a video call command on the active video conference. Common commands:

CommandEffect
toggleAudioMute / unmute the microphone
toggleVideoEnable / disable the camera
hangupEnd the conference

widget.destroy(): void

Cleans up all resources: stops cursor tracking, closes realtime channels, destroys internal managers, and emits destroyed. Always call this on component unmount.

Subscribe with widget.on(event, handler) and unsubscribe with widget.off(event, handler).

EventPayloadDescription
readySDK initialised and ready
destroyeddestroy() was called and all resources cleaned up
EventPayloadDescription
queue:joinedQueueTicketVisitor entered the queue
queue:updatenumberQueue position changed
queue:leftVisitor left the queue
EventPayloadDescription
agent:assignedAgentAn agent accepted the session
call:readySessionInfoSession info available; call UI can be rendered
call:startedVideo call is live
call:endedVideo call finished
EventPayloadDescription
cobrowse:invitationAgent requested cobrowsing
cobrowse:consent:requiredCobrowsingConsentHandlersConsent prompt should be shown to the visitor
cobrowse:startedCobrowsing session started
cobrowse:stoppedCobrowsing stopped without ending the session
cobrowse:endedCobrowsing session ended
EventPayloadDescription
agent:cursor:moveCursorPositionAgent cursor moved
agent:cursor:clickCursorPositionAgent clicked
agent:cursor:visiblebooleanCursor visibility changed
EventPayloadDescription
errorErrorAn unhandled error occurred