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:


    _11
    //
    _11
    private extension AgoraBoardUIController {
    _11
    ...
    _11
    func deinitBoardWidget() {
    _11
    self.boardWidget?.view.removeFromSuperview()
    _11
    self.boardWidget = nil
    _11
    contextPool.widget.remove(self,
    _11
    widgetId: netlessKey)
    _11
    }
    _11
    ...
    _11
    }

  3. Add contextPool.widget.add(self) in the init function in AgoraBoardUIController.swift to register an observer for observing the whiteboard state change.


    _10
    init(context: AgoraEduContextPool) {
    _10
    super.init(nibName: nil, bundle: nil)
    _10
    contextPool = context
    _10
    view.backgroundColor = .clear
    _10
    _10
    contextPool.room.registerRoomEventHandler(self)
    _10
    contextPool.media.registerMediaEventHandler(self)
    _10
    // Monitor the state change of the whiteboard widget.
    _10
    contextPool.widget.add(self)
    _10
    }

  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.


    _18
    extension AgoraBoardUIController: AgoraWidgetActivityObserver {
    _18
    func onWidgetActive(_ widgetId: String) {
    _18
    guard widgetId == netlessKey else {
    _18
    return
    _18
    }
    _18
    _18
    initBoardWidget()
    _18
    joinBoard()
    _18
    }
    _18
    _18
    func onWidgetInactive(_ widgetId: String) {
    _18
    guard widgetId == netlessKey else {
    _18
    return
    _18
    }
    _18
    _18
    deinitBoardWidget()
    _18
    }
    _18
    }

Reference

AgoraWidgetContext

create


_1
AgoraBaseWidget create(AgoraWidgetConfig config)

Creates a widget object.

Parameter:

  • config: The initialization configurations of the widget object.

Return: An AgoraBaseWidget object.

setWidgetActive


_6
void setWidgetActive(String widgetId,
_6
String ownerUuid,
_6
Map<String: Any> roomProperties,
_6
AgoraWidgetFrame syncFrame,
_6
Callback<Void> success,
_6
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


_3
void setWidgetInactive(String widgetId,
_3
Callback<Void> success,
_3
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


_1
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


_1
Array<AgoraWidgetConfig> getWidgetConfigs()

Gets the configurations of all widgets.

Return: An array of the AgoraWidgetConfig objects.

getWidgetConfig


_1
AgoraWidgetConfig getWidgetConfig(String widgetId)

Gets the configurations of a specified widget.

Parameter:

  • widgetId: The widget ID.

Return: An AgoraWidgetConfig object.

addWidgetActiveObserver


_2
AgoraWidgetError addWidgetActiveObserver(AgoraWidgetActiveObserver observer,
_2
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


_2
AgoraWidgetError removeWidgetActiveObserver(AgoraWidgetActiveObserver observer,
_2
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


_1
void onWidgetActive(String widgetId)

Occurs when the widget state changes to active.

Parameter:

  • widgetId: The widget ID.

onWidgetInactive


_1
void onWidgetInactive(String widgetId)

Occurs when the widget state changes to inactive.

Parameter:

  • widgetId: The widget ID.