Skip to content

feat(realtime): add presence-enabled flag to join push #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

grdsdev
Copy link
Collaborator

@grdsdev grdsdev commented Jun 27, 2025

Description

This PR adds support for the presence enabled flag in the realtime join push. When a presence callback exists on a channel, the presence enabled flag is automatically set to true during the subscription process.

Changes

  • Core Implementation: Modified RealtimeChannelV2.subscribe() to set config.presence.enabled = true when presence callbacks exist
  • Logic: Uses callbackManager.callbacks.contains(where: { $0.isPresence }) to detect presence callbacks
  • Testing: Added comprehensive test case testPresenceEnabledDuringSubscribe() that verifies the presence enabled flag is correctly set during subscription

Test Coverage

The new test testPresenceEnabledDuringSubscribe() in Tests/RealtimeTests/RealtimeChannelTests.swift:

  • Uses FakeWebSocket to simulate real WebSocket communication
  • Verifies that presence callbacks are properly detected
  • Checks that the presence.enabled flag is set to true in the phx_join payload when presence callbacks exist
  • Includes proper cleanup of subscriptions and connections

Technical Details

The implementation automatically enables presence when:

  1. A channel has one or more presence callbacks registered via onPresenceChange()
  2. The channel subscribes to the realtime server
  3. The presence enabled flag is included in the join configuration sent to the server

This ensures that presence functionality is only enabled when actually needed, optimizing server-side processing and network traffic.

Testing

All existing tests pass, and the new test validates the core functionality:

swift test --filter RealtimeChannelTests

Related Issues

Closes #CLIBS-219

- Add presenceEnabled property to RealtimeJoinConfig
- Update CallbackManager to handle presence-enabled joins
- Modify RealtimeChannelV2 to support presence-enabled configuration
- Add tests for presence-enabled functionality
- Update .gitignore for new test artifacts

This change allows developers to explicitly enable/disable presence
functionality when joining realtime channels, providing better control
over presence behavior in realtime subscriptions.
@coveralls
Copy link

coveralls commented Jun 27, 2025

Pull Request Test Coverage Report for Build 15971610786

Details

  • 13 of 22 (59.09%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 75.841%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Sources/Realtime/RealtimeChannelV2.swift 5 14 35.71%
Totals Coverage Status
Change from base Build 15556137759: 0.2%
Covered Lines: 5255
Relevant Lines: 6929

💛 - Coveralls

grdsdev added 2 commits June 27, 2025 07:24
- Add comprehensive test that verifies presence.enabled is set to true when presence callback exists
- Test uses FakeWebSocket to simulate real subscription flow
- Verifies that presence enabled flag is correctly set in phx_join payload
- Ensures proper cleanup of subscriptions and connections

This test validates the core functionality where presence enabled is automatically set based on presence callback existence.
…bscribed channel

When a presence callback is added to an already subscribed channel, the channel now automatically resubscribes to ensure the presence functionality works correctly. This fixes an issue where presence callbacks added after subscription would not receive presence updates.

- Add resubscription logic in onPresenceChange method
- Log debug message when resubscribing
- Maintain existing callback registration behavior
@grdsdev grdsdev requested review from dshukertjr and o-santi June 30, 2025 17:54
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.

3 participants