fetch group peer con state and slightly change interface

This commit is contained in:
Green Sky 2023-08-19 12:03:53 +02:00
parent 7c22bd51cc
commit dd596bdad8
No known key found for this signature in database
2 changed files with 27 additions and 3 deletions

View File

@ -45,6 +45,29 @@ ToxContactModel2::ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProvid
} }
} }
ToxContactModel2::~ToxContactModel2(void) {
}
void ToxContactModel2::iterate(float delta) {
// continually fetch group peer connection state, since JF does not want to add cb/event
_group_status_timer += delta;
// every second
if (_group_status_timer >= 1.f) {
_group_status_timer = 0.f;
_cr.view<Contact::Components::ToxGroupPeerEphemeral, Contact::Components::ConnectionState>().each([this](auto c, const auto& tox_peer, auto& con) {
auto state_opt = std::get<0>(_t.toxGroupPeerGetConnectionStatus(tox_peer.group_number, tox_peer.peer_number));
if (state_opt.has_value()) {
if (state_opt.value() == TOX_CONNECTION_UDP) {
con.state = Contact::Components::ConnectionState::State::direct;
} else if (state_opt.value() == TOX_CONNECTION_TCP) {
con.state = Contact::Components::ConnectionState::State::cloud;
}
}
});
}
}
void ToxContactModel2::acceptRequest(Contact3 c, std::string_view self_name, std::string_view password) { void ToxContactModel2::acceptRequest(Contact3 c, std::string_view self_name, std::string_view password) {
assert(!_cr.any_of<Contact::Components::ToxFriendEphemeral>(c)); assert(!_cr.any_of<Contact::Components::ToxFriendEphemeral>(c));
assert(_cr.all_of<Contact::Components::RequestIncoming>(c)); assert(_cr.all_of<Contact::Components::RequestIncoming>(c));

View File

@ -16,13 +16,14 @@ class ToxContactModel2 : public ContactModel3I, public ToxEventI {
Contact3 _friend_self; Contact3 _friend_self;
float _group_status_timer {0.f};
public: public:
ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProviderI& tep); ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProviderI& tep);
virtual ~ToxContactModel2(void) {} virtual ~ToxContactModel2(void);
// TODO: continually fetch group peer connection state, since JF does not want to add cb/event // TODO: continually fetch group peer connection state, since JF does not want to add cb/event
//void iterate(void); void iterate(float delta);
protected: // mmi protected: // mmi
// accept incoming request // accept incoming request