Swift

Receiving a Signal

Signals are received on the session. When a Signal is received, in addition to the data that was sent, it will contain a from property which will have information about who sent the Signal. This can be used to differentiate between Signals the current user and sent and ones they receive.

  1. Copy the following code and paste it at the bottom of the VonageVideoSDK.swift file, outside the class definition:
extension VonageVideoSDK: OTSessionDelegate {
    func sessionDidConnect(_ session: OTSession) {
       isSessionConnected = true
    }
    
    func sessionDidDisconnect(_ session: OTSession) {
        isSessionConnected = false
    }
    
    func session(_ session: OTSession, didFailWithError error: OTError) {
        print("Session Failed to connect: \(error.localizedDescription)")
    }
    
    func session(_ session: OTSession, receivedSignalType type: String?, from connection: OTConnection?, with string: String?) {
        if let string = string, let type = type, let connection = connection {
            guard type == "msg" else { return }
            guard connection.connectionId != self.session.connection?.connectionId else { return }
            messages.append(.init(text: string, isUsers: false))
        }
    }
    
    func session(_ session: OTSession, streamCreated stream: OTStream) {}
    
    func session(_ session: OTSession, streamDestroyed stream: OTStream) {}
}

This code conforms the VonageVideoSDK class to the OTSessionDelegate. The OTSessionDelegate is how we will get updates from the SDK, for example if the session connects/disconnects and if there is an incoming Signal. The receivedSignalType delegate function is called when a Signal is received in the session, we will want to check that the Signal type is as expected and the Signal is not from the current user.

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.

以下の言語で利用可能:
JavaScript Java Swift
手順
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