diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a63d431c..e5637efcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ v0.28.1 (master) * Add Brief/Article tabs in the Publish widget and load the form using Ajax * Improve Posts ticket layout * Fix Contacts invitation handling and notification counter +* XEP-0410: MUC Self-Ping, add timeout ping support (when the connection is lost and the pong is never sent) v0.28 --------------------------- diff --git a/src/Movim/ChatroomPings.php b/src/Movim/ChatroomPings.php index 62990ff89..d36d824d3 100644 --- a/src/Movim/ChatroomPings.php +++ b/src/Movim/ChatroomPings.php @@ -7,6 +7,7 @@ namespace Movim; use Moxl\Xec\Action\Ping\Room; +use App\Widgets\Rooms\Rooms as WidgetRooms; /** * Handling XEP-0410: MUC Self-Ping (Schrödinger's Chat) pings and timeouts @@ -15,7 +16,9 @@ class ChatroomPings { protected static $instance; private $_chatrooms = []; - private $_timeout = 5 * 60; + private $_chatroomsTimeout = []; + private $_pingIn = 5 * 60; + private $_pongTimeout = 5 * 60 + 10; public static function getInstance() { @@ -32,7 +35,7 @@ class ChatroomPings $this->clear($from); - $this->_chatrooms[$from] = $loop->addTimer($this->_timeout, function () use ($from) { + $this->_chatrooms[$from] = $loop->addTimer($this->_pingIn, function () use ($from) { $presence = \App\User::me()->session->conferences() ->where('conference', $from) ->first()?->presence; @@ -44,6 +47,10 @@ class ChatroomPings ->request(); } }); + + $this->_chatroomsTimeout[$from] = $loop->addTimer($this->_pongTimeout, function () use ($from) { + (new WidgetRooms())->ajaxExit($from); + }); } public function clear(string $from) @@ -52,6 +59,7 @@ class ChatroomPings if (array_key_exists($from, $this->_chatrooms)) { $loop->cancelTimer($this->_chatrooms[$from]); + $loop->cancelTimer($this->_chatroomsTimeout[$from]); } } } \ No newline at end of file diff --git a/src/Moxl/Xec/Action/Ping/Room.php b/src/Moxl/Xec/Action/Ping/Room.php index 191a45367..53503077c 100644 --- a/src/Moxl/Xec/Action/Ping/Room.php +++ b/src/Moxl/Xec/Action/Ping/Room.php @@ -2,7 +2,7 @@ namespace Moxl\Xec\Action\Ping; -use App\Widgets\Rooms\Rooms as RoomsRooms; +use App\Widgets\Rooms\Rooms as WidgetRooms; use Movim\ChatroomPings; use Moxl\Xec\Action; use Moxl\Stanza\Ping; @@ -29,6 +29,6 @@ class Room extends Action public function error(string $errorId, ?string $message = null) { - (new RoomsRooms())->ajaxExit($this->_room); + (new WidgetRooms())->ajaxExit($this->_room); } }