1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
// =================================================================
//
//                           * WARNING *
//
//                    This file is generated!
//
//  Changes made to this file will be overwritten. If changes are
//  required to the generated code, the service_crategen project
//  must be updated to generate the changes.
//
// =================================================================

use std::error::Error;
use std::fmt;

use async_trait::async_trait;
use rusoto_core::credential::ProvideAwsCredentials;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoError};

use rusoto_core::proto;
use rusoto_core::signature::SignedRequest;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
use serde_json;
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct GetIceServerConfigRequest {
    /// <p>The ARN of the signaling channel to be used for the peer-to-peer connection between configured peers. </p>
    #[serde(rename = "ChannelARN")]
    pub channel_arn: String,
    /// <p>Unique identifier for the viewer. Must be unique within the signaling channel.</p>
    #[serde(rename = "ClientId")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub client_id: Option<String>,
    /// <p>Specifies the desired service. Currently, <code>TURN</code> is the only valid value.</p>
    #[serde(rename = "Service")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub service: Option<String>,
    /// <p>An optional user ID to be associated with the credentials.</p>
    #[serde(rename = "Username")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub username: Option<String>,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct GetIceServerConfigResponse {
    /// <p>The list of ICE server information objects.</p>
    #[serde(rename = "IceServerList")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ice_server_list: Option<Vec<IceServer>>,
}

/// <p>A structure for the ICE server connection data.</p>
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct IceServer {
    /// <p>A password to login to the ICE server.</p>
    #[serde(rename = "Password")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub password: Option<String>,
    /// <p>The period of time, in seconds, during which the username and password are valid.</p>
    #[serde(rename = "Ttl")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ttl: Option<i64>,
    /// <p>An array of URIs, in the form specified in the <a href="https://tools.ietf.org/html/draft-petithuguenin-behave-turn-uris-03">I-D.petithuguenin-behave-turn-uris</a> spec. These URIs provide the different addresses and/or protocols that can be used to reach the TURN server.</p>
    #[serde(rename = "Uris")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uris: Option<Vec<String>>,
    /// <p>A username to login to the ICE server.</p>
    #[serde(rename = "Username")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub username: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct SendAlexaOfferToMasterRequest {
    /// <p>The ARN of the signaling channel by which Alexa and the master peer communicate.</p>
    #[serde(rename = "ChannelARN")]
    pub channel_arn: String,
    /// <p>The base64-encoded SDP offer content.</p>
    #[serde(rename = "MessagePayload")]
    pub message_payload: String,
    /// <p>The unique identifier for the sender client.</p>
    #[serde(rename = "SenderClientId")]
    pub sender_client_id: String,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct SendAlexaOfferToMasterResponse {
    /// <p>The base64-encoded SDP answer content.</p>
    #[serde(rename = "Answer")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub answer: Option<String>,
}

/// Errors returned by GetIceServerConfig
#[derive(Debug, PartialEq)]
pub enum GetIceServerConfigError {
    /// <p>Your request was throttled because you have exceeded the limit of allowed client calls. Try making the call later.</p>
    ClientLimitExceeded(String),
    /// <p>The value for this input parameter is invalid.</p>
    InvalidArgument(String),
    /// <p>The specified client is invalid.</p>
    InvalidClient(String),
    /// <p>The caller is not authorized to perform this operation.</p>
    NotAuthorized(String),
    /// <p>The specified resource is not found.</p>
    ResourceNotFound(String),
    /// <p>If the client session is expired. Once the client is connected, the session is valid for 45 minutes. Client should reconnect to the channel to continue sending/receiving messages.</p>
    SessionExpired(String),
}

impl GetIceServerConfigError {
    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<GetIceServerConfigError> {
        if let Some(err) = proto::json::Error::parse_rest(&res) {
            match err.typ.as_str() {
                "ClientLimitExceededException" => {
                    return RusotoError::Service(GetIceServerConfigError::ClientLimitExceeded(
                        err.msg,
                    ))
                }
                "InvalidArgumentException" => {
                    return RusotoError::Service(GetIceServerConfigError::InvalidArgument(err.msg))
                }
                "InvalidClientException" => {
                    return RusotoError::Service(GetIceServerConfigError::InvalidClient(err.msg))
                }
                "NotAuthorizedException" => {
                    return RusotoError::Service(GetIceServerConfigError::NotAuthorized(err.msg))
                }
                "ResourceNotFoundException" => {
                    return RusotoError::Service(GetIceServerConfigError::ResourceNotFound(err.msg))
                }
                "SessionExpiredException" => {
                    return RusotoError::Service(GetIceServerConfigError::SessionExpired(err.msg))
                }
                "ValidationException" => return RusotoError::Validation(err.msg),
                _ => {}
            }
        }
        RusotoError::Unknown(res)
    }
}
impl fmt::Display for GetIceServerConfigError {
    #[allow(unused_variables)]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            GetIceServerConfigError::ClientLimitExceeded(ref cause) => write!(f, "{}", cause),
            GetIceServerConfigError::InvalidArgument(ref cause) => write!(f, "{}", cause),
            GetIceServerConfigError::InvalidClient(ref cause) => write!(f, "{}", cause),
            GetIceServerConfigError::NotAuthorized(ref cause) => write!(f, "{}", cause),
            GetIceServerConfigError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
            GetIceServerConfigError::SessionExpired(ref cause) => write!(f, "{}", cause),
        }
    }
}
impl Error for GetIceServerConfigError {}
/// Errors returned by SendAlexaOfferToMaster
#[derive(Debug, PartialEq)]
pub enum SendAlexaOfferToMasterError {
    /// <p>Your request was throttled because you have exceeded the limit of allowed client calls. Try making the call later.</p>
    ClientLimitExceeded(String),
    /// <p>The value for this input parameter is invalid.</p>
    InvalidArgument(String),
    /// <p>The caller is not authorized to perform this operation.</p>
    NotAuthorized(String),
    /// <p>The specified resource is not found.</p>
    ResourceNotFound(String),
}

impl SendAlexaOfferToMasterError {
    pub fn from_response(res: BufferedHttpResponse) -> RusotoError<SendAlexaOfferToMasterError> {
        if let Some(err) = proto::json::Error::parse_rest(&res) {
            match err.typ.as_str() {
                "ClientLimitExceededException" => {
                    return RusotoError::Service(SendAlexaOfferToMasterError::ClientLimitExceeded(
                        err.msg,
                    ))
                }
                "InvalidArgumentException" => {
                    return RusotoError::Service(SendAlexaOfferToMasterError::InvalidArgument(
                        err.msg,
                    ))
                }
                "NotAuthorizedException" => {
                    return RusotoError::Service(SendAlexaOfferToMasterError::NotAuthorized(
                        err.msg,
                    ))
                }
                "ResourceNotFoundException" => {
                    return RusotoError::Service(SendAlexaOfferToMasterError::ResourceNotFound(
                        err.msg,
                    ))
                }
                "ValidationException" => return RusotoError::Validation(err.msg),
                _ => {}
            }
        }
        RusotoError::Unknown(res)
    }
}
impl fmt::Display for SendAlexaOfferToMasterError {
    #[allow(unused_variables)]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            SendAlexaOfferToMasterError::ClientLimitExceeded(ref cause) => write!(f, "{}", cause),
            SendAlexaOfferToMasterError::InvalidArgument(ref cause) => write!(f, "{}", cause),
            SendAlexaOfferToMasterError::NotAuthorized(ref cause) => write!(f, "{}", cause),
            SendAlexaOfferToMasterError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
        }
    }
}
impl Error for SendAlexaOfferToMasterError {}
/// Trait representing the capabilities of the Amazon Kinesis Video Signaling Channels API. Amazon Kinesis Video Signaling Channels clients implement this trait.
#[async_trait]
pub trait KinesisVideoSignaling {
    /// <p>Gets the Interactive Connectivity Establishment (ICE) server configuration information, including URIs, username, and password which can be used to configure the WebRTC connection. The ICE component uses this configuration information to setup the WebRTC connection, including authenticating with the Traversal Using Relays around NAT (TURN) relay server. </p> <p>TURN is a protocol that is used to improve the connectivity of peer-to-peer applications. By providing a cloud-based relay service, TURN ensures that a connection can be established even when one or more peers are incapable of a direct peer-to-peer connection. For more information, see <a href="https://tools.ietf.org/html/draft-uberti-rtcweb-turn-rest-00">A REST API For Access To TURN Services</a>.</p> <p> You can invoke this API to establish a fallback mechanism in case either of the peers is unable to establish a direct peer-to-peer connection over a signaling channel. You must specify either a signaling channel ARN or the client ID in order to invoke this API.</p>
    async fn get_ice_server_config(
        &self,
        input: GetIceServerConfigRequest,
    ) -> Result<GetIceServerConfigResponse, RusotoError<GetIceServerConfigError>>;

    /// <p>This API allows you to connect WebRTC-enabled devices with Alexa display devices. When invoked, it sends the Alexa Session Description Protocol (SDP) offer to the master peer. The offer is delivered as soon as the master is connected to the specified signaling channel. This API returns the SDP answer from the connected master. If the master is not connected to the signaling channel, redelivery requests are made until the message expires.</p>
    async fn send_alexa_offer_to_master(
        &self,
        input: SendAlexaOfferToMasterRequest,
    ) -> Result<SendAlexaOfferToMasterResponse, RusotoError<SendAlexaOfferToMasterError>>;
}
/// A client for the Amazon Kinesis Video Signaling Channels API.
#[derive(Clone)]
pub struct KinesisVideoSignalingClient {
    client: Client,
    region: region::Region,
}

impl KinesisVideoSignalingClient {
    /// Creates a client backed by the default tokio event loop.
    ///
    /// The client will use the default credentials provider and tls client.
    pub fn new(region: region::Region) -> KinesisVideoSignalingClient {
        KinesisVideoSignalingClient {
            client: Client::shared(),
            region,
        }
    }

    pub fn new_with<P, D>(
        request_dispatcher: D,
        credentials_provider: P,
        region: region::Region,
    ) -> KinesisVideoSignalingClient
    where
        P: ProvideAwsCredentials + Send + Sync + 'static,
        D: DispatchSignedRequest + Send + Sync + 'static,
    {
        KinesisVideoSignalingClient {
            client: Client::new_with(credentials_provider, request_dispatcher),
            region,
        }
    }

    pub fn new_with_client(client: Client, region: region::Region) -> KinesisVideoSignalingClient {
        KinesisVideoSignalingClient { client, region }
    }
}

#[async_trait]
impl KinesisVideoSignaling for KinesisVideoSignalingClient {
    /// <p>Gets the Interactive Connectivity Establishment (ICE) server configuration information, including URIs, username, and password which can be used to configure the WebRTC connection. The ICE component uses this configuration information to setup the WebRTC connection, including authenticating with the Traversal Using Relays around NAT (TURN) relay server. </p> <p>TURN is a protocol that is used to improve the connectivity of peer-to-peer applications. By providing a cloud-based relay service, TURN ensures that a connection can be established even when one or more peers are incapable of a direct peer-to-peer connection. For more information, see <a href="https://tools.ietf.org/html/draft-uberti-rtcweb-turn-rest-00">A REST API For Access To TURN Services</a>.</p> <p> You can invoke this API to establish a fallback mechanism in case either of the peers is unable to establish a direct peer-to-peer connection over a signaling channel. You must specify either a signaling channel ARN or the client ID in order to invoke this API.</p>
    #[allow(unused_mut)]
    async fn get_ice_server_config(
        &self,
        input: GetIceServerConfigRequest,
    ) -> Result<GetIceServerConfigResponse, RusotoError<GetIceServerConfigError>> {
        let request_uri = "/v1/get-ice-server-config";

        let mut request = SignedRequest::new("POST", "kinesisvideo", &self.region, &request_uri);
        request.set_content_type("application/x-amz-json-1.1".to_owned());

        let encoded = Some(serde_json::to_vec(&input).unwrap());
        request.set_payload(encoded);

        let mut response = self
            .client
            .sign_and_dispatch(request)
            .await
            .map_err(RusotoError::from)?;
        if response.status.is_success() {
            let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
            let result = proto::json::ResponsePayload::new(&response)
                .deserialize::<GetIceServerConfigResponse, _>()?;

            Ok(result)
        } else {
            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
            Err(GetIceServerConfigError::from_response(response))
        }
    }

    /// <p>This API allows you to connect WebRTC-enabled devices with Alexa display devices. When invoked, it sends the Alexa Session Description Protocol (SDP) offer to the master peer. The offer is delivered as soon as the master is connected to the specified signaling channel. This API returns the SDP answer from the connected master. If the master is not connected to the signaling channel, redelivery requests are made until the message expires.</p>
    #[allow(unused_mut)]
    async fn send_alexa_offer_to_master(
        &self,
        input: SendAlexaOfferToMasterRequest,
    ) -> Result<SendAlexaOfferToMasterResponse, RusotoError<SendAlexaOfferToMasterError>> {
        let request_uri = "/v1/send-alexa-offer-to-master";

        let mut request = SignedRequest::new("POST", "kinesisvideo", &self.region, &request_uri);
        request.set_content_type("application/x-amz-json-1.1".to_owned());

        let encoded = Some(serde_json::to_vec(&input).unwrap());
        request.set_payload(encoded);

        let mut response = self
            .client
            .sign_and_dispatch(request)
            .await
            .map_err(RusotoError::from)?;
        if response.status.is_success() {
            let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
            let result = proto::json::ResponsePayload::new(&response)
                .deserialize::<SendAlexaOfferToMasterResponse, _>()?;

            Ok(result)
        } else {
            let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
            Err(SendAlexaOfferToMasterError::from_response(response))
        }
    }
}