Skip to content
Snippets Groups Projects
Commit 16dc1f49 authored by trilene's avatar trilene
Browse files

Fix calls with voip v1 clients

parent 004d4203
No related branches found
No related tags found
No related merge requests found
Pipeline #789 passed
#include <cstdlib>
#include <string>
#include "mtx/events/voip.hpp"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace {
uint16_t
version(const json &obj)
{
auto v = obj.at("version");
try {
return v.get<uint16_t>();
} catch (const json::type_error &) {
return std::atoi(v.get<std::string>().c_str());
}
}
}
namespace mtx::events::msg {
// m.call.invite
......@@ -12,7 +29,7 @@ from_json(const json &obj, CallInvite &content)
{
content.call_id = obj.at("call_id").get<std::string>();
content.sdp = obj.at("offer").at("sdp").get<std::string>();
content.version = obj.at("version").get<uint16_t>();
content.version = version(obj);
content.lifetime = obj.at("lifetime").get<uint32_t>();
}
......@@ -47,7 +64,7 @@ from_json(const json &obj, CallCandidates &content)
{
content.call_id = obj.at("call_id").get<std::string>();
content.candidates = obj.at("candidates").get<std::vector<CallCandidates::Candidate>>();
content.version = obj.at("version").get<uint16_t>();
content.version = version(obj);
}
void
......@@ -64,7 +81,7 @@ from_json(const json &obj, CallAnswer &content)
{
content.call_id = obj.at("call_id").get<std::string>();
content.sdp = obj.at("answer").at("sdp").get<std::string>();
content.version = obj.at("version").get<uint16_t>();
content.version = version(obj);
}
void
......@@ -80,7 +97,7 @@ void
from_json(const json &obj, CallHangUp &content)
{
content.call_id = obj.at("call_id").get<std::string>();
content.version = obj.at("version").get<uint16_t>();
content.version = version(obj);
if (obj.count("reason") == 0) {
content.reason = CallHangUp::Reason::User;
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment