wire up some callbacks
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "./tox_client.hpp"
|
||||
|
||||
#include "./tox_utils.hpp"
|
||||
#include "./tox_callbacks.hpp"
|
||||
#include "toxcore/tox.h"
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
@@ -9,6 +11,7 @@
|
||||
#include <stdexcept>
|
||||
|
||||
ToxClient::ToxClient(const CommandLine& cl) :
|
||||
_self_name(cl.self_name),
|
||||
_tox_profile_path(cl.profile_path)
|
||||
{
|
||||
TOX_ERR_OPTIONS_NEW err_opt_new;
|
||||
@@ -16,8 +19,8 @@ ToxClient::ToxClient(const CommandLine& cl) :
|
||||
assert(err_opt_new == TOX_ERR_OPTIONS_NEW::TOX_ERR_OPTIONS_NEW_OK);
|
||||
|
||||
// use cl for options
|
||||
//tox_options_set_log_callback(options, log_cb);
|
||||
tox_options_set_local_discovery_enabled(options, false);
|
||||
tox_options_set_log_callback(options, log_cb);
|
||||
tox_options_set_local_discovery_enabled(options, true);
|
||||
tox_options_set_udp_enabled(options, true);
|
||||
tox_options_set_hole_punching_enabled(options, true);
|
||||
|
||||
@@ -57,6 +60,43 @@ ToxClient::ToxClient(const CommandLine& cl) :
|
||||
throw std::runtime_error{"tox failed"};
|
||||
}
|
||||
|
||||
#define CALLBACK_REG(x) tox_callback_##x(_tox, x##_cb)
|
||||
CALLBACK_REG(self_connection_status);
|
||||
|
||||
//CALLBACK_REG(friend_name);
|
||||
//CALLBACK_REG(friend_status_message);
|
||||
//CALLBACK_REG(friend_status);
|
||||
//CALLBACK_REG(friend_connection_status);
|
||||
//CALLBACK_REG(friend_typing);
|
||||
//CALLBACK_REG(friend_read_receipt);
|
||||
CALLBACK_REG(friend_request);
|
||||
//CALLBACK_REG(friend_message);
|
||||
|
||||
//CALLBACK_REG(file_recv_control);
|
||||
//CALLBACK_REG(file_chunk_request);
|
||||
//CALLBACK_REG(file_recv);
|
||||
//CALLBACK_REG(file_recv_chunk);
|
||||
|
||||
//CALLBACK_REG(conference_invite);
|
||||
//CALLBACK_REG(conference_connected);
|
||||
//CALLBACK_REG(conference_message);
|
||||
//CALLBACK_REG(conference_title);
|
||||
//CALLBACK_REG(conference_peer_name);
|
||||
//CALLBACK_REG(conference_peer_list_changed);
|
||||
|
||||
//CALLBACK_REG(friend_lossy_packet);
|
||||
//CALLBACK_REG(friend_lossless_packet);
|
||||
|
||||
CALLBACK_REG(group_custom_packet);
|
||||
CALLBACK_REG(group_custom_private_packet);
|
||||
CALLBACK_REG(group_invite);
|
||||
#undef CALLBACK_REG
|
||||
|
||||
if (_self_name.empty()) {
|
||||
_self_name = "tox_ngc_ft1_tool";
|
||||
}
|
||||
tox_self_set_name(_tox, reinterpret_cast<const uint8_t*>(_self_name.data()), _self_name.size(), nullptr);
|
||||
|
||||
_tox_profile_dirty = true;
|
||||
}
|
||||
|
||||
@@ -77,6 +117,37 @@ std::string ToxClient::getOwnAddress(void) const {
|
||||
return bin2hex(self_addr);
|
||||
}
|
||||
|
||||
void ToxClient::onToxSelfConnectionStatus(TOX_CONNECTION connection_status) {
|
||||
std::cout << "TCL self status: ";
|
||||
switch (connection_status) {
|
||||
case TOX_CONNECTION::TOX_CONNECTION_NONE: std::cout << "offline\n"; break;
|
||||
case TOX_CONNECTION::TOX_CONNECTION_TCP: std::cout << "TCP-relayed\n"; break;
|
||||
case TOX_CONNECTION::TOX_CONNECTION_UDP: std::cout << "UDP-direct\n"; break;
|
||||
}
|
||||
_tox_profile_dirty = true;
|
||||
}
|
||||
|
||||
void ToxClient::onToxFriendRequest(const uint8_t* public_key, std::string_view message) {
|
||||
std::vector<uint8_t> key(public_key, public_key + TOX_PUBLIC_KEY_SIZE);
|
||||
std::cout << "TCL adding friend " << bin2hex(key) << " (" << message << ")\n";
|
||||
|
||||
tox_friend_add_norequest(_tox, public_key, nullptr);
|
||||
_tox_profile_dirty = true;
|
||||
}
|
||||
|
||||
void ToxClient::onToxGroupCustomPacket(uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length) {
|
||||
}
|
||||
|
||||
void ToxClient::onToxGroupCustomPrivatePacket(uint32_t group_number, uint32_t peer_id, const uint8_t *data, size_t length) {
|
||||
}
|
||||
|
||||
void ToxClient::onToxGroupInvite(uint32_t friend_number, const uint8_t* invite_data, size_t invite_length, std::string_view group_name) {
|
||||
std::cout << "TCL accepting group invite (" << group_name << ")\n";
|
||||
|
||||
tox_group_invite_accept(_tox, friend_number, invite_data, invite_length, reinterpret_cast<const uint8_t*>(_self_name.data()), _self_name.size(), nullptr, 0, nullptr);
|
||||
_tox_profile_dirty = true;
|
||||
}
|
||||
|
||||
void ToxClient::saveToxProfile(void) {
|
||||
if (_tox_profile_path.empty()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user