1- //
2- // RealtimeChannelV2.swift
3- //
4- //
5- // Created by Guilherme Souza on 26/12/23.
6- //
7-
81import ConcurrencyExtras
92import Foundation
103import HTTPTypes
114import Helpers
5+ import IssueReporting
126
137#if canImport(FoundationNetworking)
148 import FoundationNetworking
@@ -123,9 +117,10 @@ public final class RealtimeChannelV2: Sendable {
123117 public func subscribe( ) async {
124118 if socket. status ( ) != . connected {
125119 if socket. options ( ) . connectOnSubscribe != true {
126- fatalError (
120+ reportIssue (
127121 " You can't subscribe to a channel while the realtime client is not connected. Did you forget to call `realtime.connect()`? "
128122 )
123+ return
129124 }
130125 await socket. connect ( )
131126 }
@@ -261,15 +256,21 @@ public final class RealtimeChannelV2: Sendable {
261256 }
262257 }
263258
259+ /// Tracks the given state in the channel.
260+ /// - Parameter state: The state to be tracked, conforming to `Codable`.
261+ /// - Throws: An error if the tracking fails.
264262 public func track( _ state: some Codable ) async throws {
265263 try await track ( state: JSONObject ( state) )
266264 }
267265
266+ /// Tracks the given state in the channel.
267+ /// - Parameter state: The state to be tracked as a `JSONObject`.
268268 public func track( state: JSONObject ) async {
269- assert (
270- status == . subscribed,
271- " You can only track your presence after subscribing to the channel. Did you forget to call `channel.subscribe()`? "
272- )
269+ if status != . subscribed {
270+ reportIssue (
271+ " You can only track your presence after subscribing to the channel. Did you forget to call `channel.subscribe()`? "
272+ )
273+ }
273274
274275 await push (
275276 ChannelEvent . presence,
@@ -281,6 +282,7 @@ public final class RealtimeChannelV2: Sendable {
281282 )
282283 }
283284
285+ /// Stops tracking the current state in the channel.
284286 public func untrack( ) async {
285287 await push (
286288 ChannelEvent . presence,
@@ -508,10 +510,12 @@ public final class RealtimeChannelV2: Sendable {
508510 filter: String ? ,
509511 callback: @escaping @Sendable ( AnyAction ) -> Void
510512 ) -> RealtimeSubscription {
511- precondition (
512- status != . subscribed,
513- " You cannot call postgresChange after joining the channel "
514- )
513+ guard status == . subscribed else {
514+ reportIssue (
515+ " You cannot call postgresChange after joining the channel, this won't work as expected. "
516+ )
517+ return RealtimeSubscription { }
518+ }
515519
516520 let config = PostgresJoinConfig (
517521 event: event,
0 commit comments