BlueGit

ict rusty-teams

Files

rusty-teams / vendor / libwebrtc / src / native / ice_candidate.rs

ice_candidate.rs

ice_candidate.rs 1.7 KiB Download Raw
1// Copyright 2025 LiveKit, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use cxx::SharedPtr;
16use webrtc_sys::jsep as sys_jsep;
17
18use crate::{ice_candidate as ic, session_description::SdpParseError};
19
20#[derive(Clone)]
21pub struct IceCandidate {
22 pub(crate) sys_handle: SharedPtr<sys_jsep::ffi::IceCandidate>,
23}
24
25impl IceCandidate {
26 pub fn parse(
27 sdp_mid: &str,
28 sdp_mline_index: i32,
29 sdp: &str,
30 ) -> Result<ic::IceCandidate, SdpParseError> {
31 let res = sys_jsep::ffi::create_ice_candidate(
32 sdp_mid.to_string(),
33 sdp_mline_index,
34 sdp.to_string(),
35 );
36
37 match res {
38 Ok(sys_handle) => Ok(ic::IceCandidate { handle: IceCandidate { sys_handle } }),
39 Err(e) => Err(unsafe { sys_jsep::ffi::SdpParseError::from(e.what()).into() }),
40 }
41 }
42
43 pub fn sdp_mid(&self) -> String {
44 self.sys_handle.sdp_mid()
45 }
46
47 pub fn sdp_mline_index(&self) -> i32 {
48 self.sys_handle.sdp_mline_index()
49 }
50
51 pub fn candidate(&self) -> String {
52 self.sys_handle.candidate()
53 }
54}
55
56impl ToString for IceCandidate {
57 fn to_string(&self) -> String {
58 self.sys_handle.stringify()
59 }
60}