Create a base call for m.call.* events
This commit is contained in:
parent
b9ded01e98
commit
ff6400a94a
1
.gitignore
vendored
1
.gitignore
vendored
@ -79,3 +79,4 @@ Makefile.in
|
|||||||
/src/matrix-event-call-candidates.c
|
/src/matrix-event-call-candidates.c
|
||||||
/src/matrix-event-call-answer.c
|
/src/matrix-event-call-answer.c
|
||||||
/src/matrix-event-call-hangup.c
|
/src/matrix-event-call-hangup.c
|
||||||
|
/src/matrix-event-call-base.c
|
||||||
|
@ -45,6 +45,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
|||||||
matrix-event-room-guest-access.vala \
|
matrix-event-room-guest-access.vala \
|
||||||
matrix-event-room-redaction.vala \
|
matrix-event-room-redaction.vala \
|
||||||
matrix-event-room-third-party-invite.vala \
|
matrix-event-room-third-party-invite.vala \
|
||||||
|
matrix-event-call-base.vala \
|
||||||
matrix-event-call-invite.vala \
|
matrix-event-call-invite.vala \
|
||||||
matrix-event-call-candidates.vala \
|
matrix-event-call-candidates.vala \
|
||||||
matrix-event-call-answer.vala \
|
matrix-event-call-answer.vala \
|
||||||
|
@ -19,12 +19,7 @@
|
|||||||
/**
|
/**
|
||||||
* This event is sent by the callee when they wish to answer the call.
|
* This event is sent by the callee when they wish to answer the call.
|
||||||
*/
|
*/
|
||||||
public class Matrix.Event.CallAnswer : Matrix.Event.Room {
|
public class Matrix.Event.CallAnswer : Matrix.Event.Call {
|
||||||
/**
|
|
||||||
* The ID of the call this event relates to.
|
|
||||||
*/
|
|
||||||
public string? call_id { get; set; default = null; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of session description.
|
* 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; }
|
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
|
protected override void
|
||||||
from_json(Json.Node json_data)
|
from_json(Json.Node json_data)
|
||||||
throws Matrix.Error
|
throws Matrix.Error
|
||||||
@ -48,12 +38,6 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Room {
|
|||||||
.get_member("content").get_object();
|
.get_member("content").get_object();
|
||||||
Json.Node? node;
|
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) {
|
if ((node = content_root.get_member("answer")) != null) {
|
||||||
var answer_root = node.get_object();
|
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);
|
base.from_json(json_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,16 +70,6 @@ public class Matrix.Event.CallAnswer : Matrix.Event.Room {
|
|||||||
to_json(Json.Node json_data)
|
to_json(Json.Node json_data)
|
||||||
throws Matrix.Error
|
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) {
|
if (_answer_type == null) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
"Won't generate a m.call.answer event without answer.type");
|
"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()
|
var content_root = json_data.get_object()
|
||||||
.get_member("content").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_root = new Json.Object();
|
||||||
var answer_node = new Json.Node(Json.NodeType.OBJECT);
|
var answer_node = new Json.Node(Json.NodeType.OBJECT);
|
||||||
answer_node.set_object(answer_root);
|
answer_node.set_object(answer_root);
|
||||||
|
78
src/matrix-event-call-base.vala
Normal file
78
src/matrix-event-call-base.vala
Normal file
@ -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
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@
|
|||||||
* callee after answering. Its purpose is to give the other party
|
* callee after answering. Its purpose is to give the other party
|
||||||
* additional ICE candidates to try using to communicate.
|
* 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 {
|
public struct Candidate {
|
||||||
string? sdp_mid; /// The SDP media type this candidate is
|
string? sdp_mid; /// The SDP media type this candidate is
|
||||||
/// intended for.
|
/// intended for.
|
||||||
@ -30,11 +30,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
|
|||||||
string? candidate; /// The SDP 'a' line of the candidate.
|
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.
|
* The list of candidates.
|
||||||
*/
|
*/
|
||||||
@ -50,11 +45,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
|
|||||||
default = null;
|
default = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The version of the VoIP specification this messages adheres to.
|
|
||||||
*/
|
|
||||||
public int? version { get; set; default = null; }
|
|
||||||
|
|
||||||
private List<Candidate?>? _candidates;
|
private List<Candidate?>? _candidates;
|
||||||
|
|
||||||
protected override void
|
protected override void
|
||||||
@ -65,12 +55,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
|
|||||||
.get_member("content").get_object();
|
.get_member("content").get_object();
|
||||||
Json.Node? node;
|
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) {
|
if ((node = content_root.get_member("candidates")) != null) {
|
||||||
node.get_array().foreach_element((ary, idx, cand_node) => {
|
node.get_array().foreach_element((ary, idx, cand_node) => {
|
||||||
var cand_root = cand_node.get_object();
|
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");
|
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);
|
base.from_json(json_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,16 +91,6 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Room {
|
|||||||
to_json(Json.Node json_data)
|
to_json(Json.Node json_data)
|
||||||
throws Matrix.Error
|
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)) {
|
if ((_candidates == null) || (_candidates.length() < 1)) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
"Won't generate a m.call.candidates event without candidates");
|
"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()
|
var content_root = json_data.get_object()
|
||||||
.get_member("content").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();
|
var cands = new Json.Array();
|
||||||
|
|
||||||
foreach (var entry in _candidates) {
|
foreach (var entry in _candidates) {
|
||||||
|
@ -21,37 +21,11 @@
|
|||||||
* can be sent either once the call has has been established or before
|
* can be sent either once the call has has been established or before
|
||||||
* to abort the call.
|
* to abort the call.
|
||||||
*/
|
*/
|
||||||
public class Matrix.Event.CallHangup : Matrix.Event.Room {
|
public class Matrix.Event.CallHangup : Matrix.Event.Call {
|
||||||
/**
|
|
||||||
* 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
|
protected override void
|
||||||
from_json(Json.Node json_data)
|
from_json(Json.Node json_data)
|
||||||
throws Matrix.Error
|
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);
|
base.from_json(json_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,22 +33,6 @@ public class Matrix.Event.CallHangup : Matrix.Event.Room {
|
|||||||
to_json(Json.Node json_data)
|
to_json(Json.Node json_data)
|
||||||
throws Matrix.Error
|
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);
|
base.to_json(json_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,7 @@
|
|||||||
* This event is sent by the caller when they wish to establish a
|
* This event is sent by the caller when they wish to establish a
|
||||||
* call.
|
* call.
|
||||||
*/
|
*/
|
||||||
public class Matrix.Event.CallInvite : Matrix.Event.Room {
|
public class Matrix.Event.CallInvite : Matrix.Event.Call {
|
||||||
/**
|
|
||||||
* A unique identifer for the call.
|
|
||||||
*/
|
|
||||||
public string? call_id { get; set; default = null;}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of session description.
|
* The type of session description.
|
||||||
*/
|
*/
|
||||||
@ -35,11 +30,6 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
|
|||||||
*/
|
*/
|
||||||
public string? sdp { get; set; default = null; }
|
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
|
* The time in milliseconds that the invite is valid for. Once the
|
||||||
* invite age exceeds this value, clients should discard it. They
|
* 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();
|
.get_member("content").get_object();
|
||||||
Json.Node? node;
|
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) {
|
if ((node = content_root.get_member("offer")) != null) {
|
||||||
var offer_node = node.get_object();
|
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) {
|
if ((node = content_root.get_member("lifetime")) != null) {
|
||||||
_lifetime = (int)node.get_int();
|
_lifetime = (int)node.get_int();
|
||||||
} else {
|
} else {
|
||||||
@ -111,16 +89,11 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
|
|||||||
"Won't generate a m.call.invite without offer.type");
|
"Won't generate a m.call.invite without offer.type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_offer_sdp == null) {
|
if (_sdp == null) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
"Won't generate a m.call.invite without offer.sdp");
|
"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) {
|
if (_lifetime == null) {
|
||||||
throw new Matrix.Error.INCOMPLETE(
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
"Won't generate a m.call.invite without lifetime");
|
"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()
|
var content_root = json_data.get_object()
|
||||||
.get_member("content").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);
|
content_root.set_int_member("lifetime", _lifetime);
|
||||||
|
|
||||||
var offer_root = new Json.Object();
|
var offer_root = new Json.Object();
|
||||||
@ -141,7 +112,7 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room {
|
|||||||
"type",
|
"type",
|
||||||
_g_enum_value_to_nick(typeof(CallOfferType),
|
_g_enum_value_to_nick(typeof(CallOfferType),
|
||||||
_offer_type));
|
_offer_type));
|
||||||
offer_root.set_string_member("sdp", _offer_sdp);
|
offer_root.set_string_member("sdp", _sdp);
|
||||||
|
|
||||||
content_root.set_member("offer", offer_node);
|
content_root.set_member("offer", offer_node);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user