Skip to content

Extract a shared MQTT client core for v3.1.1 and v5 lifecycle logic #699

Description

@hjianbo

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions