diff --git a/.gitignore b/.gitignore
index 7ba75f1..46a92ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -79,3 +79,4 @@ Makefile.in
/src/matrix-event-call-candidates.c
/src/matrix-event-call-answer.c
/src/matrix-event-call-hangup.c
+/src/matrix-event-call-base.c
diff --git a/src/Makefile.am b/src/Makefile.am
index e233bad..6fdf4b1 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-base.vala \
matrix-event-call-invite.vala \
matrix-event-call-candidates.vala \
matrix-event-call-answer.vala \
diff --git a/src/matrix-event-call-answer.vala b/src/matrix-event-call-answer.vala
index 93289ac..ca81bee 100644
--- a/src/matrix-event-call-answer.vala
+++ b/src/matrix-event-call-answer.vala
@@ -19,12 +19,7 @@
/**
* 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; }
-
+public class Matrix.Event.CallAnswer : Matrix.Event.Call {
/**
* The type of session description.
*/
@@ -35,11 +30,6 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Room {
*/
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
@@ -48,12 +38,6 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Room {
.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();
@@ -79,12 +63,6 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Room {
}
}
- 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);
}
@@ -92,16 +70,6 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Room {
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");
@@ -115,9 +83,6 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Room {
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);
diff --git a/src/matrix-event-call-base.vala b/src/matrix-event-call-base.vala
new file mode 100644
index 0000000..941148b
--- /dev/null
+++ b/src/matrix-event-call-base.vala
@@ -0,0 +1,78 @@
+/*
+ * 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
+ * .
+ */
+
+/**
+ * Base class for m.call.* events.
+ */
+public abstract class Matrix.Event.Call : Matrix.Event.Room {
+ /**
+ * The ID of the call this event relates to.
+ */
+ public string? call_id { get; set; default = null; }
+
+ /**
+ * The version of the VoIP specification this message 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.hangup event");
+ }
+
+ if ((node = content_root.get_member("version")) != null) {
+ _version = (int)node.get_int();
+ } else {
+ warning("content.version is missing from a m.call.hangup event");
+ }
+
+ base.from_json(json_data);
+ }
+
+ protected override void
+ to_json(Json.Node json_data)
+ throws Matrix.Error
+ {
+ if (_call_id == null) {
+ throw new Matrix.Error.INCOMPLETE(
+ "Won't generate a m.call.hangup event without call_id");
+ }
+
+ if (_version == null) {
+ throw new Matrix.Error.INCOMPLETE(
+ "Won't generate a m.call.hangup event without version");
+ }
+
+ 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);
+
+ base.to_json(json_data);
+ }
+}
diff --git a/src/matrix-event-call-candidates.vala b/src/matrix-event-call-candidates.vala
index 695a5f0..a94c28c 100644
--- a/src/matrix-event-call-candidates.vala
+++ b/src/matrix-event-call-candidates.vala
@@ -21,7 +21,7 @@
* 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.Room {
+public class Matrix.Event.CallCandidates : Matrix.Event.Call {
public struct Candidate {
string? sdp_mid; /// The SDP media type this candidate is
/// intended for.
@@ -30,11 +30,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
string? candidate; /// The SDP 'a' line of the candidate.
}
- /**
- * The ID of the call this event relates to.
- */
- public string? call_id { get; set; default = null; }
-
/**
* The list of candidates.
*/
@@ -50,11 +45,6 @@ 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;
protected override void
@@ -65,12 +55,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
.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.candidates event");
- }
-
if ((node = content_root.get_member("candidates")) != null) {
node.get_array().foreach_element((ary, idx, cand_node) => {
var cand_root = cand_node.get_object();
@@ -100,12 +84,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
warning("content.candidates is missing from a m.call.candidates event");
}
- if ((node = content_root.get_member("version")) != null) {
- _version = (int)node.get_int();
- } else {
- warning("content.version is missing from a m.call.candidates event");
- }
-
base.from_json(json_data);
}
@@ -113,16 +91,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
to_json(Json.Node json_data)
throws Matrix.Error
{
- if (_call_id == null) {
- throw new Matrix.Error.INCOMPLETE(
- "Won't generate a m.call.candidates event without call_id");
- }
-
- if (_version == null) {
- throw new Matrix.Error.INCOMPLETE(
- "Won't generate a m.call.candidates event without version");
- }
-
if ((_candidates == null) || (_candidates.length() < 1)) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.call.candidates event without candidates");
@@ -131,9 +99,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
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 cands = new Json.Array();
foreach (var entry in _candidates) {
diff --git a/src/matrix-event-call-hangup.vala b/src/matrix-event-call-hangup.vala
index bb828d6..9b099fb 100644
--- a/src/matrix-event-call-hangup.vala
+++ b/src/matrix-event-call-hangup.vala
@@ -21,37 +21,11 @@
* can be sent either once the call has has been established or before
* to abort the call.
*/
-public class Matrix.Event.CallHangup : Matrix.Event.Room {
- /**
- * The ID of the call this event relates to.
- */
- public string? call_id { get; set; default = null; }
-
- /**
- * The version of the VoIP specification this message adheres to.
- */
- public int? version { get; set; default = null; }
-
+public class Matrix.Event.CallHangup : Matrix.Event.Call {
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.hangup event");
- }
-
- if ((node = content_root.get_member("version")) != null) {
- _version = (int)node.get_int();
- } else {
- warning("content.version is missing from a m.call.hangup event");
- }
-
base.from_json(json_data);
}
@@ -59,22 +33,6 @@ public class Matrix.Event.CallHangup : Matrix.Event.Room {
to_json(Json.Node json_data)
throws Matrix.Error
{
- if (_call_id == null) {
- throw new Matrix.Error.INCOMPLETE(
- "Won't generate a m.call.hangup event without call_id");
- }
-
- if (_version == null) {
- throw new Matrix.Error.INCOMPLETE(
- "Won't generate a m.call.hangup event without version");
- }
-
- 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);
-
base.to_json(json_data);
}
}
diff --git a/src/matrix-event-call-invite.vala b/src/matrix-event-call-invite.vala
index 7e1dfc1..78afc6a 100644
--- a/src/matrix-event-call-invite.vala
+++ b/src/matrix-event-call-invite.vala
@@ -20,12 +20,7 @@
* 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;}
-
+public class Matrix.Event.CallInvite : Matrix.Event.Call {
/**
* The type of session description.
*/
@@ -35,11 +30,6 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
*/
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
@@ -56,12 +46,6 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
.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();
@@ -87,12 +71,6 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
}
}
- 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 {
@@ -111,16 +89,11 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
"Won't generate a m.call.invite without offer.type");
}
- if (_offer_sdp == null) {
+ if (_sdp == null) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.call.invite without offer.sdp");
}
- if (_version == null) {
- throw new Matrix.Error.INCOMPLETE(
- "Won't generate a m.call.invite without version");
- }
-
if (_lifetime == null) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.call.invite without lifetime");
@@ -129,8 +102,6 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
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);
content_root.set_int_member("lifetime", _lifetime);
var offer_root = new Json.Object();
@@ -141,7 +112,7 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
"type",
_g_enum_value_to_nick(typeof(CallOfferType),
_offer_type));
- offer_root.set_string_member("sdp", _offer_sdp);
+ offer_root.set_string_member("sdp", _sdp);
content_root.set_member("offer", offer_node);