Skip to content

Commit

Permalink
NgwNativeRTCDataChannel: turns to final class
Browse files Browse the repository at this point in the history
Since we no longer use vfuncs, we might as well make it a final class.
Not that it makes much sense practically, but why not?
  • Loading branch information
peat-psuwit committed Sep 23, 2023
1 parent 684f65e commit 57623b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
30 changes: 13 additions & 17 deletions src-native/NgwNativeRTCDataChannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

#include "NgwNativeRTCDataChannel.h"

typedef struct {
struct _NgwNativeRTCDataChannel {
GObject parent_object;

GstWebRTCDataChannel *gstdatachannel;
} NgwNativeRTCDataChannelPrivate;
};

G_DEFINE_TYPE_WITH_PRIVATE(
G_DEFINE_TYPE(
NgwNativeRTCDataChannel,
ngw_native_rtc_data_channel,
G_TYPE_OBJECT)
Expand Down Expand Up @@ -115,9 +117,7 @@ static void ngw_native_rtc_data_channel_class_init(
static void ngw_native_rtc_data_channel_init(
NgwNativeRTCDataChannel * self)
{
NgwNativeRTCDataChannelPrivate * priv = ngw_native_rtc_data_channel_get_instance_private(self);

priv->gstdatachannel = NULL;
self->gstdatachannel = NULL;
}

static void ngw_native_rtc_data_channel_set_property(
Expand All @@ -127,14 +127,13 @@ static void ngw_native_rtc_data_channel_set_property(
GParamSpec *pspec)
{
NgwNativeRTCDataChannel * self = NGW_NATIVE_RTC_DATA_CHANNEL(object);
NgwNativeRTCDataChannelPrivate * priv = ngw_native_rtc_data_channel_get_instance_private(self);

switch (property_id) {
case PROP_GSTDATACHANNEL:
if (priv->gstdatachannel) // ???
g_object_unref(priv->gstdatachannel);
if (self->gstdatachannel) // ???
g_object_unref(self->gstdatachannel);

priv->gstdatachannel = g_value_dup_object(value);
self->gstdatachannel = g_value_dup_object(value);
break;

default:
Expand All @@ -150,11 +149,10 @@ static void ngw_native_rtc_data_channel_get_property(
GParamSpec *pspec)
{
NgwNativeRTCDataChannel * self = NGW_NATIVE_RTC_DATA_CHANNEL(object);
NgwNativeRTCDataChannelPrivate * priv = ngw_native_rtc_data_channel_get_instance_private(self);

switch (property_id) {
case PROP_GSTDATACHANNEL:
g_value_set_object(value, priv->gstdatachannel);
g_value_set_object(value, self->gstdatachannel);
break;

default:
Expand Down Expand Up @@ -188,9 +186,8 @@ static void on_open_callback(
static void ngw_native_rtc_data_channel_constructed(GObject * object)
{
NgwNativeRTCDataChannel * self = NGW_NATIVE_RTC_DATA_CHANNEL(object);
NgwNativeRTCDataChannelPrivate * priv = ngw_native_rtc_data_channel_get_instance_private(self);

g_object_connect(priv->gstdatachannel,
g_object_connect(self->gstdatachannel,
"signal::on-buffered-amount-low", on_buffered_amount_low_callback, self,
"signal::on-close", on_close_callback, self,
"signal::on-error", on_error_callback, self,
Expand All @@ -205,10 +202,9 @@ static void ngw_native_rtc_data_channel_constructed(GObject * object)
static void ngw_native_rtc_data_channel_dispose(GObject * object)
{
NgwNativeRTCDataChannel * self = NGW_NATIVE_RTC_DATA_CHANNEL(object);
NgwNativeRTCDataChannelPrivate * priv = ngw_native_rtc_data_channel_get_instance_private(self);

g_signal_handlers_disconnect_by_data(priv->gstdatachannel, self);
g_clear_object(&priv->gstdatachannel);
g_signal_handlers_disconnect_by_data(self->gstdatachannel, self);
g_clear_object(&self->gstdatachannel);
}

static int ngw_native_rtc_data_channel_on_buffered_amount_low(gpointer user_data)
Expand Down
6 changes: 1 addition & 5 deletions src-native/NgwNativeRTCDataChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ G_BEGIN_DECLS
*/
#define NGW_NATIVE_RTC_DATA_CHANNEL_TYPE ngw_native_rtc_data_channel_get_type()

NGWNATIVE_PUBLIC G_DECLARE_DERIVABLE_TYPE(
NGWNATIVE_PUBLIC G_DECLARE_FINAL_TYPE(
NgwNativeRTCDataChannel,
ngw_native_rtc_data_channel,
NGW_NATIVE, RTC_DATA_CHANNEL, GObject)

struct _NgwNativeRTCDataChannelClass {
GObjectClass parent_class;
};

NGWNATIVE_PUBLIC
NgwNativeRTCDataChannel * ngw_native_rtc_data_channel_new(
GstWebRTCDataChannel * gstdatachannel
Expand Down
4 changes: 0 additions & 4 deletions src/@types/node-ngwnative-0.0.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ interface RTCDataChannel {
readonly gstDataChannel: GstWebRTC.WebRTCDataChannel
__gtype__: number

// Own fields of NgwNative-0.0.NgwNative.RTCDataChannel

parentInstance: GObject.Object

// Own signals of NgwNative-0.0.NgwNative.RTCDataChannel

connect(sigName: "on-buffered-amount-low", callback: RTCDataChannel.OnBufferedAmountLowSignalCallback): number
Expand Down

0 comments on commit 57623b5

Please sign in to comment.