| 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 | |
| 15 | use std::fmt::Debug; |
| 16 | |
| 17 | use crate::{imp::ice_candidate as imp_ic, session_description::SdpParseError}; |
| 18 | |
| 19 | pub struct IceCandidate { |
| 20 | pub(crate) handle: imp_ic::IceCandidate, |
| 21 | } |
| 22 | |
| 23 | impl IceCandidate { |
| 24 | pub fn parse( |
| 25 | sdp_mid: &str, |
| 26 | sdp_mline_index: i32, |
| 27 | sdp: &str, |
| 28 | ) -> Result<IceCandidate, SdpParseError> { |
| 29 | imp_ic::IceCandidate::parse(sdp_mid, sdp_mline_index, sdp) |
| 30 | } |
| 31 | |
| 32 | pub fn sdp_mid(&self) -> String { |
| 33 | self.handle.sdp_mid() |
| 34 | } |
| 35 | |
| 36 | pub fn sdp_mline_index(&self) -> i32 { |
| 37 | self.handle.sdp_mline_index() |
| 38 | } |
| 39 | |
| 40 | pub fn candidate(&self) -> String { |
| 41 | self.handle.candidate() |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl ToString for IceCandidate { |
| 46 | fn to_string(&self) -> String { |
| 47 | self.handle.to_string() |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | impl Debug for IceCandidate { |
| 52 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 53 | f.debug_struct("IceCandidate").field("candidate", &self.to_string()).finish() |
| 54 | } |
| 55 | } |