Skip to content
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

feat: expose Realtime options on SupabaseClient #377

Merged
merged 9 commits into from
May 13, 2024
40 changes: 29 additions & 11 deletions Sources/Realtime/V2/RealtimeClientV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ import Foundation
public typealias JSONObject = _Helpers.JSONObject

public actor RealtimeClientV2 {
public struct ConfigurationOptions: Sendable {
var heartbeatInterval: TimeInterval
var reconnectDelay: TimeInterval
var timeoutInterval: TimeInterval
var disconnectOnSessionLoss: Bool
var connectOnSubscribe: Bool

public init(
heartbeatInterval: TimeInterval = 15,
reconnectDelay: TimeInterval = 7,
timeoutInterval: TimeInterval = 10,
disconnectOnSessionLoss: Bool = true,
connectOnSubscribe: Bool = true
) {
self.heartbeatInterval = heartbeatInterval
self.reconnectDelay = reconnectDelay
self.timeoutInterval = timeoutInterval
self.disconnectOnSessionLoss = disconnectOnSessionLoss
self.connectOnSubscribe = connectOnSubscribe
}
}

public struct Configuration: Sendable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be better marked as internal given it's not intended to be accessed by consumers

var url: URL
var apiKey: String
Expand All @@ -26,26 +48,22 @@ public actor RealtimeClientV2 {
var disconnectOnSessionLoss: Bool
var connectOnSubscribe: Bool
var logger: (any SupabaseLogger)?

public init(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also might be better marked as internal given it's not intended to be accessed by consumers

url: URL,
apiKey: String,
headers: [String: String] = [:],
heartbeatInterval: TimeInterval = 15,
reconnectDelay: TimeInterval = 7,
timeoutInterval: TimeInterval = 10,
disconnectOnSessionLoss: Bool = true,
connectOnSubscribe: Bool = true,
options: ConfigurationOptions = ConfigurationOptions(),
logger: (any SupabaseLogger)? = nil
) {
self.url = url
self.apiKey = apiKey
self.headers = headers
self.heartbeatInterval = heartbeatInterval
self.reconnectDelay = reconnectDelay
self.timeoutInterval = timeoutInterval
self.disconnectOnSessionLoss = disconnectOnSessionLoss
self.connectOnSubscribe = connectOnSubscribe
self.heartbeatInterval = options.heartbeatInterval
self.reconnectDelay = options.reconnectDelay
self.timeoutInterval = options.timeoutInterval
self.disconnectOnSessionLoss = options.disconnectOnSessionLoss
self.connectOnSubscribe = options.connectOnSubscribe
self.logger = logger
}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Supabase/SupabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public final class SupabaseClient: @unchecked Sendable {
public init(
supabaseURL: URL,
supabaseKey: String,
options: SupabaseClientOptions
options: SupabaseClientOptions,
realtimeOptions: RealtimeClientV2.ConfigurationOptions = RealtimeClientV2.ConfigurationOptions()
) {
self.supabaseURL = supabaseURL
self.supabaseKey = supabaseKey
Expand Down Expand Up @@ -150,6 +151,7 @@ public final class SupabaseClient: @unchecked Sendable {
url: supabaseURL.appendingPathComponent("/realtime/v1"),
apiKey: supabaseKey,
headers: defaultHeaders,
options: realtimeOptions,
logger: options.global.logger
)
)
Expand Down