Motivation
CocoaMQTT.swift (~980 lines) and CocoaMQTT5.swift (~1,111 lines) duplicate connection lifecycle, reconnect policy, keepalive, packet ID allocation, delivery, transport delegation, and callback dispatch.
Fixes are already inconsistent—for example, v5 wraps connState in ConcurrentAtomic while v3 does not. Every reconnect or delivery change must be implemented and tested twice.
Suggested architecture
Keep public/Objective-C-compatible v3 and v5 facades, backed by a shared internal core with injected:
- protocol codec;
- connection state machine;
- delivery/session engine;
- packet identifier allocator;
- reconnect policy;
- keepalive scheduler/clock;
- transport;
- session store.
Protocol-specific frame and property behavior should remain in separate codecs rather than being selected through global state.
Acceptance criteria
- Shared lifecycle behavior has one implementation and one protocol-neutral test suite.
- MQTT 3.1.1 and MQTT 5 differences are explicit typed dependencies.
- Existing public APIs and Objective-C delegate compatibility are preserved.
- v3 and v5 can run concurrently without shared mutable protocol state.
Motivation
CocoaMQTT.swift(~980 lines) andCocoaMQTT5.swift(~1,111 lines) duplicate connection lifecycle, reconnect policy, keepalive, packet ID allocation, delivery, transport delegation, and callback dispatch.Fixes are already inconsistent—for example, v5 wraps
connStateinConcurrentAtomicwhile v3 does not. Every reconnect or delivery change must be implemented and tested twice.Suggested architecture
Keep public/Objective-C-compatible v3 and v5 facades, backed by a shared internal core with injected:
Protocol-specific frame and property behavior should remain in separate codecs rather than being selected through global state.
Acceptance criteria