-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose Realtime options on SupabaseClient (#377)
* Update RealtimeClientV2.swift Provide a means to configure RealtimeV2 options * Update SupabaseClient.swift * Update RealtimeClientV2.swift * feat(realtime): add RealtimeClientOptions and expose it to SupbaseClient * Add deprecated init to avoid breaking changes * use renamed for deprecation message * merge headers in-place * fix realtime integration tests * test logger instance --------- Co-authored-by: Guilherme Souza <grsouza@pm.me>
- Loading branch information
1 parent
866a039
commit 9cfafdb
Showing
12 changed files
with
210 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Types.swift | ||
// | ||
// | ||
// Created by Guilherme Souza on 13/05/24. | ||
// | ||
|
||
import _Helpers | ||
import Foundation | ||
|
||
/// Options for initializing ``RealtimeClientV2``. | ||
public struct RealtimeClientOptions: Sendable { | ||
package var headers: HTTPHeaders | ||
var heartbeatInterval: TimeInterval | ||
var reconnectDelay: TimeInterval | ||
var timeoutInterval: TimeInterval | ||
var disconnectOnSessionLoss: Bool | ||
var connectOnSubscribe: Bool | ||
package var logger: (any SupabaseLogger)? | ||
|
||
public static let defaultHeartbeatInterval: TimeInterval = 15 | ||
public static let defaultReconnectDelay: TimeInterval = 7 | ||
public static let defaultTimeoutInterval: TimeInterval = 10 | ||
public static let defaultDisconnectOnSessionLoss = true | ||
public static let defaultConnectOnSubscribe: Bool = true | ||
|
||
public init( | ||
headers: [String: String] = [:], | ||
heartbeatInterval: TimeInterval = Self.defaultHeartbeatInterval, | ||
reconnectDelay: TimeInterval = Self.defaultReconnectDelay, | ||
timeoutInterval: TimeInterval = Self.defaultTimeoutInterval, | ||
disconnectOnSessionLoss: Bool = Self.defaultDisconnectOnSessionLoss, | ||
connectOnSubscribe: Bool = Self.defaultConnectOnSubscribe, | ||
logger: (any SupabaseLogger)? = nil | ||
) { | ||
self.headers = HTTPHeaders(headers) | ||
self.heartbeatInterval = heartbeatInterval | ||
self.reconnectDelay = reconnectDelay | ||
self.timeoutInterval = timeoutInterval | ||
self.disconnectOnSessionLoss = disconnectOnSessionLoss | ||
self.connectOnSubscribe = connectOnSubscribe | ||
self.logger = logger | ||
} | ||
|
||
var apikey: String? { | ||
headers["apikey"] | ||
} | ||
|
||
var accessToken: String? { | ||
guard let accessToken = headers["Authorization"]?.split(separator: " ").last else { | ||
return nil | ||
} | ||
return String(accessToken) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.