In this tutorial, we'll build an iOS app for livestream events where attendees and speakers can interact in a virtual conference room using Stream Chat, to deliver fully featured chat components, and Dolby.io, to provide quality live-streamed audio and video for large audiences. By the end, we'll have an application similar to the screenshots below. As a bonus, it's compatible with both light and dark mode.
If you get lost during this tutorial, you can check the completed project in this GitHub repo. Let's get started with our live event app development!
Build real-time chat in less time. Rapidly ship in-app messaging with our highly reliable chat infrastructure. Drive in-app conversion, engagement, and retention with the Stream Chat messaging platform API & SDKs.
Dolby Interactivity APIs provide a platform for unified communications and collaboration. In-flow communications refers to the combination of voice, video, and messaging integrated into your application in a way that is cohesive for your end-users. This is in contrast to out-of-app communications where users must stop using your application and instead turn to third-party tools.
First, we open Xcode and create a Single View App project.
And make sure to select 'Storyboard' for the User Interface.
In the folder where you saved the project, run
pod init and add
VoxeetUXKit to the
Podfile. It should look similar to this:
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/013b8917755ff82d283925417f9e9bb9) - TIP: If you refresh the page, it may fix it!
After you do that, run
pod install, wait a bit for it to finish, and open the project via the
.xcworkspace that CocoaPods created.
Sign up for Chat at GetStream.io, create the application, and make sure to select development instead of production.
To make things simple for now, let's disable both auth checks and permission checks. Make sure to hit save. When your app is in production, you should keep these enabled.
Now, save your Stream credentials, as we'll need them to power the chat in the app. Since we disabled auth and permissions, we'll only really need the key for now. Still, in production, you'll use the secret in your backend to implement proper authentication to issue user tokens for Stream Chat, so users can interact with your app securely.
As you can see, I've blacked out my keys. You should make sure to keep your credentials safe.
Configuring the Dolby.io dashboard is simpler. Just create an account there, and it should already set up an initial application for you.
Now, save your credentials, as we'll need them to power the audio and video streaming in the app. As with the Stream credentials, you use these for development. In production, you'll need to set up proper authentication. It's described in detail here.
The first step with code is to configure the Stream and Dolby SDK with the credentials from the dashboards. Open the
AppDelegate.swift file and modify it, so it looks similar to this:
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/0b61d39c197a28d981cb10455c0413f3)
That code initializes the Dolby.io and Stream Chat SDKs with credentials you got in the previous two steps.
Let's start building the "Join" screen. This screen consists of two
UIButton instances. One to join as an attendee, and the other to participate as the speaker. That is an oversimplification to make this tutorial short and get to the chat, audio, and video features faster. In your complete app, you'll need proper registration, database, and all that. For this tutorial, the screen will look similar to the screenshot below.
Go to the storyboard, select the default view controller, and click
Editor > Embed In > Navigation Controller. That will place it under a navigation controller, which we'll use to navigate to the conference room screen.
Make sure to rename
JoinViewController, so you don't get confused later. You can do this easily by right-clicking on
ViewController.swift and selecting
To make things simple, let's leave the storyboard like this and use only code from now on. To set up the two buttons, we need the following code in
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/09728d77c428f4fb041afbd574675714)
That code sets up the views, the constraints, and the handlers we need. Let's start by extending
JoinViewController to define
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/2ac3cf99c34cb13bca84ee61f1214d36)
That code will create the buttons and add them to the controller's view. Next, we need to define constraints between the three. Let's do this by extending
JoinViewController to define
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/33f4944db3fa4ac90f166661bb0c482f)
That code will ensure the
attendeeButton stays in the center of the screen and the
speakerButton below it. Now we need to set up the handler for when the user presses the buttons. Let's do this again by extending the controller to define
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/b0587ff914aed7cd9f30543fed420ea4)
That code will make it so, when the user presses the button, a
RoomViewController is created and set up for the speaker or an attendee, depending on which button the user pressed. We'll create
RoomViewController in the next step.
Now, let's create the screen where the the attendees and speaker will talk via chat and where they may begin a video call to watch or transmit the event stream. We'll start by defining RoomViewController. It will look similar to the screenshots below.
The first step is to create a RoomViewController.swift file and paste the code below.
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/697fbd88ee1464918b3c0c2b00a21e5e)
That code defines a subclass of ChatViewController, which provides most of the chat behavior and UI we need. It also defines the attendee and speaker
User objects and a
Channel object. These objects will be used to interact with the Stream API. Additionally, we're generating a random id for the attendee using the String extension below.
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/1433835a9e316431e92f9814ed9b2a96)
viewDidLoad, we also call
setupHandlers to set up the views and handlers needed. We'll define those functions next.
But, let's first define the
setupAttendee function that sets the current Stream Chat user as an attendee, and the
setupSpeaker function that sets it as the speaker.
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/f44e9f0cae5e548569a2edae583edf4b)
Now we define
setupViews to set up the views we need.
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/8332e7f47650aaa91bdd93cc829f804c)
Those functions will display a button which starts a call. For it to work, we'll need to define
setupHandlers as well.
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/96c06e84a416dc421d6e7caa0b4f29b2)
Those functions set
callButtonPressed as the function to be called when the call button is pressed, which in turn calls
startCall, which we define next.
(dev.to might be showing a different snippet due to a bug, if so link is here: https://gist.github.com/cardoso/81b8b83b9d68c199e8d427c79050034e)
Finally, that function uses the Dolby.io SDK to start a conference call.
If you run the app now, you'll be able to chat, but pressing the call button will cause the application to crash. That happens because we need to configure the usage descriptions for microphone and video in the
Info.plist file. To do this, just open
Info.plist and set the
NSCameraUsageDescription keys as pictured below.
Finally, we open the app in two devices, and, from the chat, we can start a call.
Congratulations! You've built the basis of a functioning Online Event app with Stream Chat and Dolby.io. I encourage you to browse through Stream Chat's docs, Dolby.io's docs, and experiment with the project you just built. Good luck on your Live Event app development!
If you also need a web version, there's a separate tutorial on how to build a live stream chat with Wowza and Stream.