Skip to main content

Enable and disable the whiteboard

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, the drawing tools, including pencils, text boxes, shapes, and erasers will no longer be available. Users can neither display class files on the whiteboard. Other features, such as uploading or deleting class files, pop-up quiz, count-down timer, and screen sharing will not be affected.

Disable the whiteboard

You need to monitor the whiteboard widget state change caused by the teacher's client and adjust the UI accordingly. Below takes an iOS project as an example. Generally speaking, you need to edit the /SDKs/AgoraEduUI/AgoraEduUI/Classes/Components/FlatComponents/AgoraBoardUIController.swift file.

  1. Create a new branch based on the latest release branch in the CloudClass-iOS repository.

  2. Add a function in the AgoraBoardUIController.swift file for destroying the board widget in AgoraBoardUIController, as follows:

    //
    private extension AgoraBoardUIController {
    ...
    func deinitBoardWidget() {
    self.boardWidget?.view.removeFromSuperview()
    self.boardWidget = nil
    contextPool.widget.remove(self,
    widgetId: netlessKey)
    }
    ...
    }
    Copy
  3. Add contextPool.widget.add(self) in the init function in AgoraBoardUIController.swift to register an observer for observing the whiteboard state change.

    init(context: AgoraEduContextPool) {
    super.init(nibName: nil, bundle: nil)
    contextPool = context
    view.backgroundColor = .clear

    contextPool.room.registerRoomEventHandler(self)
    contextPool.media.registerMediaEventHandler(self)
    // Monitor the state change of the whiteboard widget.
    contextPool.widget.add(self)
    }
    Copy
  4. When the state of the whiteboard widget changes, the SDK triggers the onWidgetActive or onWidgetInactive callback. Add logic in the onWidgetActive and onWidgetInactive callbacks. When the whiteboard state changes to active, render the whiteboard are; when the whiteboard state changes to inactive, call deinitBoardWidget to destroy the board widget.

    extension AgoraBoardUIController: AgoraWidgetActivityObserver {
    func onWidgetActive(_ widgetId: String) {
    guard widgetId == netlessKey else {
    return
    }

    initBoardWidget()
    joinBoard()
    }

    func onWidgetInactive(_ widgetId: String) {
    guard widgetId == netlessKey else {
    return
    }

    deinitBoardWidget()
    }
    }
    Copy

Reference

AgoraWidgetContext

create

AgoraBaseWidget create(AgoraWidgetConfig config)
Copy

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)
Copy

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)
Copy

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)
Copy

Gets the state of a specified widget.

Parameter:

  • widgetId: The widget ID.

Return: Whether the widget is active or not.

getWidgetConfigs

Array<AgoraWidgetConfig> getWidgetConfigs()
Copy

Gets the configurations of all widgets.

Return: An array of the AgoraWidgetConfig objects.

getWidgetConfig

AgoraWidgetConfig getWidgetConfig(String widgetId)
Copy

Gets the configurations of a specified widget.

Parameter:

  • widgetId: The widget ID.

Return: An AgoraWidgetConfig object.

addWidgetActiveObserver

AgoraWidgetError addWidgetActiveObserver(AgoraWidgetActiveObserver observer,
String widgetId)
Copy

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)
Copy

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)
Copy

Occurs when the widget state changes to active.

Parameter:

  • widgetId: The widget ID.

onWidgetInactive

void onWidgetInactive(String widgetId)
Copy

Occurs when the widget state changes to inactive.

Parameter:

  • widgetId: The widget ID.