Commit 2c824edd authored by Adrien Dorsaz's avatar Adrien Dorsaz

adjust framed stream management

parent 1dc3bd41
#pragma once
#include <iostream>
#include "constants.hpp"
#include "IHttpClient.hpp"
......
......@@ -29,7 +29,7 @@ namespace Xmpp {
virtual ~IStream() {};
virtual ustring initiate() = 0;
virtual void initiate(ustring id, ustring from, ustring to) = 0;
virtual void initiate(ustring id, ustring from, ustring xmllang) = 0;
virtual ustring close() = 0;
};
}
......@@ -54,6 +54,10 @@ SoupHttpClient::websocket_send_close(ushort code, ustring data)
void
SoupHttpClient::websocket_send_message(ustring data)
{
if (Project::Constants::Debug)
{
std::cout << "Sending websocket message:" << std::endl << data.c_str() << std::endl;
}
soup_websocket_connection_send_text(_websocketConnection, data.c_str());
}
......
......@@ -131,15 +131,7 @@ Xmpp::Client::on_closing()
void
Xmpp::Client::on_connection()
{
// Lookup password
auto passwordFuture = std::async(&ISecretClient::password, _secretClient, _account.jid());
_httpClient->websocket_send_message(_stream.initiate());
// Use retrieved password
auto password = passwordFuture.get();
_httpClient->websocket_send_close(SOUP_WEBSOCKET_CLOSE_NORMAL, _stream.close());
}
void
......@@ -151,8 +143,6 @@ Xmpp::Client::on_error(ustring error)
void
Xmpp::Client::on_message(int type, Glib::RefPtr<Glib::Bytes> message)
{
std::cout << "Message received: type:"s << type << ", message: " << std::endl;
if (type == SOUP_WEBSOCKET_DATA_TEXT)
{
bool isValid {false};
......@@ -175,6 +165,11 @@ Xmpp::Client::on_message(int type, Glib::RefPtr<Glib::Bytes> message)
{
_httpClient->websocket_send_close(SOUP_WEBSOCKET_CLOSE_BAD_DATA , "unable to parse received message");
}
std::cout << "Message received: " << std::endl;
}
else
{
_httpClient->websocket_send_close(SOUP_WEBSOCKET_CLOSE_BAD_DATA , "unable to parse received message");
}
}
......@@ -18,27 +18,26 @@ Xmpp::FramedStream::initiate()
auto open = document.create_root_node("open", Xmpp::Constants::Framing);
open->set_attribute("from", _from);
open->set_attribute("to", _to);
open->set_attribute("id", _id);
open->set_attribute("xmllang", _xmllang);
if (!_xmllang.empty())
{
open->set_attribute("xmllang", _xmllang);
}
open->set_attribute("version", _version);
return document.write_to_string();
}
void
Xmpp::FramedStream::initiate(ustring id, ustring from, ustring to)
Xmpp::FramedStream::initiate(ustring id, ustring from, ustring xmllang)
{
this->_id = id;
this->_from = from;
this->_to = to;
_id = id;
_from = from;
_xmllang = xmllang;
}
ustring
Xmpp::FramedStream::close()
{
xmlpp::Document document {};
auto close = document.create_root_node("close", Xmpp::Constants::Framing);
close->set_attribute("from", _from);
close->set_attribute("to", _to);
close->set_attribute("version", _version);
document.create_root_node("close", Xmpp::Constants::Framing);
return document.write_to_string();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment