Skip to main content
Version: 2.0.x

Whiteboard - iOS

A whiteboard is a digital canvas that allows users to collaborate in real-time by drawing, writing, and sharing ideas visually, making it ideal for brainstorming, presentations, and teamwork.

Before initiating a whiteboard session, it is essential to have an active VideoSDK Meeting in progress.

Starting the Whiteboard​

To start the whiteboard during a meeting, invoke the startWhiteboard() method of the meeting class.

Upon successful execution, the onWhiteboardStarted event will return a url.

You can embed the url into a WKWebView to display the whiteboard session within your iOS app.

Stopping the Whiteboard​

To stop the whiteboard session, call the stopWhiteboard() method of the meeting class. This will trigger the onWhiteboardStopped event, halting the whiteboard for all participants.

Example​

class MeetingViewController: UIViewController {
let meeting;
let isWhiteboardStarted = false;

private var webView: WKWebView?

override func viewDidLoad() {
super.viewDidLoad()
//setup ui
//setup actions
setupWebView()
}

meeting = VideoSDK.initMeeting({
//... Initialization parameters
});

//setup webview
private func setupWebView() {
// Create WKWebView
webView = WKWebView(frame: .zero)
guard let webView = webView else { return }

webView.translatesAutoresizingMaskIntoConstraints = false

// Add WKWebView to the view hierarchy
view.addSubview(webView)

// Set up constraints
NSLayoutConstraint.activate([
webView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
webView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
// Initially hide the WebView
webView.isHidden = true
}
// show webview
func showWebView(with url: URL) {
guard let webView = webView else { return }

let request = URLRequest(url: url)
webView.load(request)
webView.isHidden = false
}
// hide webview
func hideWebView() {
webView?.isHidden = true
}
}

extension MeetingViewController {
// Start Whiteboard
@IBAction func toggleWhiteboardTapped(_ sender: Any) {
guard !isWhiteboardStarted else {
meeting.stopWhiteboard();
isWhiteboardStarted = false;
return;
}
meeting.startWhiteboard();
isWhiteboardStarted = true;
}
}

// Handle Whiteboard State Changed Event
extension MeetingViewController: MeetingEventListener {
func onWhiteboardStarted(url: URL) {
DispatchQueue.main.async {
self.showWebView(with: url)
}
}

func onWhiteboardStopped() {
DispatchQueue.main.async {
self.hideWebView()
}
}
}

Events Associated with startWhiteboard() and stopWhiteboard()​

  • onWhiteboardStarted: Fired when the whiteboard is successfully started and it will return the url.

  • onWhiteboardStopped: Fired when the whiteboard session is stopped for all participants.

extension MeetingViewController: MeetingEventListener {
func onWhiteboardStarted(url: URL) {
print("Whiteboard Started Successfully with url:", url)
}

func onWhiteboardStopped() {
print("Whiteboard Stopped Successfully")
}
}

API Reference​

Got a Question? Ask us on discord