Skip to content

New realtime sdk methods and working#1466

Merged
ArnabChatterjee20k merged 9 commits into
masterfrom
realtime-add-new-messages
Apr 21, 2026
Merged

New realtime sdk methods and working#1466
ArnabChatterjee20k merged 9 commits into
masterfrom
realtime-add-new-messages

Conversation

@ArnabChatterjee20k
Copy link
Copy Markdown
Member

@ArnabChatterjee20k ArnabChatterjee20k commented Apr 20, 2026

What does this PR do?

realtime = new Realtime()
sub1 = realtime.subscribe()
sub2 = realtime.subscribe()

// for unsubscribing only sub1
sub1.unsubscribe() // earlier it would disconnect the whole client
sub2.unsubscribe() // only sub2

// update
sub1.update({channels:[], queries:[]})

// disconnect the whole client
realtime.disconnect() // typically during the component unmount

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 20, 2026

Greptile Summary

This PR replaces the slot-based subscription-ID reconciliation model with client-generated UUIDs across web, Flutter, Android, and Apple SDK templates, and adds unsubscribe(), update(), and disconnect() as first-class methods on the subscription object.

  • React Native not updated: templates/react-native/src/client.ts.twig is in the changeset but subscribe() still returns a bare () => void with the old slotToSubscriptionId/pendingSubscribeSlots internals — the new unsubscribe, update, and disconnect API is absent for React Native consumers.
  • Android lock held across ws.send(): In Realtime.kt.twig, sendPendingSubscribes() is called inside synchronized(subscriptionLock) in subscribe(), causing ws.send() to execute while the lock is held — a potential deadlock with OkHttp's IO-thread callbacks that also acquire subscriptionLock.

Confidence Score: 4/5

Safe to merge after the Android lock scope and React Native gaps are resolved.

Two P1 findings remain: the React Native template missing the new API entirely, and the Android subscribe() holding subscriptionLock across ws.send() which is a latent deadlock. The core redesign is sound across web, Flutter, Apple, and Android listener paths.

templates/react-native/src/client.ts.twig (missing new API) and templates/android/library/src/main/java/io/package/services/Realtime.kt.twig (lock held across ws.send).

Important Files Changed

Filename Overview
templates/react-native/src/client.ts.twig subscribe() still returns () => void using the old slot-based model — missing the new unsubscribe/update/disconnect API that was added to every other platform in this PR.
templates/android/library/src/main/java/io/package/services/Realtime.kt.twig Switches to client-generated subscriptionIds with LinkedHashMap pending queue; sendPendingSubscribes called inside the lock in subscribe() causing ws.send() to execute while the lock is held.
templates/apple/Sources/Services/Realtime.swift.twig Migrated to client-side subscriptionIds; update closure calls DispatchQueue.sync inside an async context which can block the Swift cooperative thread pool; logic otherwise well-structured.
templates/flutter/lib/src/realtime_mixin.dart.twig Adds unsubscribe/update/close to RealtimeSubscription; _createSocket still computes allChannels set just to check emptiness; overall logic is correct.
templates/web/src/services/realtime.ts.twig Complete redesign using client-generated subscriptionIds; adds unsubscribe/update/disconnect with debounce logic; pendingSubscribes.clear() precedes socket.send() but reconnect re-enqueue mitigates silent drops.
templates/flutter/lib/src/realtime_subscription.dart.twig Adds unsubscribe, update, and close fields; clean data class with correct documentation.
templates/android/library/src/main/java/io/package/models/RealtimeModels.kt.twig Adds RealtimeSubscriptionUpdate and unsubscribe/update fields to RealtimeSubscription; channels typed as Collection to accept both String and Channel objects.
templates/swift/Sources/Models/RealtimeModels.swift.twig Adds RealtimeSubscriptionUpdate and RealtimeSubscription classes with unsubscribe/update/close async actions; clean implementation.

Comments Outside Diff (1)

  1. templates/react-native/src/client.ts.twig, line 513-540 (link)

    P1 React Native subscribe still returns the old () => void teardown — missing unsubscribe, update, and disconnect

    Every other platform in this PR (web, Flutter, Android, Apple) now returns a RealtimeSubscription object with unsubscribe(), update(), and close() methods, plus a top-level disconnect(). The React Native template was included in the changeset but its subscribe() still returns a bare () => void closure backed by the old slotToSubscriptionId / subscriptionIdToSlot maps. React Native consumers cannot call sub.unsubscribe() or sub.update({channels, queries}) as described in the PR.

    The Realtime type defined inside the file (lines 108–140) also still references pendingSubscribeSlots, slotToSubscriptionId, and subscriptionIdToSlot — the slot-based model that was replaced everywhere else.

Reviews (6): Last reviewed commit: "refactor: update subscription handling t..." | Re-trigger Greptile

Comment thread tests/languages/android/Tests.kt
Comment thread templates/android/library/src/main/java/io/package/services/Realtime.kt.twig Outdated
Comment thread templates/web/src/services/realtime.ts.twig Outdated
@ArnabChatterjee20k ArnabChatterjee20k changed the title updated New realtime sdk methods and working Apr 20, 2026
#1467)

* refactor: update subscription handling to use unique subscription IDs across services

* updated

* updated

* feat: implement unique subscription ID generation across services

* updated

* updated
@ArnabChatterjee20k ArnabChatterjee20k merged commit 72dd118 into master Apr 21, 2026
57 checks passed
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.

2 participants