Vonage Video API: Real-Time Video in iOS

Get started with the Vonage Video API and add real-time video streaming to your iOS apps. By Yusuf Tör.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 3 of 3 of this article. Click here to view the first page.

Disconnecting From the Session

Press the Leave button and you’ll notice the app doesn’t call sessionDidDisconnect(). That’s because the session is still connected. When leaving a session, it’s important that you make sure to disconnect from it.

In StreamingViewController.swift, replace the body of leave() with the following:

var error: OTError?
session?.disconnect(&error)

if let error = error {
  print("An error occurred disconnecting from the session", error)
} else {
  navigationController?.popViewController(animated: true)
}

This disconnects you from the session, which automatically unpublishes your stream when you tap the Leave button. It then pops the current view controller from the navigation stack, if no synchronous error occurred when disconnecting.

Inside session(_:streamDestroyed:), add the following code at the bottom:

subscriberView?.removeFromSuperview()

This removes the subscriber’s view from the screen when they stop publishing their stream in the session.

Now, build and run and double-check that leaving and entering the lounge works as you expect.

And, just like that, you now have a fully functioning app ready to install onto real devices so you can have a virtual tea party with your friend! :]

Where to Go From Here?

Download the completed project files by clicking the Download Materials button at the top or bottom of the tutorial.

In this tutorial, you learned a lot about how to create a livestreaming event. You got to know important terms like WebRTC, HLS and RTMP, you set up your Vonage Video API account and you built a two-way live video streaming app using the Vonage Video API.

However, this project just scraped the surface of the Vonage Video API’s capabilities. There’s still plenty to learn, including:

  • Archiving: Record, save and retrieve sessions.
  • Signaling: Send text and data between clients connected to the session.
  • Server integration: Handle interactions between the client and server SDKs to automatically distribute tokens, session IDs and more.
  • Broadcasts: Set up HLS, RTMP and WebRTC broadcasts simultaneously.
  • SIP Interconnect: Add audio from a VoIP call to a session.
  • Voice-only: Set up voice-only sessions.

If you want to learn more about the capabilities of the Vonage Video API, check out their developer guides.

Also make sure you read about iOS video streaming using Apple’s frameworks in our Video Streaming Tutorial for iOS.

I hope you enjoyed this tutorial. If you have any questions or comments, join the discussion below.