Skip to content

AWS Kinesis Video WebRTC iOS 应用文档 AWS Kinesis Video WebRTC iOS Application Documentation

Morgan edited this page Mar 25, 2025 · 1 revision

AWS Kinesis Video WebRTC iOS Application Documentation

I. Overview

This document mainly introduces the functions and usage methods of key classes in the AWS Kinesis Video WebRTC iOS application, focusing on the ChannelConfigurationViewController, VideoViewController, SignalingClient, WebRTCClient, and KVSSigner classes. These classes work together to implement video communication functionality based on WebRTC.

II. Key Class Introduction

2.1 ChannelConfigurationViewController

2.1.1 Function Overview

ChannelConfigurationViewController is a view controller responsible for handling user - input configuration information, such as channel name, region name, client ID, etc., and establishing a WebRTC connection based on this information. It also manages the display of connection status and error handling.

2.1.2 Key Attributes

  • sendAudioEnabled: A boolean value that controls whether audio sending is enabled.
  • isMaster: A boolean value indicating whether the current user is in the master role.
  • signalingConnected: A boolean value indicating whether the signaling connection has been established.
  • signalingClient: An instance of SignalingClient used to communicate with the signaling server.
  • webRTCClient: An instance of WebRTCClient used to handle WebRTC connections.
  • awsCredentials: An instance of AWSStaticCredentialsProvider used to provide AWS credentials.
  • localSenderId: A string representing the client ID of the local sender.

2.1.3 Key Methods

  • connectAsRole(): This is the core method for establishing a WebRTC connection. The main steps are as follows:
    1. Verify whether the user - input channel name and region name are empty.
    2. Try to retrieve the ARN of the signaling channel. If the channel does not exist, create a new one.
    3. Check whether the media server is used to store recorded content (only applicable to the master role).
    4. Obtain the endpoint information of the signaling channel.
    5. Create a signed WSS URL.
    6. Get ICE candidates.
    7. Initialize WebRTCClient and SignalingClient and establish a connection.
    8. Display VideoViewController after a 2 - second delay.
  • createChannel(channelName: String): Create a signaling channel and return the ARN of the created channel.
  • retrieveChannelARN(channelName: String): Try to retrieve the ARN of the signaling channel with the specified name.
  • isUsingMediaServer(channelARN: String, channelName: String): Check whether the signaling channel has enabled media server storage.
  • getIceCandidates(channelARN: String, endpoint: AWSEndpoint, regionType: AWSRegionType, clientId: String): Get the list of ICE server configurations.
  • getSignallingEndpoints(channelARN: String, region: String, isMaster: Bool, useMediaServer: Bool): Obtain the endpoint information of the signaling channel.
  • createSignedWSSUrl(channelARN: String, region: String, wssEndpoint: String?, isMaster: Bool): Create a signed WSS URL.

2.1.4 Delegate Methods

  • SignalClientDelegate: Handles events such as connection, disconnection, receiving remote SDP, and ICE candidates of the signaling client.
  • WebRTCClientDelegate: Handles events such as generating local ICE candidates, connection state changes, and receiving data of the WebRTC client.

2.2 VideoViewController

2.2.1 Function Overview

VideoViewController is a view controller used to display the video call interface. It relies on WebRTCClient and SignalingClient to handle video streams and signaling interactions.

2.2.2 Key Attributes

  • webRTCClient: An instance of WebRTCClient used to handle WebRTC connections and video streams.
  • signalingClient: An instance of SignalingClient used to communicate with the signaling server.
  • localSenderClientID: A string representing the client ID of the local sender.
  • isMaster: A boolean value indicating whether the current user is in the master role.
  • mediaServerEndPoint: A string representing the endpoint information of the media server.

2.2.3 Usage Method

VideoViewController is instantiated and displayed in the connectAsRole() method of ChannelConfigurationViewController. It receives instances of WebRTCClient and SignalingClient, as well as the client ID of the local sender, the role, and the media server endpoint information.

2.3 SignalingClient

2.3.1 Function Overview

SignalingClient is responsible for communicating with the signaling server and handling signaling interactions for WebRTC connections, such as sending and receiving SDP information and ICE candidates.

2.3.2 Key Methods

  • connect(): Establish a connection with the signaling server.
  • sendIceCandidate(rtcIceCandidate: RTCIceCandidate, master: Bool, recipientClientId: String, senderClientId: String): Send an ICE candidate to the specified recipient.

2.3.3 Delegate Methods

The delegate methods of SignalingClient are implemented in ChannelConfigurationViewController to handle events such as connection state changes, receiving remote SDP, and ICE candidates.

2.4 WebRTCClient

2.4.1 Function Overview

WebRTCClient is responsible for handling WebRTC connections, including creating peer - to - peer connections, collecting ICE candidates, setting remote SDP, and ICE candidates.

2.4.2 Key Methods

  • set(remoteSdp: RTCSessionDescription, clientId: String, completion: @escaping (Bool) -> Void): Set the remote SDP information.
  • set(remoteCandidate: RTCIceCandidate, clientId: String): Set the remote ICE candidate.
  • didGenerate(candidate: RTCIceCandidate): A delegate method called when a local ICE candidate is generated.
  • didChangeConnectionState(state: RTCIceConnectionState): A delegate method called when the WebRTC connection state changes.

2.4.3 Delegate Methods

The delegate methods of WebRTCClient are implemented in ChannelConfigurationViewController to handle events such as generating local ICE candidates, connection state changes, and receiving data.

2.5 KVSSigner

2.5.1 Function Overview

KVSSigner is used to sign the WSS URL to ensure the security of communication with the signaling server.

2.5.2 Key Methods

  • sign(signRequest: URL, secretKey: String, accessKey: String, sessionToken: String, wssRequest: URL, region: String): Sign the specified request URL and return the signed WSS URL.

III. Interaction Flow between Classes

  1. The user enters configuration information in ChannelConfigurationViewController and clicks the connect button.
  2. ChannelConfigurationViewController calls the connectAsRole() method to perform a series of verification and configuration operations, including creating a signaling channel, obtaining endpoint information, and signing the WSS URL.
  3. ChannelConfigurationViewController initializes WebRTCClient and SignalingClient and calls the connect() method of SignalingClient to establish a connection with the signaling server.
  4. SignalingClient communicates with the signaling server to handle the exchange of SDP information and ICE candidates.
  5. WebRTCClient handles the WebRTC connection, including collecting ICE candidates, setting remote SDP, and ICE candidates.
  6. When the connection is successfully established, ChannelConfigurationViewController displays VideoViewController to start the video call.

IV. Notes

  • Before use, replace AWSAccessKey and AWSSecretKey with actual AWS credentials.
  • Ensure that the entered channel name, region name, and other information are correct; otherwise, the connection may fail.
  • When using the media server to store recorded content, ensure that the audio is enabled.

AWS Kinesis Video WebRTC iOS 应用文档

一、概述

本文档主要介绍 AWS Kinesis Video WebRTC iOS 应用中关键类的功能和使用方法,重点涉及 ChannelConfigurationViewControllerVideoViewControllerSignalingClientWebRTCClient 以及 KVSSigner 类。这些类协同工作,实现了基于 WebRTC 的视频通信功能。

二、关键类介绍

2.1 ChannelConfigurationViewController

2.1.1 功能概述

ChannelConfigurationViewController 是一个视图控制器,负责处理用户输入的配置信息,如通道名称、区域名称、客户端 ID 等,并根据这些信息建立 WebRTC 连接。它还管理着连接状态的显示和错误处理。

2.1.2 关键属性

  • sendAudioEnabled:布尔值,控制是否启用音频发送。
  • isMaster:布尔值,指示当前用户是否为主角色。
  • signalingConnected:布尔值,指示信令连接是否已建立。
  • signalingClientSignalingClient 类型,用于与信令服务器进行通信。
  • webRTCClientWebRTCClient 类型,用于处理 WebRTC 连接。
  • awsCredentialsAWSStaticCredentialsProvider 类型,用于提供 AWS 凭证。
  • localSenderId:字符串,本地发送者的客户端 ID。

2.1.3 关键方法

  • connectAsRole():该方法是建立 WebRTC 连接的核心方法,主要步骤如下:
    1. 验证用户输入的通道名称和区域名称是否为空。
    2. 尝试检索信令通道的 ARN,如果通道不存在则创建新通道。
    3. 检查是否使用媒体服务器存储录制内容(仅适用于主角色)。
    4. 获取信令通道的端点信息。
    5. 创建签名的 WSS URL。
    6. 获取 ICE 候选者。
    7. 初始化 WebRTCClientSignalingClient 并建立连接。
    8. 延迟 2 秒后显示 VideoViewController
  • createChannel(channelName: String):创建信令通道,并返回创建成功后的通道 ARN。
  • retrieveChannelARN(channelName: String):尝试检索指定名称的信令通道的 ARN。
  • isUsingMediaServer(channelARN: String, channelName: String):检查信令通道是否启用了媒体服务器存储。
  • getIceCandidates(channelARN: String, endpoint: AWSEndpoint, regionType: AWSRegionType, clientId: String):获取 ICE 服务器配置列表。
  • getSignallingEndpoints(channelARN: String, region: String, isMaster: Bool, useMediaServer: Bool):获取信令通道的端点信息。
  • createSignedWSSUrl(channelARN: String, region: String, wssEndpoint: String?, isMaster: Bool):创建签名的 WSS URL。

2.1.4 代理方法

  • SignalClientDelegate:处理信令客户端的连接、断开连接、接收远程 SDP 和 ICE 候选者等事件。
  • WebRTCClientDelegate:处理 WebRTC 客户端生成本地 ICE 候选者、连接状态变化和接收数据等事件。

2.2 VideoViewController

2.2.1 功能概述

VideoViewController 是一个视图控制器,用于显示视频通话界面。它依赖于 WebRTCClientSignalingClient 来处理视频流和信令交互。

2.2.2 关键属性

  • webRTCClientWebRTCClient 类型,用于处理 WebRTC 连接和视频流。
  • signalingClientSignalingClient 类型,用于与信令服务器进行通信。
  • localSenderClientID:字符串,本地发送者的客户端 ID。
  • isMaster:布尔值,指示当前用户是否为主角色。
  • mediaServerEndPoint:字符串,媒体服务器的端点信息。

2.2.3 使用方法

VideoViewControllerChannelConfigurationViewControllerconnectAsRole() 方法中被实例化并显示。它接收 WebRTCClientSignalingClient 的实例,以及本地发送者的客户端 ID、角色和媒体服务器端点信息。

2.3 SignalingClient

2.3.1 功能概述

SignalingClient 负责与信令服务器进行通信,处理 WebRTC 连接的信令交互,如发送和接收 SDP 信息、ICE 候选者等。

2.3.2 关键方法

  • connect():建立与信令服务器的连接。
  • sendIceCandidate(rtcIceCandidate: RTCIceCandidate, master: Bool, recipientClientId: String, senderClientId: String):发送 ICE 候选者到指定的接收者。

2.3.3 代理方法

SignalingClient 的代理方法在 ChannelConfigurationViewController 中实现,用于处理连接状态变化、接收远程 SDP 和 ICE 候选者等事件。

2.4 WebRTCClient

2.4.1 功能概述

WebRTCClient 负责处理 WebRTC 连接,包括创建对等连接、收集 ICE 候选者、设置远程 SDP 和 ICE 候选者等。

2.4.2 关键方法

  • set(remoteSdp: RTCSessionDescription, clientId: String, completion: @escaping (Bool) -> Void):设置远程 SDP 信息。
  • set(remoteCandidate: RTCIceCandidate, clientId: String):设置远程 ICE 候选者。
  • didGenerate(candidate: RTCIceCandidate):生成本地 ICE 候选者时调用的代理方法。
  • didChangeConnectionState(state: RTCIceConnectionState):WebRTC 连接状态变化时调用的代理方法。

2.4.3 代理方法

WebRTCClient 的代理方法在 ChannelConfigurationViewController 中实现,用于处理生成本地 ICE 候选者、连接状态变化和接收数据等事件。

2.5 KVSSigner

2.5.1 功能概述

KVSSigner 用于对 WSS URL 进行签名,确保与信令服务器的通信安全。

2.5.2 关键方法

  • sign(signRequest: URL, secretKey: String, accessKey: String, sessionToken: String, wssRequest: URL, region: String):对指定的请求 URL 进行签名,并返回签名后的 WSS URL。

三、类之间的交互流程

  1. 用户在 ChannelConfigurationViewController 中输入配置信息,点击连接按钮。
  2. ChannelConfigurationViewController 调用 connectAsRole() 方法,进行一系列的验证和配置操作,包括创建信令通道、获取端点信息、签名 WSS URL 等。
  3. ChannelConfigurationViewController 初始化 WebRTCClientSignalingClient,并调用 SignalingClientconnect() 方法建立与信令服务器的连接。
  4. SignalingClient 与信令服务器进行通信,处理 SDP 信息和 ICE 候选者的交换。
  5. WebRTCClient 处理 WebRTC 连接,包括收集 ICE 候选者、设置远程 SDP 和 ICE 候选者等。
  6. 当连接建立成功后,ChannelConfigurationViewController 显示 VideoViewController,开始视频通话。

四、注意事项

  • 在使用前,需要将 AWSAccessKeyAWSSecretKey 替换为实际的 AWS 凭证。
  • 确保输入的通道名称、区域名称等信息正确,否则可能导致连接失败。
  • 在使用媒体服务器存储录制内容时,需要确保音频已启用。