Port MatrixEventCallCandidates to C
This commit is contained in:
parent
d51ab6ec50
commit
664f3a0ff6
1
.gitignore
vendored
1
.gitignore
vendored
@ -53,5 +53,4 @@ Makefile.in
|
||||
/src/matrix-http-client.c
|
||||
/src/namespace-info.vala
|
||||
/src/namespace-info.c
|
||||
/src/matrix-event-call-candidates.c
|
||||
/src/matrix-glib-0.0.pc
|
||||
|
@ -21,7 +21,6 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
||||
matrix-client.vala \
|
||||
matrix-http-api.vala \
|
||||
matrix-http-client.vala \
|
||||
matrix-event-call-candidates.vala \
|
||||
$(NULL)
|
||||
|
||||
AM_CPPFLAGS += \
|
||||
@ -82,6 +81,7 @@ INST_H_SRC_FILES = \
|
||||
matrix-event-call-answer.h \
|
||||
matrix-event-call-hangup.h \
|
||||
matrix-event-call-invite.h \
|
||||
matrix-event-call-candidates.h \
|
||||
matrix-message-base.h \
|
||||
matrix-message-text.h \
|
||||
matrix-message-location.h \
|
||||
@ -140,6 +140,7 @@ libmatrix_glib_0_0_la_SOURCES = \
|
||||
matrix-event-call-answer.c \
|
||||
matrix-event-call-hangup.c \
|
||||
matrix-event-call-invite.c \
|
||||
matrix-event-call-candidates.c \
|
||||
matrix-message-base.c \
|
||||
matrix-message-text.c \
|
||||
matrix-message-location.c \
|
||||
|
491
src/matrix-event-call-candidates.c
Normal file
491
src/matrix-event-call-candidates.c
Normal file
@ -0,0 +1,491 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "matrix-event-call-candidates.h"
|
||||
#include "matrix-enumtypes.h"
|
||||
|
||||
/**
|
||||
* SECTION:matrix-event-call-candidates
|
||||
* @short_description: Event to represent call candidates
|
||||
*
|
||||
*/
|
||||
|
||||
struct _MatrixCallCandidate {
|
||||
gchar *sdp_mid; /// The SDP media type this candidate is intended for.
|
||||
int sdp_line_index; /// The index of the SDP 'm' line this candidate is intended for.
|
||||
gchar *candidate; /// The SDP 'a' line of the candidate.
|
||||
|
||||
guint refcount;
|
||||
};
|
||||
|
||||
/**
|
||||
* MatrixCallCandidate:
|
||||
*
|
||||
* An opaque data structure to represent a call candidate.
|
||||
*/
|
||||
G_DEFINE_BOXED_TYPE(MatrixCallCandidate, matrix_call_candidate, (GBoxedCopyFunc)matrix_call_candidate_unref, (GBoxedFreeFunc)matrix_call_candidate_unref);
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_new:
|
||||
*
|
||||
* Create a new #MatrixCallCandidate object with a reference count of 1.
|
||||
*
|
||||
* Returns: (transfer full): a new #MatrixCallCandidate object
|
||||
*/
|
||||
MatrixCallCandidate *
|
||||
matrix_call_candidate_new(void)
|
||||
{
|
||||
MatrixCallCandidate *ret;
|
||||
|
||||
ret = g_new0(MatrixCallCandidate, 1);
|
||||
ret->refcount = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_ref:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
*
|
||||
* Increment reference count on @candidate.
|
||||
*
|
||||
* Returns: (transfer full): the same object
|
||||
*/
|
||||
MatrixCallCandidate *
|
||||
matrix_call_candidate_ref(MatrixCallCandidate *matrix_call_candidate)
|
||||
{
|
||||
g_return_val_if_fail(matrix_call_candidate != NULL, NULL);
|
||||
|
||||
matrix_call_candidate->refcount++;
|
||||
|
||||
return matrix_call_candidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_unref:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
*
|
||||
* Decrement reference count on @candidate.
|
||||
*
|
||||
* If reference count reaches zero, @candidate gets freed.
|
||||
*/
|
||||
void
|
||||
matrix_call_candidate_unref(MatrixCallCandidate *matrix_call_candidate)
|
||||
{
|
||||
g_return_if_fail(matrix_call_candidate != NULL);
|
||||
|
||||
g_free(matrix_call_candidate->sdp_mid);
|
||||
g_free(matrix_call_candidate->candidate);
|
||||
g_free(matrix_call_candidate);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_get_sdp_mid:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
*
|
||||
* Get the SDP mid of @candidate.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the SDP mid
|
||||
*/
|
||||
const gchar *
|
||||
matrix_call_candidate_get_sdp_mid(MatrixCallCandidate *matrix_call_candidate)
|
||||
{
|
||||
g_return_val_if_fail(matrix_call_candidate != NULL, NULL);
|
||||
|
||||
return matrix_call_candidate->sdp_mid;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_set_sdp_mid:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
* @sdp_mid: an SDP mid
|
||||
*
|
||||
* Set the SDP mid for @candidate.
|
||||
*/
|
||||
void
|
||||
matrix_call_candidate_set_sdp_mid(MatrixCallCandidate *matrix_call_candidate, const gchar *sdp_mid)
|
||||
{
|
||||
g_return_if_fail(matrix_call_candidate);
|
||||
|
||||
g_free(matrix_call_candidate->sdp_mid);
|
||||
matrix_call_candidate->sdp_mid = g_strdup(sdp_mid);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_get_sdp_line_index:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
*
|
||||
* Get the SDP line of @candidate.
|
||||
*
|
||||
* The value returned is owned by @candidate and should not be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the SDP line
|
||||
*/
|
||||
int
|
||||
matrix_call_candidate_get_sdp_line_index(MatrixCallCandidate *matrix_call_candidate)
|
||||
{
|
||||
g_return_val_if_fail(matrix_call_candidate != NULL, 0);
|
||||
|
||||
return matrix_call_candidate->sdp_line_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_set_sdp_line_index:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
* @sdp_line_index: an SDP line index
|
||||
*
|
||||
* Set the SDP line index of @candidate.
|
||||
*/
|
||||
void
|
||||
matrix_call_candidate_set_sdp_line_index(MatrixCallCandidate *matrix_call_candidate, int sdp_line_index)
|
||||
{
|
||||
g_return_if_fail(matrix_call_candidate != NULL);
|
||||
|
||||
matrix_call_candidate->sdp_line_index = sdp_line_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_get_candidate:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
*
|
||||
* Get the call candidate from @candidate.
|
||||
*
|
||||
* The returned value is owned by @candidate and should not be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the candidate name
|
||||
*/
|
||||
const gchar *
|
||||
matrix_call_candidate_get_candidate(MatrixCallCandidate *matrix_call_candidate)
|
||||
{
|
||||
g_return_val_if_fail(matrix_call_candidate != NULL, NULL);
|
||||
|
||||
return matrix_call_candidate->candidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_call_candidate_set_candidate:
|
||||
* @candidate: a #MatrixCallCandidate
|
||||
* @candidate_name: (transfer none) (nullable): the name of the candidate
|
||||
*
|
||||
* Set the name of the call candidate.
|
||||
*/
|
||||
void
|
||||
matrix_call_candidate_set_candidate(MatrixCallCandidate *matrix_call_candidate, const gchar *candidate)
|
||||
{
|
||||
g_return_if_fail(matrix_call_candidate != NULL);
|
||||
|
||||
g_free(matrix_call_candidate->candidate);
|
||||
matrix_call_candidate->candidate = g_strdup(candidate);
|
||||
}
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CANDIDATES,
|
||||
NUM_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *matrix_event_call_candidates_properties[NUM_PROPS];
|
||||
|
||||
typedef struct {
|
||||
MatrixCallCandidate** _candidates;
|
||||
gint _candidates_len;
|
||||
} MatrixEventCallCandidatesPrivate;
|
||||
|
||||
/**
|
||||
* MatrixEventCallCandidates:
|
||||
*
|
||||
* This event is sent by callers after sending an invite and by the callee after answering.
|
||||
* Its purpose is to give the other party additional ICE candidates to try using to communicate.
|
||||
*/
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(MatrixEventCallCandidates, matrix_event_call_candidates, MATRIX_EVENT_TYPE_CALL);
|
||||
|
||||
static void
|
||||
matrix_event_call_candidates_real_from_json(MatrixEventBase *matrix_event_base, JsonNode *json_data, GError **error)
|
||||
{
|
||||
MatrixEventCallCandidatesPrivate *priv;
|
||||
JsonObject *root;
|
||||
JsonObject *content_root;
|
||||
JsonNode *content_node;
|
||||
JsonNode *node;
|
||||
|
||||
g_return_if_fail(json_data != NULL);
|
||||
|
||||
priv = matrix_event_call_candidates_get_instance_private(MATRIX_EVENT_CALL_CANDIDATES(matrix_event_base));
|
||||
root = json_node_get_object(json_data);
|
||||
content_node = json_object_get_member(root, "content");
|
||||
content_root = json_node_get_object(content_node);
|
||||
|
||||
if ((node = json_object_get_member(content_root, "candidates")) != NULL) {
|
||||
JsonArray *candidates = json_node_get_array(node);
|
||||
gint len = json_array_get_length(candidates);
|
||||
|
||||
priv->_candidates = g_new(MatrixCallCandidate *, len);
|
||||
|
||||
for (gint i = 0; i < len; i++) {
|
||||
JsonNode *cand_node = json_array_get_element(candidates, i);
|
||||
JsonObject *cand_root = json_node_get_object(cand_node);
|
||||
priv->_candidates[i] = matrix_call_candidate_new();
|
||||
|
||||
if ((node = json_object_get_member(cand_root, "sdpMid")) != NULL) {
|
||||
priv->_candidates[i]->sdp_mid = g_strdup(json_node_get_string(node));
|
||||
} else {
|
||||
g_warning("sdpMid is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
if ((node = json_object_get_member(cand_root, "sdpMLineIndex")) != NULL) {
|
||||
priv->_candidates[i]->sdp_line_index = json_node_get_int(node);
|
||||
} else {
|
||||
g_warning("sdpMLineIndex is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
if ((node = json_object_get_member(cand_root, "candidate")) != NULL) {
|
||||
priv->_candidates[i]->candidate = g_strdup(json_node_get_string(node));
|
||||
} else {
|
||||
g_warning("candidate is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
};
|
||||
} else {
|
||||
g_warning("content.candidates is missing from a m.call.candidates event");
|
||||
}
|
||||
|
||||
MATRIX_EVENT_BASE_CLASS(matrix_event_call_candidates_parent_class)->from_json(matrix_event_base, json_data, error);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_call_candidates_real_to_json(MatrixEventBase *matrix_event_base, JsonNode *json_data, GError **error)
|
||||
{
|
||||
MatrixEventCallCandidatesPrivate *priv;
|
||||
JsonObject *root;
|
||||
JsonObject *content_root;
|
||||
JsonArray *cands;
|
||||
JsonNode *content_node;
|
||||
JsonNode *cands_node;
|
||||
|
||||
g_return_if_fail(json_data != NULL);
|
||||
|
||||
priv = matrix_event_call_candidates_get_instance_private(MATRIX_EVENT_CALL_CANDIDATES(matrix_event_base));
|
||||
root = json_node_get_object(json_data);
|
||||
content_node = json_object_get_member(root, "content");
|
||||
content_root = json_node_get_object(content_node);
|
||||
|
||||
if (priv->_candidates_len < 1) {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE,
|
||||
"Won't generate a m.call.candidates event without candidates");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cands = json_array_new();
|
||||
cands_node = json_node_new(JSON_NODE_ARRAY);
|
||||
json_node_set_array(cands_node, cands);
|
||||
json_object_set_member(content_root, "candidates", cands_node);
|
||||
|
||||
for (gint i = 0; i < priv->_candidates_len; i++) {
|
||||
MatrixCallCandidate *entry = priv->_candidates[i];
|
||||
JsonObject *cand_root;
|
||||
JsonNode *cand_node;
|
||||
|
||||
if (entry->sdp_mid == NULL) {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE,
|
||||
"Won't generate a m.call.candidates event with a missing sdpMid for candidates");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry->candidate == NULL) {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE,
|
||||
"Won't generate a m.call.candidates event with a missing candidate for candidates");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cand_root = json_object_new();
|
||||
cand_node = json_node_new(JSON_NODE_OBJECT);
|
||||
json_node_set_object(cand_node, cand_root);
|
||||
|
||||
json_object_set_string_member(cand_root, "sdpMid", entry->sdp_mid);
|
||||
json_object_set_int_member(cand_root, "sdpMLineIndex", entry->sdp_line_index);
|
||||
json_object_set_string_member(cand_root, "candidate", entry->candidate);
|
||||
|
||||
json_array_add_element(cands, cand_node);
|
||||
}
|
||||
|
||||
if (json_array_get_length(cands) < 1) {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE,
|
||||
"Won't generate a m.call.candidates event with empty candidates list");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MATRIX_EVENT_BASE_CLASS(matrix_event_call_candidates_parent_class)->to_json(matrix_event_base, json_data, error);
|
||||
}
|
||||
|
||||
MatrixEventCallCandidates *
|
||||
matrix_event_call_candidates_construct(GType object_type)
|
||||
{
|
||||
return (MatrixEventCallCandidates *)matrix_event_call_construct(object_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_call_candidates_new:
|
||||
*
|
||||
* Create a new #MatrixEventCallCandidates object.
|
||||
*
|
||||
* Returns: (transfer full): a new #MatrixEventCallCandidates object
|
||||
*/
|
||||
MatrixEventCallCandidates *
|
||||
matrix_event_call_candidates_new(void)
|
||||
{
|
||||
return matrix_event_call_candidates_construct(MATRIX_EVENT_TYPE_CALL_CANDIDATES);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_call_candidates_get_candidates:
|
||||
* @event: a #MatrixEventCallCandidates:
|
||||
* @n_candidates: (nullable): placeholder for the length of the list, or %NULL to ignore
|
||||
*
|
||||
* Get the list of the candidates from @event.
|
||||
*
|
||||
* The returned value is owned by @event, and should not be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the list of candidates
|
||||
*/
|
||||
MatrixCallCandidate **
|
||||
matrix_event_call_candidates_get_candidates(MatrixEventCallCandidates *matrix_event_call_candidates, int *n_candidates)
|
||||
{
|
||||
MatrixEventCallCandidatesPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(matrix_event_call_candidates != NULL, NULL);
|
||||
|
||||
priv = matrix_event_call_candidates_get_instance_private(matrix_event_call_candidates);
|
||||
|
||||
if (n_candidates != NULL) {
|
||||
*n_candidates = priv->_candidates_len;
|
||||
}
|
||||
|
||||
return priv->_candidates;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_call_candidates_set_candidates:
|
||||
* @event: a #MatrixEventCallCandidates
|
||||
* @candidates: a list of #MatrixCallCandidate objects
|
||||
* @n_candidates: the number of elements in @candidates
|
||||
*
|
||||
* Set the list of call candidates in @event.
|
||||
*/
|
||||
void
|
||||
matrix_event_call_candidates_set_candidates(MatrixEventCallCandidates *matrix_event_call_candidates, MatrixCallCandidate **candidates, int n_candidates)
|
||||
{
|
||||
MatrixEventCallCandidatesPrivate *priv;
|
||||
|
||||
g_return_if_fail(matrix_event_call_candidates != NULL);
|
||||
|
||||
priv = matrix_event_call_candidates_get_instance_private(matrix_event_call_candidates);
|
||||
|
||||
for (gint i = 0; i < priv->_candidates_len; i++) {
|
||||
matrix_call_candidate_unref(priv->_candidates[i]);
|
||||
}
|
||||
|
||||
g_free(priv->_candidates);
|
||||
|
||||
priv->_candidates = (MatrixCallCandidate **)g_new(MatrixCallCandidate, n_candidates);
|
||||
priv->_candidates_len = n_candidates;
|
||||
|
||||
for (gint i = 0; i < n_candidates; i++) {
|
||||
priv->_candidates[i] = matrix_call_candidate_ref(candidates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_call_candidates_finalize(GObject *gobject)
|
||||
{
|
||||
MatrixEventCallCandidatesPrivate *priv = matrix_event_call_candidates_get_instance_private(MATRIX_EVENT_CALL_CANDIDATES(gobject));
|
||||
|
||||
for (gint i = 0; i < priv->_candidates_len; i++) {
|
||||
matrix_call_candidate_unref(priv->_candidates[i]);
|
||||
}
|
||||
|
||||
g_free(priv->_candidates);
|
||||
|
||||
G_OBJECT_CLASS(matrix_event_call_candidates_parent_class)->finalize(gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_call_candidates_get_property(GObject *gobject, guint property_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
MatrixEventCallCandidates *matrix_event_call_candidates = MATRIX_EVENT_CALL_CANDIDATES(gobject);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CANDIDATES:
|
||||
g_value_set_boxed(value, matrix_event_call_candidates_get_candidates(matrix_event_call_candidates, NULL));
|
||||
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_call_candidates_set_property(GObject *gobject, guint property_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
MatrixEventCallCandidates *matrix_event_call_candidates = MATRIX_EVENT_CALL_CANDIDATES(gobject);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CANDIDATES:
|
||||
{
|
||||
gpointer boxed = g_value_get_boxed(value);
|
||||
|
||||
matrix_event_call_candidates_set_candidates(matrix_event_call_candidates, g_value_get_boxed(value), (boxed == NULL) ? 0 : g_strv_length(boxed));
|
||||
}
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_call_candidates_class_init(MatrixEventCallCandidatesClass *klass)
|
||||
{
|
||||
((MatrixEventBaseClass *)klass)->from_json = matrix_event_call_candidates_real_from_json;
|
||||
((MatrixEventBaseClass *)klass)->to_json = matrix_event_call_candidates_real_to_json;
|
||||
G_OBJECT_CLASS(klass)->get_property = matrix_event_call_candidates_get_property;
|
||||
G_OBJECT_CLASS(klass)->set_property = matrix_event_call_candidates_set_property;
|
||||
G_OBJECT_CLASS(klass)->finalize = matrix_event_call_candidates_finalize;
|
||||
|
||||
/**
|
||||
* MatrixEventCallCandidates:candidates:
|
||||
*
|
||||
* The list of call candidates.
|
||||
*/
|
||||
matrix_event_call_candidates_properties[PROP_CANDIDATES] = g_param_spec_boxed(
|
||||
"candidates", "candidates", "candidates",
|
||||
MATRIX_TYPE_CALL_CANDIDATE,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_CANDIDATES, matrix_event_call_candidates_properties[PROP_CANDIDATES]);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_call_candidates_init(MatrixEventCallCandidates *matrix_event_call_candidates)
|
||||
{
|
||||
MatrixEventCallCandidatesPrivate *priv = matrix_event_call_candidates_get_instance_private(matrix_event_call_candidates);
|
||||
|
||||
priv->_candidates = NULL;
|
||||
}
|
56
src/matrix-event-call-candidates.h
Normal file
56
src/matrix-event-call-candidates.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_GLIB_SDK_EVENT_CALL_CANDIDATES_H__
|
||||
# define __MATRIX_GLIB_SDK_EVENT_CALL_CANDIDATES_H__
|
||||
|
||||
# include <glib-object.h>
|
||||
# include "matrix-event-call-base.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
# define MATRIX_TYPE_CALL_CANDIDATE matrix_call_candidate_get_type()
|
||||
typedef struct _MatrixCallCandidate MatrixCallCandidate;
|
||||
|
||||
GType matrix_call_candidate_get_type(void) G_GNUC_CONST;
|
||||
MatrixCallCandidate *matrix_call_candidate_new(void);
|
||||
MatrixCallCandidate *matrix_call_candidate_ref(MatrixCallCandidate *candidate);
|
||||
void matrix_call_candidate_unref(MatrixCallCandidate *candidate);
|
||||
const gchar *matrix_call_candidate_get_sdp_mid(MatrixCallCandidate *candidate);
|
||||
void matrix_call_candidate_set_sdp_mid(MatrixCallCandidate *candidate, const gchar *sdp_mid);
|
||||
int matrix_call_candidate_get_sdp_line_index(MatrixCallCandidate *candidate);
|
||||
void matrix_call_candidate_set_sdp_line_index(MatrixCallCandidate *candidate, int sdp_line_index);
|
||||
const gchar *matrix_call_candidate_get_candidate(MatrixCallCandidate *candidate);
|
||||
void matrix_call_candidate_set_candidate(MatrixCallCandidate *candidate, const gchar *candidate_name);
|
||||
|
||||
#define MATRIX_EVENT_TYPE_CALL_CANDIDATES (matrix_event_call_candidates_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixEventCallCandidates, matrix_event_call_candidates, MATRIX_EVENT, CALL_CANDIDATES, MatrixEventCall);
|
||||
|
||||
struct _MatrixEventCallCandidatesClass {
|
||||
MatrixEventCallClass parent_class;
|
||||
};
|
||||
|
||||
MatrixEventCallCandidates* matrix_event_call_candidates_new (void);
|
||||
MatrixEventCallCandidates* matrix_event_call_candidates_construct (GType object_type);
|
||||
MatrixCallCandidate* matrix_event_call_candidates_candidate_dup (const MatrixCallCandidate *event);
|
||||
MatrixCallCandidate** matrix_event_call_candidates_get_candidates (MatrixEventCallCandidates *event, int *n_candidates);
|
||||
void matrix_event_call_candidates_set_candidates (MatrixEventCallCandidates *event, MatrixCallCandidate **candidates, int n_candidates);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MATRIX_GLIB_SDK_EVENT_CALL_CANDIDATES_H__ */
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This event is sent by callers after sending an invite and by the
|
||||
* callee after answering. Its purpose is to give the other party
|
||||
* additional ICE candidates to try using to communicate.
|
||||
*/
|
||||
public class Matrix.Event.CallCandidates : Matrix.Event.Call {
|
||||
public struct Candidate {
|
||||
string? sdp_mid; /// The SDP media type this candidate is
|
||||
/// intended for.
|
||||
int? sdp_line_index; /// The index of the SDP 'm' line this
|
||||
/// candidate is intended for.
|
||||
string? candidate; /// The SDP 'a' line of the candidate.
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of candidates.
|
||||
*/
|
||||
public Candidate[] candidates { get; set; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("candidates")) != null) {
|
||||
_candidates = new Candidate[node.get_array().get_length()];
|
||||
|
||||
node.get_array().foreach_element((ary, idx, cand_node) => {
|
||||
var cand_root = cand_node.get_object();
|
||||
var cand = Candidate();
|
||||
|
||||
if ((node = cand_root.get_member("sdpMid")) != null) {
|
||||
cand.sdp_mid = node.get_string();
|
||||
} else {
|
||||
warning("sdpMid is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
if ((node = cand_root.get_member("sdpMLineIndex")) != null) {
|
||||
cand.sdp_line_index = (int)node.get_int();
|
||||
} else {
|
||||
warning("sdpMLineIndex is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
if ((node = cand_root.get_member("candidate")) != null) {
|
||||
cand.candidate = node.get_string();
|
||||
} else {
|
||||
warning("candidate is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
_candidates[idx] = cand;
|
||||
});
|
||||
} else {
|
||||
warning("content.candidates is missing from a m.call.candidates event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_candidates.length < 1) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event without candidates");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
var cands = new Json.Array();
|
||||
|
||||
foreach (var entry in _candidates) {
|
||||
if (entry.sdp_mid == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with a missing sdpMid for candidates");
|
||||
}
|
||||
|
||||
if (entry.sdp_line_index == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with a missing sdpMLineIndex for candidates");
|
||||
}
|
||||
|
||||
if (entry.candidate == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with a missing candidate for candidates");
|
||||
}
|
||||
|
||||
var cand_obj = new Json.Object();
|
||||
var cand_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
cand_node.set_object(cand_obj);
|
||||
|
||||
cand_obj.set_string_member("sdpMid", entry.sdp_mid);
|
||||
cand_obj.set_int_member("sdpMLineIndex", entry.sdp_line_index);
|
||||
cand_obj.set_string_member("candidate", entry.candidate);
|
||||
|
||||
cands.add_element(cand_node);
|
||||
}
|
||||
|
||||
if (cands.get_length() < 1) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with empty candidates list");
|
||||
}
|
||||
|
||||
var cands_node = new Json.Node(Json.NodeType.ARRAY);
|
||||
cands_node.set_array(cands);
|
||||
content_root.set_member("candidates", cands_node);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
@ -40,6 +40,7 @@
|
||||
#include "matrix-event-call-answer.h"
|
||||
#include "matrix-event-call-hangup.h"
|
||||
#include "matrix-event-call-invite.h"
|
||||
#include "matrix-event-call-candidates.h"
|
||||
|
||||
#include "matrix-message-text.h"
|
||||
#include "matrix-message-location.h"
|
||||
|
@ -287,6 +287,9 @@ namespace Matrix {
|
||||
public struct ThirdPartyInvitePublicKey {
|
||||
}
|
||||
|
||||
public struct CallCandidate {
|
||||
}
|
||||
|
||||
/* Compact classes */
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public abstract class JsonCompact {
|
||||
@ -879,6 +882,17 @@ namespace Matrix {
|
||||
protected override void to_json(Json.Node json_data)
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-event-call-candidates.h")]
|
||||
public class CallCandidates : Call {
|
||||
public Matrix.CallCandidate[] candidates { get; set; }
|
||||
|
||||
protected override void from_json(Json.Node json_data)
|
||||
throws Matrix.Error;
|
||||
|
||||
protected override void to_json(Json.Node json_data)
|
||||
throws Matrix.Error;
|
||||
}
|
||||
}
|
||||
|
||||
[CCode (gir_namespace = "MatrixMessage", gir_version = "0.0")]
|
||||
|
Loading…
Reference in New Issue
Block a user