Below are the available methods, each with a description of its usage:
on(eventType: string, callback: EventCallback) => () => void
Description: This method allows you to listen for specific events emitted by the OrufyWidget. It enables handling events such as user login, user creation, and more. Once an event occurs, the provided callback is executed. Add a listener for a specific event.
- eventType: Type of event to listen for (e.g., 'login', 'user created').
- callback: Function to run when the event happens.
- Returns: A function you can call to remove this listener.
Example Usage:
// Listening for a 'login' event
const removeListener = window.orufyWidget.on('login', (eventData) => {
console.log('User logged in:', eventData);
});
// Later, remove the listener if needed
removeListener();
off(eventType: string, callback: EventCallback) => void
Description: This method removes a previously registered event listener. It is used to stop listening for a specific event and executing the associated callback. Remove a listener for a specific event.
- eventType: Type of event to stop listening for.
- callback: Function that was listening for the event.
Example Usage:
// Example: Remove 'login' event listener
off('login', callbackFunction);
// Later, remove the listener if needed
removeListener();
hideWidget() => boolean
Description: This method hides the widget from the user interface. It can be used to temporarily hide the widget without closing the session. Hide the widget.
- Returns: true if the widget was hidden successfully, otherwise false.
Example Usage:
// Hide the widget
const isHidden = window.orufyWidget.hideWidget();
console.log(isHidden ? 'Widget hidden' : 'Failed to hide widget');
showWidget() => boolean
Description: This method shows the widget, making it visible again if it was previously hidden. Show the widget.
- Returns: true if the widget was shown successfully, otherwise false. Example Usage:
// Show the widget
const isShown = window.orufyWidget.showWidget
isIntializationDone() => boolean
Description: This method checks if the widget has finished its initialization. You can use this method to ensure the widget is ready for interaction. Check if the widget has finished setting up.
- Returns: true if setup is complete, otherwise false.
Example Usage:
// Check if widget is initialized
const isInitialized = window.orufyWidget.isIntializationDone();
console.log(isInitialized ? 'Widget initialized' : 'Widget setup not complete');
openWidget() => void
Description: This method opens the widget, making it available for interaction. Open the widget. Example Usage:
// Open the widget
window.orufyWidget.openWidget();
console.log('Widget opened');
orufyBookingsSetup() => void
Description: This method sets up the Orufy bookings system. It is used to configure the widget to support bookings functionality. Set up the Orufy bookings system.
Example Usage:
// Set up Orufy bookings system
window.orufyWidget.orufyBookingsSetup();
console.log('Orufy bookings system set up');
setWidgetConfig(obj: Record<string, ReactNode>) => void
Description: This method configures the widget with the provided settings. It can be used to update properties like externalUserId and restoreId to log in the user. Configure the widget.
- obj: An object with settings where the keys are values.
- setWidgetConfig can be used to update externalUserId, restoreId to log in the user.
Example Usage:
// Configure widget settings
const config = { externalUserId: 'user123', restoreId: 'restoreId123' };
window.orufyWidget.setWidgetConfig(config);
console.log('Widget configuration updated');