matrix-glib-sdk/src/matrix-event-call-answer.vala

101 lines
3.5 KiB
Vala
Raw Normal View History

2016-03-09 09:31:26 +00:00
/*
* 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 the callee when they wish to answer the call.
*/
2016-03-09 10:43:53 +00:00
public class Matrix.Event.CallAnswer : Matrix.Event.Call {
2016-03-09 09:31:26 +00:00
/**
* The type of session description.
*/
public CallAnswerType answer_type { get; set; default = CallAnswerType.UNKNOWN; }
2016-03-09 09:31:26 +00:00
/**
* The SDP text of the session description.
*/
public string? answer_sdp { 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("answer")) != null) {
var answer_root = node.get_object();
if ((node = answer_root.get_member("type")) != null) {
2017-11-03 06:19:29 +00:00
try {
_answer_type = (CallAnswerType)_g_enum_nick_to_value(
typeof(CallAnswerType), node.get_string());
} catch (Matrix.Error e) {
2016-03-09 09:31:26 +00:00
_answer_type = CallAnswerType.UNKNOWN;
if (Config.DEBUG) {
warning("Unknown value %s for content.answer.type in a m.call.answer event",
node.get_string());
}
2016-03-09 09:31:26 +00:00
}
} 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");
}
}
base.from_json(json_data);
}
protected override void
to_json(Json.Node json_data)
throws Matrix.Error
{
if (_answer_type == CallAnswerType.UNKNOWN) {
2016-03-09 09:31:26 +00:00
throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.call.answer event without a valid answer.type");
2016-03-09 09:31:26 +00:00
}
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();
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);
}
}