Enable and disable the whiteboard

Updated

Turn the Flexible Classroom whiteboard module on or off and understand the related APIs.

The whiteboard module in Flexible Classroom is implemented based on AgoraWidget. You can turn the whiteboard module on or off in the classroom by setting the widget state as active or inactive.

After disabling the whiteboard module, drawing tools including pencil, text box, shape, and eraser will no longer be available and users cannot upload, delete, or display class files on the whiteboard. Other features that do not rely on the whiteboard, such as uploading or deleting class files, pop-up quiz, countdown timer, and screen sharing will not be affected.

iOS

In Flexible Classroom, the implementation logic of opening and closing the Whiteboard is located in the CloudClass-iOS/SDKs/AgoraEduUI/Classes/Components/Flat/FcrBoardUIComponent.swift file. Take the following steps to manage the Whiteboard:

  1. Add an observer to monitor widget activity

    // add WidgetActivityObserver
    widgetController.add(self)
  2. When the state of the Whiteboard widget activity changes, onWidgetActive or onWidgetInactive is called. When the status is active, open the Whiteboard by creating a Whiteboard Widget object; when the status is inactive, close the Whiteboard by destroying the Whiteboard Widget object as follows:

    extension FcrBoardUIComponent: AgoraWidgetActivityObserver {
        func onWidgetActive(_ widgetId: String) {
            guard widgetId == BoardWidgetId else {
                return
            }
    
            initWidget()
        }
    
        func onWidgetInactive(_ widgetId: String) {
            guard widgetId == BoardWidgetId else {
                return
            }
    
            deinitWidget()
        }
    }

API Reference

AgoraWidgetContext

create

AgoraBaseWidget create(AgoraWidgetConfig config)

Creates a widget object.

Parameter:

  • config: The initialization configurations of the widget object.

Return: An AgoraBaseWidget object.

setWidgetActive

void setWidgetActive(String widgetId,
                     String ownerUuid,
                     Map<String: Any> roomProperties,
                     AgoraWidgetFrame syncFrame,
                     Callback<Void> success,
                     Callback<Error> failure)

Sets the widget state as active.

Parameter:

  • widgetId: The widget ID.
  • ownerUuid: (Nullable) The ID of the user to whom the widget belongs. When the user goes offline, the onWidgetInactive callback will be triggered for the widgets owned by this user.
  • roomProperties: (Nullable) The room properties related to the widget.
  • syncFrame: (Nullable) The size and position of the widget.
  • success: The method call succeeds.
  • failure: The method call fails, the SDK returns an error.

setWidgetInactive

void setWidgetInactive(String widgetId,
                       Callback<Void> success,
                       Callback<Error> failure)

Sets the widget state as inactive.

Parameter:

  • widgetId: The widget ID.
  • roomProperties: (Nullable) The room properties related to the widget.
  • success: The method call succeeds.
  • failure: The method call fails, the SDK returns an error.

getWidgetActivity

Bool getWidgetActivity(String widgetId)

Gets the state of a specified widget.

Parameter:

  • widgetId: The widget ID.

Return: Whether the widget is active or not.

getWidgetConfigs

Array<AgoraWidgetConfig> getWidgetConfigs()

Gets the configurations of all widgets.

Return: An array of the AgoraWidgetConfig objects.

getWidgetConfig

AgoraWidgetConfig getWidgetConfig(String widgetId)

Gets the configurations of a specified widget.

Parameter:

  • widgetId: The widget ID.

Return: An AgoraWidgetConfig object.

addWidgetActiveObserver

AgoraWidgetError addWidgetActiveObserver(AgoraWidgetActiveObserver observer,
                                         String widgetId)

Registers an observer to observe the state of a specified widget. When the state of the widget changes, the SDK triggers a callback.

Parameter:

  • observer: See AgoraWidgetActiveObserver.
  • widgetId: The widget ID.

Return: When the widget ID is not valid, the SDK returns an error.

removeWidgetActiveObserver

AgoraWidgetError removeWidgetActiveObserver(AgoraWidgetActiveObserver observer,
                                            String widgetId)

Registers the observer of a specified widget.

Parameter:

  • observer: See AgoraWidgetActiveObserver.
  • widgetId: The widget ID.

Return: When the widget ID is not valid, the SDK returns an error.

AgoraWidgetActiveObserver

onWidgetActive

void onWidgetActive(String widgetId)

Occurs when the widget state changes to active.

Parameter:

  • widgetId: The widget ID.

onWidgetInactive

void onWidgetInactive(String widgetId)

Occurs when the widget state changes to inactive.

Parameter:

  • widgetId: The widget ID.