From be8910b8be01b884145caf904a84cdda05306545 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 9 Mar 2016 08:26:53 +0000 Subject: [PATCH] Add event handler for m.call.invite --- .gitignore | 1 + src/Makefile.am | 1 + src/matrix-event-call-invite.vala | 103 ++++++++++++++++++++++++++++++ src/matrix-event-types.c | 3 + src/matrix-types.vala | 5 ++ 5 files changed, 113 insertions(+) create mode 100644 src/matrix-event-call-invite.vala diff --git a/.gitignore b/.gitignore index f8036f2..6aefbc2 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ Makefile.in /src/matrix-event-room-guest-access.c /src/matrix-event-room-redaction.c /src/matrix-event-room-third-party-invite.c +/src/matrix-event-call-invite.c diff --git a/src/Makefile.am b/src/Makefile.am index 7df85f7..2ac2cbb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,6 +45,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-room-guest-access.vala \ matrix-event-room-redaction.vala \ matrix-event-room-third-party-invite.vala \ + matrix-event-call-invite.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-call-invite.vala b/src/matrix-event-call-invite.vala new file mode 100644 index 0000000..3d7fa3b --- /dev/null +++ b/src/matrix-event-call-invite.vala @@ -0,0 +1,103 @@ +/* + * 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 + * . + */ + +/** + * This event is sent by the caller when they wish to establish a + * call. + */ +public class Matrix.Event.CallInvite : Matrix.Event.Room { + /** + * A unique identifer for the call. + */ + public string? call_id { get; set; default = null;} + + /** + * The type of session description. + */ + public CallOfferType? offer_type { get; set; default = null; } + /** + * The SDP text of the session description. + */ + public string? sdp { get; set; default = null; } + + /** + * The version of the VoIP specification this message adheres to. + */ + public int? version { get; set; default = null; } + + /** + * The time in milliseconds that the invite is valid for. Once the + * invite age exceeds this value, clients should discard it. They + * should also no longer show the call as awaiting an answer in + * the UI. + */ + public int? lifetime { get; set; default = null; } + + 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("call_id")) != null) { _call_id = node.get_string(); + } else { + warning("content.call_id is missing from a m.call.invite event"); + } + + if ((node = content_root.get_member("offer")) != null) { + var offer_node = node.get_object(); + + if ((node = offer_node.get_member("type")) != null) { + CallOfferType? typ = (CallOfferType?)_g_enum_nick_to_value( + typeof(CallOfferType), node.get_string()); + + if (typ != null) { + _offer_type = typ; + } else { + _offer_type = CallOfferType.UNKNOWN; + warning("Unknown value %s in content.offer.type of a m.call.invite event", + node.get_string()); + } + } else { + warning("content.offer.type is missing from a m.call.invite event"); + } + + if ((node = offer_node.get_member("sdp")) != null) { + _sdp = node.get_string(); + } else { + warning("content.offer.sdp is missing from a m.call.invite event"); + } + } + + if ((node = content_root.get_member("version")) != null) { + _version = (int)node.get_int(); + } else { + warning("content.version is missing from a m.call.invite event"); + } + + if ((node = content_root.get_member("lifetime")) != null) { + _lifetime = (int)node.get_int(); + } else { + warning("content.lifetime is missing from a m.call.invite event"); + } + + base.from_json(json_data); + } +} diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index 7b31a8a..c2a9449 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -209,6 +209,9 @@ matrix_event_types_ctor(void) matrix_event_register_type("m.room.third_party_invite", MATRIX_EVENT_TYPE_ROOM_THIRD_PARTY_INVITE, NULL); + matrix_event_register_type("m.call.invite", + MATRIX_EVENT_TYPE_CALL_INVITE, + NULL); } void diff --git a/src/matrix-types.vala b/src/matrix-types.vala index d8f6e8c..6f19979 100644 --- a/src/matrix-types.vala +++ b/src/matrix-types.vala @@ -276,6 +276,11 @@ namespace Matrix { FORBIDDEN; /// guest users are not allowed to access the room } + public enum CallOfferType { + UNKNOWN, /// represents a value unknown to this library + OFFER; /// call offer + } + public struct ImageInfo { int? size; int? height;