gstreamer_webrtc/auto/
web_rtc_data_channel.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5#![allow(deprecated)]
6
7use crate::{ffi, WebRTCDataChannelState, WebRTCPriorityType};
8use glib::{
9    object::ObjectType as _,
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17    ///
18    ///
19    /// This is an Abstract Base Class, you cannot instantiate it.
20    ///
21    /// ## Properties
22    ///
23    ///
24    /// #### `buffered-amount`
25    ///  Readable
26    ///
27    ///
28    /// #### `buffered-amount-low-threshold`
29    ///  Readable | Writeable
30    ///
31    ///
32    /// #### `id`
33    ///  Readable | Writeable | Construct Only
34    ///
35    ///
36    /// #### `label`
37    ///  Readable | Writeable | Construct Only
38    ///
39    ///
40    /// #### `max-packet-lifetime`
41    ///  Readable | Writeable | Construct Only
42    ///
43    ///
44    /// #### `max-retransmits`
45    ///  Readable | Writeable | Construct Only
46    ///
47    ///
48    /// #### `negotiated`
49    ///  Readable | Writeable | Construct Only
50    ///
51    ///
52    /// #### `ordered`
53    ///  Readable | Writeable | Construct Only
54    ///
55    ///
56    /// #### `priority`
57    ///  Readable | Writeable | Construct Only
58    ///
59    ///
60    /// #### `protocol`
61    ///  Readable | Writeable | Construct Only
62    ///
63    ///
64    /// #### `ready-state`
65    ///  Readable
66    ///
67    /// ## Signals
68    ///
69    ///
70    /// #### `close`
71    ///  Close the data channel
72    ///
73    /// Action
74    ///
75    ///
76    /// #### `on-buffered-amount-low`
77    ///
78    ///
79    ///
80    /// #### `on-close`
81    ///
82    ///
83    ///
84    /// #### `on-error`
85    ///
86    ///
87    ///
88    /// #### `on-message-data`
89    ///
90    ///
91    ///
92    /// #### `on-message-string`
93    ///
94    ///
95    ///
96    /// #### `on-open`
97    ///
98    ///
99    ///
100    /// #### `send-data`
101    ///  Action
102    ///
103    ///
104    /// #### `send-string`
105    ///  Action
106    ///
107    /// # Implements
108    ///
109    /// [`trait@glib::ObjectExt`]
110    #[doc(alias = "GstWebRTCDataChannel")]
111    pub struct WebRTCDataChannel(Object<ffi::GstWebRTCDataChannel, ffi::GstWebRTCDataChannelClass>);
112
113    match fn {
114        type_ => || ffi::gst_webrtc_data_channel_get_type(),
115    }
116}
117
118impl WebRTCDataChannel {
119    /// Close the `self`.
120    #[doc(alias = "gst_webrtc_data_channel_close")]
121    pub fn close(&self) {
122        unsafe {
123            ffi::gst_webrtc_data_channel_close(self.to_glib_none().0);
124        }
125    }
126
127    /// Send `data` as a data message over `self`.
128    ///
129    /// # Deprecated since 1.22
130    ///
131    /// Use [`send_data_full()`][Self::send_data_full()] instead
132    /// ## `data`
133    /// a [`glib::Bytes`][crate::glib::Bytes] or [`None`]
134    #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
135    #[allow(deprecated)]
136    #[doc(alias = "gst_webrtc_data_channel_send_data")]
137    pub fn send_data(&self, data: Option<&glib::Bytes>) {
138        unsafe {
139            ffi::gst_webrtc_data_channel_send_data(self.to_glib_none().0, data.to_glib_none().0);
140        }
141    }
142
143    /// Send `data` as a data message over `self`.
144    /// ## `data`
145    /// a [`glib::Bytes`][crate::glib::Bytes] or [`None`]
146    ///
147    /// # Returns
148    ///
149    /// TRUE if `self` is open and data could be queued
150    #[cfg(feature = "v1_22")]
151    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
152    #[doc(alias = "gst_webrtc_data_channel_send_data_full")]
153    pub fn send_data_full(&self, data: Option<&glib::Bytes>) -> Result<(), glib::Error> {
154        unsafe {
155            let mut error = std::ptr::null_mut();
156            let is_ok = ffi::gst_webrtc_data_channel_send_data_full(
157                self.to_glib_none().0,
158                data.to_glib_none().0,
159                &mut error,
160            );
161            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
162            if error.is_null() {
163                Ok(())
164            } else {
165                Err(from_glib_full(error))
166            }
167        }
168    }
169
170    /// Send `str` as a string message over `self`.
171    ///
172    /// # Deprecated since 1.22
173    ///
174    /// Use [`send_string_full()`][Self::send_string_full()] instead
175    /// ## `str`
176    /// a string or [`None`]
177    #[cfg_attr(feature = "v1_22", deprecated = "Since 1.22")]
178    #[allow(deprecated)]
179    #[doc(alias = "gst_webrtc_data_channel_send_string")]
180    pub fn send_string(&self, str: Option<&str>) {
181        unsafe {
182            ffi::gst_webrtc_data_channel_send_string(self.to_glib_none().0, str.to_glib_none().0);
183        }
184    }
185
186    /// Send `str` as a string message over `self`.
187    /// ## `str`
188    /// a string or [`None`]
189    ///
190    /// # Returns
191    ///
192    /// TRUE if `self` is open and data could be queued
193    #[cfg(feature = "v1_22")]
194    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
195    #[doc(alias = "gst_webrtc_data_channel_send_string_full")]
196    pub fn send_string_full(&self, str: Option<&str>) -> Result<(), glib::Error> {
197        unsafe {
198            let mut error = std::ptr::null_mut();
199            let is_ok = ffi::gst_webrtc_data_channel_send_string_full(
200                self.to_glib_none().0,
201                str.to_glib_none().0,
202                &mut error,
203            );
204            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
205            if error.is_null() {
206                Ok(())
207            } else {
208                Err(from_glib_full(error))
209            }
210        }
211    }
212
213    #[doc(alias = "buffered-amount")]
214    pub fn buffered_amount(&self) -> u64 {
215        ObjectExt::property(self, "buffered-amount")
216    }
217
218    #[doc(alias = "buffered-amount-low-threshold")]
219    pub fn buffered_amount_low_threshold(&self) -> u64 {
220        ObjectExt::property(self, "buffered-amount-low-threshold")
221    }
222
223    #[doc(alias = "buffered-amount-low-threshold")]
224    pub fn set_buffered_amount_low_threshold(&self, buffered_amount_low_threshold: u64) {
225        ObjectExt::set_property(
226            self,
227            "buffered-amount-low-threshold",
228            buffered_amount_low_threshold,
229        )
230    }
231
232    pub fn id(&self) -> i32 {
233        ObjectExt::property(self, "id")
234    }
235
236    pub fn label(&self) -> Option<glib::GString> {
237        ObjectExt::property(self, "label")
238    }
239
240    #[doc(alias = "max-packet-lifetime")]
241    pub fn max_packet_lifetime(&self) -> i32 {
242        ObjectExt::property(self, "max-packet-lifetime")
243    }
244
245    #[doc(alias = "max-retransmits")]
246    pub fn max_retransmits(&self) -> i32 {
247        ObjectExt::property(self, "max-retransmits")
248    }
249
250    pub fn is_negotiated(&self) -> bool {
251        ObjectExt::property(self, "negotiated")
252    }
253
254    pub fn is_ordered(&self) -> bool {
255        ObjectExt::property(self, "ordered")
256    }
257
258    pub fn priority(&self) -> WebRTCPriorityType {
259        ObjectExt::property(self, "priority")
260    }
261
262    pub fn protocol(&self) -> Option<glib::GString> {
263        ObjectExt::property(self, "protocol")
264    }
265
266    #[doc(alias = "ready-state")]
267    pub fn ready_state(&self) -> WebRTCDataChannelState {
268        ObjectExt::property(self, "ready-state")
269    }
270
271    #[doc(alias = "on-buffered-amount-low")]
272    pub fn connect_on_buffered_amount_low<F: Fn(&Self) + Send + Sync + 'static>(
273        &self,
274        f: F,
275    ) -> SignalHandlerId {
276        unsafe extern "C" fn on_buffered_amount_low_trampoline<
277            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
278        >(
279            this: *mut ffi::GstWebRTCDataChannel,
280            f: glib::ffi::gpointer,
281        ) {
282            let f: &F = &*(f as *const F);
283            f(&from_glib_borrow(this))
284        }
285        unsafe {
286            let f: Box_<F> = Box_::new(f);
287            connect_raw(
288                self.as_ptr() as *mut _,
289                c"on-buffered-amount-low".as_ptr() as *const _,
290                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291                    on_buffered_amount_low_trampoline::<F> as *const (),
292                )),
293                Box_::into_raw(f),
294            )
295        }
296    }
297
298    #[doc(alias = "on-close")]
299    pub fn connect_on_close<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
300        unsafe extern "C" fn on_close_trampoline<
301            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
302        >(
303            this: *mut ffi::GstWebRTCDataChannel,
304            f: glib::ffi::gpointer,
305        ) {
306            let f: &F = &*(f as *const F);
307            f(&from_glib_borrow(this))
308        }
309        unsafe {
310            let f: Box_<F> = Box_::new(f);
311            connect_raw(
312                self.as_ptr() as *mut _,
313                c"on-close".as_ptr() as *const _,
314                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
315                    on_close_trampoline::<F> as *const (),
316                )),
317                Box_::into_raw(f),
318            )
319        }
320    }
321
322    /// ## `error`
323    /// the [`glib::Error`][crate::glib::Error] thrown
324    #[doc(alias = "on-error")]
325    pub fn connect_on_error<F: Fn(&Self, &glib::Error) + Send + Sync + 'static>(
326        &self,
327        f: F,
328    ) -> SignalHandlerId {
329        unsafe extern "C" fn on_error_trampoline<
330            F: Fn(&WebRTCDataChannel, &glib::Error) + Send + Sync + 'static,
331        >(
332            this: *mut ffi::GstWebRTCDataChannel,
333            error: *mut glib::ffi::GError,
334            f: glib::ffi::gpointer,
335        ) {
336            let f: &F = &*(f as *const F);
337            f(&from_glib_borrow(this), &from_glib_borrow(error))
338        }
339        unsafe {
340            let f: Box_<F> = Box_::new(f);
341            connect_raw(
342                self.as_ptr() as *mut _,
343                c"on-error".as_ptr() as *const _,
344                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
345                    on_error_trampoline::<F> as *const (),
346                )),
347                Box_::into_raw(f),
348            )
349        }
350    }
351
352    /// ## `data`
353    /// a [`glib::Bytes`][crate::glib::Bytes] of the data received
354    #[doc(alias = "on-message-data")]
355    pub fn connect_on_message_data<F: Fn(&Self, Option<&glib::Bytes>) + Send + Sync + 'static>(
356        &self,
357        f: F,
358    ) -> SignalHandlerId {
359        unsafe extern "C" fn on_message_data_trampoline<
360            F: Fn(&WebRTCDataChannel, Option<&glib::Bytes>) + Send + Sync + 'static,
361        >(
362            this: *mut ffi::GstWebRTCDataChannel,
363            data: *mut glib::ffi::GBytes,
364            f: glib::ffi::gpointer,
365        ) {
366            let f: &F = &*(f as *const F);
367            f(
368                &from_glib_borrow(this),
369                Option::<glib::Bytes>::from_glib_borrow(data)
370                    .as_ref()
371                    .as_ref(),
372            )
373        }
374        unsafe {
375            let f: Box_<F> = Box_::new(f);
376            connect_raw(
377                self.as_ptr() as *mut _,
378                c"on-message-data".as_ptr() as *const _,
379                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
380                    on_message_data_trampoline::<F> as *const (),
381                )),
382                Box_::into_raw(f),
383            )
384        }
385    }
386
387    /// ## `data`
388    /// the data received as a string
389    #[doc(alias = "on-message-string")]
390    pub fn connect_on_message_string<F: Fn(&Self, Option<&str>) + Send + Sync + 'static>(
391        &self,
392        f: F,
393    ) -> SignalHandlerId {
394        unsafe extern "C" fn on_message_string_trampoline<
395            F: Fn(&WebRTCDataChannel, Option<&str>) + Send + Sync + 'static,
396        >(
397            this: *mut ffi::GstWebRTCDataChannel,
398            data: *mut std::ffi::c_char,
399            f: glib::ffi::gpointer,
400        ) {
401            let f: &F = &*(f as *const F);
402            f(
403                &from_glib_borrow(this),
404                Option::<glib::GString>::from_glib_borrow(data)
405                    .as_ref()
406                    .as_ref()
407                    .map(|s| s.as_str()),
408            )
409        }
410        unsafe {
411            let f: Box_<F> = Box_::new(f);
412            connect_raw(
413                self.as_ptr() as *mut _,
414                c"on-message-string".as_ptr() as *const _,
415                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
416                    on_message_string_trampoline::<F> as *const (),
417                )),
418                Box_::into_raw(f),
419            )
420        }
421    }
422
423    #[doc(alias = "on-open")]
424    pub fn connect_on_open<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
425        unsafe extern "C" fn on_open_trampoline<
426            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
427        >(
428            this: *mut ffi::GstWebRTCDataChannel,
429            f: glib::ffi::gpointer,
430        ) {
431            let f: &F = &*(f as *const F);
432            f(&from_glib_borrow(this))
433        }
434        unsafe {
435            let f: Box_<F> = Box_::new(f);
436            connect_raw(
437                self.as_ptr() as *mut _,
438                c"on-open".as_ptr() as *const _,
439                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
440                    on_open_trampoline::<F> as *const (),
441                )),
442                Box_::into_raw(f),
443            )
444        }
445    }
446
447    #[doc(alias = "buffered-amount")]
448    pub fn connect_buffered_amount_notify<F: Fn(&Self) + Send + Sync + 'static>(
449        &self,
450        f: F,
451    ) -> SignalHandlerId {
452        unsafe extern "C" fn notify_buffered_amount_trampoline<
453            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
454        >(
455            this: *mut ffi::GstWebRTCDataChannel,
456            _param_spec: glib::ffi::gpointer,
457            f: glib::ffi::gpointer,
458        ) {
459            let f: &F = &*(f as *const F);
460            f(&from_glib_borrow(this))
461        }
462        unsafe {
463            let f: Box_<F> = Box_::new(f);
464            connect_raw(
465                self.as_ptr() as *mut _,
466                c"notify::buffered-amount".as_ptr() as *const _,
467                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
468                    notify_buffered_amount_trampoline::<F> as *const (),
469                )),
470                Box_::into_raw(f),
471            )
472        }
473    }
474
475    #[doc(alias = "buffered-amount-low-threshold")]
476    pub fn connect_buffered_amount_low_threshold_notify<F: Fn(&Self) + Send + Sync + 'static>(
477        &self,
478        f: F,
479    ) -> SignalHandlerId {
480        unsafe extern "C" fn notify_buffered_amount_low_threshold_trampoline<
481            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
482        >(
483            this: *mut ffi::GstWebRTCDataChannel,
484            _param_spec: glib::ffi::gpointer,
485            f: glib::ffi::gpointer,
486        ) {
487            let f: &F = &*(f as *const F);
488            f(&from_glib_borrow(this))
489        }
490        unsafe {
491            let f: Box_<F> = Box_::new(f);
492            connect_raw(
493                self.as_ptr() as *mut _,
494                c"notify::buffered-amount-low-threshold".as_ptr() as *const _,
495                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
496                    notify_buffered_amount_low_threshold_trampoline::<F> as *const (),
497                )),
498                Box_::into_raw(f),
499            )
500        }
501    }
502
503    #[doc(alias = "ready-state")]
504    pub fn connect_ready_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
505        &self,
506        f: F,
507    ) -> SignalHandlerId {
508        unsafe extern "C" fn notify_ready_state_trampoline<
509            F: Fn(&WebRTCDataChannel) + Send + Sync + 'static,
510        >(
511            this: *mut ffi::GstWebRTCDataChannel,
512            _param_spec: glib::ffi::gpointer,
513            f: glib::ffi::gpointer,
514        ) {
515            let f: &F = &*(f as *const F);
516            f(&from_glib_borrow(this))
517        }
518        unsafe {
519            let f: Box_<F> = Box_::new(f);
520            connect_raw(
521                self.as_ptr() as *mut _,
522                c"notify::ready-state".as_ptr() as *const _,
523                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
524                    notify_ready_state_trampoline::<F> as *const (),
525                )),
526                Box_::into_raw(f),
527            )
528        }
529    }
530}
531
532unsafe impl Send for WebRTCDataChannel {}
533unsafe impl Sync for WebRTCDataChannel {}