Skip to content

feat(broadcasting): Echo facade, BroadcastManager, Reverb driver (#37)#38

Merged
anilcancakir merged 4 commits intomasterfrom
feat/broadcasting
Apr 5, 2026
Merged

feat(broadcasting): Echo facade, BroadcastManager, Reverb driver (#37)#38
anilcancakir merged 4 commits intomasterfrom
feat/broadcasting

Conversation

@anilcancakir
Copy link
Copy Markdown
Contributor

Summary

  • Echo facade (17th facade) — Laravel Echo equivalent API: channel(), private(), join(), listen(), leave(), connect(), disconnect(), socketId, connectionState, onReconnect, addInterceptor(), fake()/unfake()
  • ReverbBroadcastDriver — Pusher-compatible WebSocket client (~820 lines): automatic reconnection with exponential backoff, event deduplication via ring buffer, application-level ping/pong heartbeat, private/presence channel auth, interceptor pipeline, channelFactory DI for testability
  • NullBroadcastDriver — zero-allocation no-op driver using const Stream.empty() for local dev
  • BroadcastManager — config-driven driver resolution with extend() for custom drivers, follows LogManager/CacheManager pattern
  • BroadcastInterceptoronSend(Map), onReceive(BroadcastEvent), onError(dynamic) with pass-through defaults
  • BroadcastServiceProvider — opt-in (NOT auto-registered), auto-connects on boot unless default is 'null'
  • FakeBroadcastManagerEcho.fake() returns fake with assertion helpers: assertConnected(), assertDisconnected(), assertSubscribed(), assertNotSubscribed(), assertInterceptorAdded()
  • Magic CLI--without-broadcasting flag, broadcasting_config.stub, env vars (BROADCAST_DRIVER, REVERB_HOST/PORT/SCHEME/APP_KEY)
  • Full documentationdoc/digging-deeper/broadcasting.md (9 sections), .claude/rules/broadcasting.md, skill references, CLI docs updated

Test plan

  • 829 tests pass (flutter test) — 123 new broadcasting tests across 7 test files
  • dart analyze — zero warnings, zero errors
  • Code review (ac:code-reviewer) — APPROVED
  • Plan compliance (ac:verifier) — APPROVE (47/47 criteria met)
  • Lint check (ac:linter) — CLEAN (all 22 source files)
  • CI pipeline (flutter analyze + format + test + coverage)

Closes #37

… full testing support (#37)

Laravel Echo equivalent for real-time WebSocket channels. Pusher-compatible
ReverbBroadcastDriver with automatic reconnection (exponential backoff),
event deduplication (ring buffer), application-level heartbeat, and
interceptor pipeline. NullBroadcastDriver for local dev. Echo.fake()
for testing with assertion helpers. BroadcastServiceProvider (opt-in).
CLI install stubs with --without-broadcasting flag.
Copilot AI review requested due to automatic review settings April 5, 2026 20:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a first-class broadcasting/WebSocket subsystem to Magic (Laravel Echo–style) including a new Echo facade, a config-driven BroadcastManager, and a Pusher/Reverb-compatible WebSocket driver, along with testing fakes and documentation updates.

Changes:

  • Introduces the broadcasting public API (Echo facade + contracts) and container integration (BroadcastManager, BroadcastServiceProvider, default config export).
  • Implements built-in drivers: ReverbBroadcastDriver (Pusher protocol) and NullBroadcastDriver (no-op).
  • Adds extensive test coverage plus docs/README/skill references and CLI documentation updates.

Reviewed changes

Copilot reviewed 32 out of 33 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
test/testing/fake_broadcast_manager_test.dart Tests FakeBroadcastManager behavior and Echo fake integration.
test/broadcasting/echo_facade_test.dart Verifies Echo facade API routes through manager/driver correctly.
test/broadcasting/drivers/reverb_broadcast_driver_test.dart Unit tests for Reverb driver lifecycle, protocol handling, reconnection, dedup, interceptors, channels.
test/broadcasting/drivers/null_broadcast_driver_test.dart Tests NullBroadcastDriver no-op semantics and silent channels.
test/broadcasting/broadcast_service_provider_test.dart Verifies provider registration and boot behavior with null default.
test/broadcasting/broadcast_manager_test.dart Tests driver resolution, caching, and custom driver registry behavior.
test/broadcasting/broadcast_event_test.dart Tests BroadcastEvent and BroadcastConnectionState basics.
skills/magic-framework/SKILL.md Updates facade count and adds Echo to framework skill reference.
skills/magic-framework/references/secondary-systems.md Adds broadcasting docs to the “secondary systems” reference.
skills/magic-framework/references/cli-commands.md Documents new CLI install flag and generated broadcasting config.
README.md Adds broadcasting feature highlight and includes Echo.fake() in testing list.
pubspec.yaml Adds web_socket_channel dependency for WebSocket support.
lib/src/testing/fake_broadcast_manager.dart Implements FakeBroadcastManager + FakeBroadcastDriver for tests/assertions.
lib/src/foundation/application.dart Registers default broadcasting config into the app’s default config set.
lib/src/facades/echo.dart Adds Echo facade API (channels, lifecycle, interceptors, fake/unfake).
lib/src/broadcasting/drivers/reverb_broadcast_driver.dart Implements Pusher-compatible WebSocket driver + channels + presence.
lib/src/broadcasting/drivers/null_broadcast_driver.dart Implements no-op broadcast driver and silent channels.
lib/src/broadcasting/contracts/broadcast_presence_channel.dart Defines presence channel contract (members/onJoin/onLeave).
lib/src/broadcasting/contracts/broadcast_interceptor.dart Defines interceptor hooks with pass-through defaults.
lib/src/broadcasting/contracts/broadcast_driver.dart Defines broadcast driver interface for connections/channels.
lib/src/broadcasting/contracts/broadcast_channel.dart Defines broadcast channel interface for events + named listeners.
lib/src/broadcasting/broadcast_service_provider.dart Adds service provider to bind manager and optionally auto-connect.
lib/src/broadcasting/broadcast_manager.dart Adds config-driven driver resolution with extend() registry + caching.
lib/src/broadcasting/broadcast_event.dart Adds immutable BroadcastEvent envelope.
lib/src/broadcasting/broadcast_connection_state.dart Adds connection state enum.
lib/magic.dart Exports broadcasting API + config + testing fake.
lib/config/broadcasting.dart Provides default broadcasting configuration map.
example/pubspec.lock Updates example lockfile for new dependency resolution.
doc/packages/magic-cli.md Documents --without-broadcasting in CLI package docs.
doc/getting-started/installation.md Updates installation docs to mention broadcasting config + flag.
doc/digging-deeper/broadcasting.md Adds full broadcasting guide (config, usage, drivers, testing).
CHANGELOG.md Adds unreleased changelog entry for broadcasting feature set.
.claude/rules/broadcasting.md Adds internal domain rules/reference for broadcasting subsystem.

…ars, resource leak

- Fix docstring examples: Broadcast.xxx → Echo.xxx in all contracts
- Fix NullBroadcastDriver docstring config namespace (broadcast → broadcasting)
- Fix BroadcastServiceProvider docstring facade reference (Broadcast → Echo)
- Fix _authenticateAndSubscribe: safe type check instead of direct cast
- Fix reconnect resource leak: close existing WebSocket before reconnecting
- Fix env var consistency: BROADCAST_DRIVER → BROADCAST_CONNECTION everywhere
- Remove no-op mock.sentFrames in ping/pong test
@sentry
Copy link
Copy Markdown

sentry bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 95.87852% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../broadcasting/drivers/reverb_broadcast_driver.dart 95.09% 15 Missing ⚠️
lib/src/testing/fake_broadcast_manager.dart 95.08% 3 Missing ⚠️
lib/src/facades/echo.dart 96.15% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…, presence, interceptor defaults

Adds 29 tests covering previously uncovered paths:
- _onDone/_onError reconnection and interceptor routing
- _handlePusherError with fatal/immediate/backoff/malformed codes
- Presence events routed through driver (member_added/removed, subscription_succeeded)
- Subscription queue for private/presence channels before connect
- BroadcastInterceptor base class pass-through defaults (onSend/onReceive/onError)
- Echo.listen() and Echo.leave() facade methods
- BroadcastManager reverb driver resolution
- BroadcastServiceProvider boot with non-null driver
- Application event edge cases (unknown channel, missing channel, non-Map data)
Published version includes broadcasting config stub, env var fixes,
and install command --without-broadcasting support.
@anilcancakir anilcancakir merged commit 5059146 into master Apr 5, 2026
2 checks passed
@anilcancakir anilcancakir mentioned this pull request Apr 5, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broadcasting & WebSocket support (Laravel Echo equivalent)

2 participants