-
Notifications
You must be signed in to change notification settings - Fork 0
AWS Kinesis Video WebRTC iOS 应用文档 AWS Kinesis Video WebRTC iOS Application Documentation
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.
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.
-
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 ofSignalingClient
used to communicate with the signaling server. -
webRTCClient
: An instance ofWebRTCClient
used to handle WebRTC connections. -
awsCredentials
: An instance ofAWSStaticCredentialsProvider
used to provide AWS credentials. -
localSenderId
: A string representing the client ID of the local sender.
-
connectAsRole()
: This is the core method for establishing a WebRTC connection. The main steps are as follows:- Verify whether the user - input channel name and region name are empty.
- Try to retrieve the ARN of the signaling channel. If the channel does not exist, create a new one.
- Check whether the media server is used to store recorded content (only applicable to the master role).
- Obtain the endpoint information of the signaling channel.
- Create a signed WSS URL.
- Get ICE candidates.
- Initialize
WebRTCClient
andSignalingClient
and establish a connection. - 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.
-
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.
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.
-
webRTCClient
: An instance ofWebRTCClient
used to handle WebRTC connections and video streams. -
signalingClient
: An instance ofSignalingClient
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.
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.
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.
-
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.
The delegate methods of SignalingClient
are implemented in ChannelConfigurationViewController
to handle events such as connection state changes, receiving remote SDP, and ICE candidates.
WebRTCClient
is responsible for handling WebRTC connections, including creating peer - to - peer connections, collecting ICE candidates, setting remote SDP, and ICE candidates.
-
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.
The delegate methods of WebRTCClient
are implemented in ChannelConfigurationViewController
to handle events such as generating local ICE candidates, connection state changes, and receiving data.
KVSSigner
is used to sign the WSS URL to ensure the security of communication with the signaling server.
-
sign(signRequest: URL, secretKey: String, accessKey: String, sessionToken: String, wssRequest: URL, region: String)
: Sign the specified request URL and return the signed WSS URL.
- The user enters configuration information in
ChannelConfigurationViewController
and clicks the connect button. -
ChannelConfigurationViewController
calls theconnectAsRole()
method to perform a series of verification and configuration operations, including creating a signaling channel, obtaining endpoint information, and signing the WSS URL. -
ChannelConfigurationViewController
initializesWebRTCClient
andSignalingClient
and calls theconnect()
method ofSignalingClient
to establish a connection with the signaling server. -
SignalingClient
communicates with the signaling server to handle the exchange of SDP information and ICE candidates. -
WebRTCClient
handles the WebRTC connection, including collecting ICE candidates, setting remote SDP, and ICE candidates. - When the connection is successfully established,
ChannelConfigurationViewController
displaysVideoViewController
to start the video call.
- Before use, replace
AWSAccessKey
andAWSSecretKey
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 应用中关键类的功能和使用方法,重点涉及 ChannelConfigurationViewController
、VideoViewController
、SignalingClient
、WebRTCClient
以及 KVSSigner
类。这些类协同工作,实现了基于 WebRTC 的视频通信功能。
ChannelConfigurationViewController
是一个视图控制器,负责处理用户输入的配置信息,如通道名称、区域名称、客户端 ID 等,并根据这些信息建立 WebRTC 连接。它还管理着连接状态的显示和错误处理。
-
sendAudioEnabled
:布尔值,控制是否启用音频发送。 -
isMaster
:布尔值,指示当前用户是否为主角色。 -
signalingConnected
:布尔值,指示信令连接是否已建立。 -
signalingClient
:SignalingClient
类型,用于与信令服务器进行通信。 -
webRTCClient
:WebRTCClient
类型,用于处理 WebRTC 连接。 -
awsCredentials
:AWSStaticCredentialsProvider
类型,用于提供 AWS 凭证。 -
localSenderId
:字符串,本地发送者的客户端 ID。
-
connectAsRole()
:该方法是建立 WebRTC 连接的核心方法,主要步骤如下:- 验证用户输入的通道名称和区域名称是否为空。
- 尝试检索信令通道的 ARN,如果通道不存在则创建新通道。
- 检查是否使用媒体服务器存储录制内容(仅适用于主角色)。
- 获取信令通道的端点信息。
- 创建签名的 WSS URL。
- 获取 ICE 候选者。
- 初始化
WebRTCClient
和SignalingClient
并建立连接。 - 延迟 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。
-
SignalClientDelegate
:处理信令客户端的连接、断开连接、接收远程 SDP 和 ICE 候选者等事件。 -
WebRTCClientDelegate
:处理 WebRTC 客户端生成本地 ICE 候选者、连接状态变化和接收数据等事件。
VideoViewController
是一个视图控制器,用于显示视频通话界面。它依赖于 WebRTCClient
和 SignalingClient
来处理视频流和信令交互。
-
webRTCClient
:WebRTCClient
类型,用于处理 WebRTC 连接和视频流。 -
signalingClient
:SignalingClient
类型,用于与信令服务器进行通信。 -
localSenderClientID
:字符串,本地发送者的客户端 ID。 -
isMaster
:布尔值,指示当前用户是否为主角色。 -
mediaServerEndPoint
:字符串,媒体服务器的端点信息。
VideoViewController
在 ChannelConfigurationViewController
的 connectAsRole()
方法中被实例化并显示。它接收 WebRTCClient
和 SignalingClient
的实例,以及本地发送者的客户端 ID、角色和媒体服务器端点信息。
SignalingClient
负责与信令服务器进行通信,处理 WebRTC 连接的信令交互,如发送和接收 SDP 信息、ICE 候选者等。
-
connect()
:建立与信令服务器的连接。 -
sendIceCandidate(rtcIceCandidate: RTCIceCandidate, master: Bool, recipientClientId: String, senderClientId: String)
:发送 ICE 候选者到指定的接收者。
SignalingClient
的代理方法在 ChannelConfigurationViewController
中实现,用于处理连接状态变化、接收远程 SDP 和 ICE 候选者等事件。
WebRTCClient
负责处理 WebRTC 连接,包括创建对等连接、收集 ICE 候选者、设置远程 SDP 和 ICE 候选者等。
-
set(remoteSdp: RTCSessionDescription, clientId: String, completion: @escaping (Bool) -> Void)
:设置远程 SDP 信息。 -
set(remoteCandidate: RTCIceCandidate, clientId: String)
:设置远程 ICE 候选者。 -
didGenerate(candidate: RTCIceCandidate)
:生成本地 ICE 候选者时调用的代理方法。 -
didChangeConnectionState(state: RTCIceConnectionState)
:WebRTC 连接状态变化时调用的代理方法。
WebRTCClient
的代理方法在 ChannelConfigurationViewController
中实现,用于处理生成本地 ICE 候选者、连接状态变化和接收数据等事件。
KVSSigner
用于对 WSS URL 进行签名,确保与信令服务器的通信安全。
-
sign(signRequest: URL, secretKey: String, accessKey: String, sessionToken: String, wssRequest: URL, region: String)
:对指定的请求 URL 进行签名,并返回签名后的 WSS URL。
- 用户在
ChannelConfigurationViewController
中输入配置信息,点击连接按钮。 -
ChannelConfigurationViewController
调用connectAsRole()
方法,进行一系列的验证和配置操作,包括创建信令通道、获取端点信息、签名 WSS URL 等。 -
ChannelConfigurationViewController
初始化WebRTCClient
和SignalingClient
,并调用SignalingClient
的connect()
方法建立与信令服务器的连接。 -
SignalingClient
与信令服务器进行通信,处理 SDP 信息和 ICE 候选者的交换。 -
WebRTCClient
处理 WebRTC 连接,包括收集 ICE 候选者、设置远程 SDP 和 ICE 候选者等。 - 当连接建立成功后,
ChannelConfigurationViewController
显示VideoViewController
,开始视频通话。
- 在使用前,需要将
AWSAccessKey
和AWSSecretKey
替换为实际的 AWS 凭证。 - 确保输入的通道名称、区域名称等信息正确,否则可能导致连接失败。
- 在使用媒体服务器存储录制内容时,需要确保音频已启用。