Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
This PR contains the complete MQTT feature for Catroid, implemented under the epic CATROID-1669: two new bricks that let a Catrobat program publish and receive network messages, enabling multiplayer games, IoT devices, and Home Assistant setups.
This is a draft PR opened for visibility, not for merging. It exists so the whole of the GSoC work is reviewable in one place. The individual tickets will be raised as their own PRs against develop and merged one by one; this branch will be closed once they have all landed.
Tickets already merged:
(Add MQTT dependencies, settings UI, and test coverage (CATROID-1670, CATROID-1672) #5220)
Tickets implemented in this branch:
Work in this branch that has no ticket yet, listed here so it can be split out once the tickets exist: wildcard topic matching, stage lifecycle integration, event dispatch, the two bricks, variable binding, the offline publish queue, reconnect with subscription recovery, and multiplayer over MQTT. Those commits deliberately carry no ticket prefix.
Changes Implemented
org.catrobat.catroid.devices.mqttMqttManagerThe central manager, a Koinsingleliving for the lifetime of the app. Owns the connection, publishing, subscriptions, listener routing, both queues and reconnect. A session flag ends the connection for good when the stage stops, so a connect still in flight cannot revive a stage the user has left.MqttClientInterface,PahoMqttClient,MqttClientFactoryAbstract the Paho client behind an interface soMqttManageris testable on the JVM without an Android runtime or a network.PahoMqttClientalso bounds Paho'stimeToWait, which otherwise waits forever for an unacknowledged publish.MqttConnectionConfigGroups the six broker parameters and reads them fromSettingsFragment.MqttTopicMatcherTopic matching to MQTT 3.1.1 section 4.7, including+,#and the rule that neither matches a topic beginning with$. Also validates filters and topic names, because Paho rejects malformed ones withIllegalArgumentExceptionrather thanMqttException.MqttMessageQueue,MqttPublishQueueBounded queues that drop the oldest entry when full. Incoming messages are buffered by the Paho network thread and drained on the render thread; outgoing messages wait here while the broker is unreachable and are flushed on reconnect.MqttListener,MqttEventDispatcher,MqttScriptRegistrarRoute a received message to the listeners registered for its topic, turn it into a Catroid event, and register and subscribe every MQTT script when the stage starts.MqttMultiplayerTransportCarries multiplayer variables over MQTT alongside Bluetooth, undercatrobat/multiplayer/<room>/<sender>/<variable>.Bricks, scripts and actions
PublishMqttMessageBrick,PublishMqttMessageActionPublish a formula-computed message to a formula-computed topic, with QoS and a retained flag. The send happens off the render thread so a slow broker cannot freeze the stage.WhenMqttMessageReceivedBrick,MqttScript,MqttEventIdA script that runs when a message arrives on a topic, optionally binding the payload and the topic to user variables. Both bindings are optional and a "not set" entry keeps them unset until the user picks a variable.Integration with existing code
Brick.MQTT_CONNECTIONas a stage resource, connection setup inStageResourceHolderand teardown inStageActivity, per-frame draining inStageListener, brick registration inCategoryBricksFactory, XStream aliases inXstreamSerializer, action creation inActionFactory, variable remapping inScriptController, and Koin registration inCatroidKoinHelper.Testing
51 files changed, 252 MQTT unit tests, 20 instrumented tests.
Known Limitations
Project.getRequiredResources()addsBrick.BLUETOOTH_MULTIPLAYERwhenever a project contains them, with no notion of which transport the user wants. The two bricks give working multiplayer in the meantime.Your Checklist