Setting Up Authentication
In order to connect to a Vonage Video session, the client will need access to some authentication credentials — an App ID, Session ID, and Token.
In a production application, these credentials should be generated using a Server SDKs, but to speed things up we will hard code the values for now.
Create a new file called
VonageVideoSDK.swift.Start by copying the following code block and adding it to your
VonageVideoSDK.swiftfile:import OpenTok // Replace with your Vonage Application ID let kAppId = "YOUR_APP_ID" // Replace with your generated session ID let kSessionId = "YOUR_SESSION_ID" // Replace with your generated token let kToken = "YOUR_TOKEN" struct Signal: Identifiable { let id = UUID() let text: String let isUsers: Bool } class VonageVideoSDK: NSObject, ObservableObject { @Published var isSessionConnected = false @Published var messages: [Signal] = [] lazy var session: OTSession = { return OTSession(apiKey: kAppId, sessionId: kSessionId, delegate: self)! }() override init() { super.init() } }Go ahead and replace
YOUR_APP_IDwith the application ID we generated earlier. Not that while the SDK parameter is labelledapiKey, a Vonage Application ID is valid.Log into your your Vonage Dashboard and navigate to the Video Playground. It is under Troubleshoot & Learn - Developer Tools - Video - Playground.
Make sure that the "Create a new session" tab is selected at the top.
Select "Yes" under "Have a specific Application ID?"
Paste in the Application ID you generated before into the "Application ID" box that appears.
Leave everything else as-is, and click "Create Session".
On the next page that appears, copy the "SESSION ID".
In
VonageVideoSDK.swift, replaceYOUR_SESSION_IDwith the session ID we just copied.Click the "Connect" button at the top.
Expand the "Session and token info" section at the top.
Copy the "TOKEN" that was generated
In
VonageVideoSDK.swift, replaceYOUR_TOKENwith the token we just copied.Save the
VonageVideoSDK.swiftfile.
Important: You can continue to get the session ID and token values from your Account during testing and development, but before you go into production you must set up a server.
This information will allow our client-side code to talk to the Vonage Video API.
Basic text chat
Follow this tutorial to build basic text chat from scratch using the Vonage Video API. It is the quickest way to build a proof of concept for this functionality on the video platform.