-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
642 additions
and
143 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
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,30 @@ | ||
import Dispatch | ||
import Foundation | ||
|
||
class CodableRealtimeConnection<Input: Encodable>: RealtimeConnection<Input> { | ||
override public func send(_ data: Input) throws { | ||
let json = try JSONEncoder().encode(data) | ||
try sendReference(json) | ||
} | ||
} | ||
|
||
public extension Realtime { | ||
func connect<Input: Encodable, Output: Decodable>( | ||
to app: String, | ||
connectionKey: String, | ||
throttleInterval: DispatchTimeInterval, | ||
onResult completion: @escaping (Result<Output, Error>) -> Void | ||
) throws -> RealtimeConnection<Input> { | ||
return handleConnection( | ||
to: app, connectionKey: connectionKey, throttleInterval: throttleInterval, | ||
resultConverter: { data in | ||
let result = try JSONDecoder().decode(Output.self, from: data) | ||
return result | ||
}, | ||
connectionFactory: { send, close in | ||
CodableRealtimeConnection(send, close) | ||
}, | ||
onResult: completion | ||
) | ||
} | ||
} |
Oops, something went wrong.