Swift

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.

  1. Create a new file called VonageVideoSDK.swift.

  2. Start by copying the following code block and adding it to your VonageVideoSDK.swift file:

    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()
        }
    }
    
  3. Go ahead and replace YOUR_APP_ID with the application ID we generated earlier. Not that while the SDK parameter is labelled apiKey, a Vonage Application ID is valid.

  4. Log into your your Vonage Dashboard and navigate to the Video Playground. It is under Troubleshoot & Learn - Developer Tools - Video - Playground.

  5. Make sure that the "Create a new session" tab is selected at the top.

  6. Select "Yes" under "Have a specific Application ID?"

  7. Paste in the Application ID you generated before into the "Application ID" box that appears.

  8. Leave everything else as-is, and click "Create Session".

  9. On the next page that appears, copy the "SESSION ID".

  10. In VonageVideoSDK.swift, replace YOUR_SESSION_ID with the session ID we just copied.

  11. Click the "Connect" button at the top.

  12. Expand the "Session and token info" section at the top.

  13. Copy the "TOKEN" that was generated

  14. In VonageVideoSDK.swift, replace YOUR_TOKEN with the token we just copied.

  15. Save the VonageVideoSDK.swift file.

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.

Steps
1
Overview
2
Before You Begin
3
Configure a Vonage Video Application
4
Creating the Project
5
Setting Up Authentication
6
Connecting to the Session
7
Sending a Signal
8
Receiving a Signal
9
Testing your Code
10
Conclusion