Publishing a Stream to the Session
When the app connects to the Vonage Video session, we want it to publish an audio-video stream to the session, using the device's camera and microphone:
- Add a
publisher&pubViewproperties to theVonageVideoManagerclass.
The OTPublisher class is defined in the iOS SDK. It uses the device's camera and microphone, to publish a stream Vonage Video session.
- Modify the implementation of the
sessionDidConnect(_:)method to include code to publish a stream to the session:
When the app connects to a session, it initializes an instance of the OTPublisher, defined in the iOS SDK. The constructor takes one parameter: the object that implements the OTPublisherDelegate protocol.
The code then passes the OTPublisher object in as a parameter of the session.publish() method. This method publishes an audio-video stream to the session, using the camera and microphone of the iOS device. (Note that in the Xcode simulator, the iOS SDK uses a test video when publishing a stream.)
The OTPublisher object has a view property, which is a UIView object. This view displays the video captured from the device's camera. In the next steps we will display this view in SwiftUI (in case of UIKit it is simple and can be done with a addSubview(view) function)
- Next we need to create a wrapper around UIView to be able to use it in SwiftUI world:
- Now let's connect
VonageVideoManagerto theContentViewas a property, we'll need it to interact with the data. The solution is flexible and fits any architecture, so if you're using ViewModel, Interactors or anything else in your project - we've got you covered:
- It's time to populate the body of the view, we will use our
Wrapview that we've created earlier:
- Now we will implement methods of the
OTPublisherDelegateprotocol. This protocol includes methods for handling events related to the publisher. Add the following code to the end of theVonageVideoManager.swiftfile, after the closing bracket of theOTSessionDelegateextension:
- If the client fails to publish to the session, an
OTErrorobject is passed into thepublisher(_: didFailWithError:)method.
Debug your application. If the app successfully connects to the session, it will publish a stream to the session, and you will see the publisher's video in the app.
Basic video chat
Learn the basic concepts of the Vonage Video API platform, including how users can communicate through video, voice, and messaging. Explore a basic Vonage Video API flow.