From b6b5bbf5671c5ba7db6925c167f0b998685fdbbc Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 9 Mar 2016 10:31:26 +0100 Subject: [PATCH] Add event handler for m.call.answer --- .gitignore | 1 + src/Makefile.am | 1 + src/matrix-event-call-answer.vala | 134 ++++++++++++++++++++++++++ src/matrix-event-call-candidates.vala | 3 + src/matrix-event-types.c | 3 + src/matrix-types.vala | 5 + 6 files changed, 147 insertions(+) create mode 100644 src/matrix-event-call-answer.vala diff --git a/.gitignore b/.gitignore index b1144f2..e77a46f 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,4 @@ Makefile.in /src/matrix-event-room-third-party-invite.c /src/matrix-event-call-invite.c /src/matrix-event-call-candidates.c +/src/matrix-event-call-answer.c diff --git a/src/Makefile.am b/src/Makefile.am index 59908b8..d6b22c0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-room-third-party-invite.vala \ matrix-event-call-invite.vala \ matrix-event-call-candidates.vala \ + matrix-event-call-answer.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-call-answer.vala b/src/matrix-event-call-answer.vala new file mode 100644 index 0000000..93289ac --- /dev/null +++ b/src/matrix-event-call-answer.vala @@ -0,0 +1,134 @@ +/* + * 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 callee when they wish to answer the call. + */ +public class Matrix.Event.CallAnswer : Matrix.Event.Room { + /** + * The ID of the call this event relates to. + */ + public string? call_id { get; set; default = null; } + + /** + * The type of session description. + */ + public CallAnswerType? answer_type { get; set; default = null; } + + /** + * The SDP text of the session description. + */ + public string? answer_sdp { get; set; default = null; } + + /** + * The version of the VoIP specification this messages adheres to. + */ + public int? version { 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.answer event"); + } + + if ((node = content_root.get_member("answer")) != null) { + var answer_root = node.get_object(); + + if ((node = answer_root.get_member("type")) != null) { + CallAnswerType? typ = (CallAnswerType?)_g_enum_nick_to_value( + typeof(CallAnswerType), node.get_string()); + + if (typ != null) { + _answer_type = typ; + } else { + _answer_type = CallAnswerType.UNKNOWN; + warning("Unknown value %s for content.answer.type in a m.call.answer event", + node.get_string()); + } + } else { + warning("content.answer.type is missing from a m.call.answer event"); + } + + if ((node = answer_root.get_member("sdp")) != null) { + _answer_sdp = node.get_string(); + } else { + warning("content.answer.sdp is missing from a m.call.answer event"); + } + } + + if ((node = content_root.get_member("version")) != null) { + _version = (int)node.get_int(); + } else { + warning("content.version is missing from a m.call.answer event"); + } + + base.from_json(json_data); + } + + protected override void + to_json(Json.Node json_data) + throws Matrix.Error + { + if (_version == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.answer event without version"); + } + + if (_call_id == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.answer event without call_id"); + } + + if (_answer_type == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.answer event without answer.type"); + } + + if (_answer_sdp == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.answer event without answer.sdp"); + } + + var content_root = json_data.get_object() + .get_member("content").get_object(); + + content_root.set_string_member("call_id", _call_id); + content_root.set_int_member("version", _version); + + var answer_root = new Json.Object(); + var answer_node = new Json.Node(Json.NodeType.OBJECT); + answer_node.set_object(answer_root); + + answer_root.set_string_member("type", + _g_enum_value_to_nick(typeof(CallAnswerType), + _answer_type)); + answer_root.set_string_member("sdp", _answer_sdp); + + content_root.set_member("answer", answer_node); + + base.to_json(json_data); + } +} diff --git a/src/matrix-event-call-candidates.vala b/src/matrix-event-call-candidates.vala index dd9016b..695a5f0 100644 --- a/src/matrix-event-call-candidates.vala +++ b/src/matrix-event-call-candidates.vala @@ -50,6 +50,9 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room { default = null; } + /** + * The version of the VoIP specification this messages adheres to. + */ public int? version { get; set; default = null; } private List? _candidates; diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index 04a65ae..75c42b9 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -215,6 +215,9 @@ matrix_event_types_ctor(void) matrix_event_register_type("m.call.candidates", MATRIX_EVENT_TYPE_CALL_CANDIDATES, NULL); + matrix_event_register_type("m.call.answer", + MATRIX_EVENT_TYPE_CALL_ANSWER, + NULL); } void diff --git a/src/matrix-types.vala b/src/matrix-types.vala index 6f19979..729e203 100644 --- a/src/matrix-types.vala +++ b/src/matrix-types.vala @@ -281,6 +281,11 @@ namespace Matrix { OFFER; /// call offer } + public enum CallAnswerType { + UNKNOWN, /// represents a value unknown to this library + ANSWER; /// call answer + } + public struct ImageInfo { int? size; int? height;