Skip to content
Snippets Groups Projects
Commit d165d1ef authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add MessageSender

parent 4ae1a96a
No related branches found
No related tags found
1 merge request!2Bindings API wrapper
......@@ -2,6 +2,7 @@ import Bindings
public struct Connection {
public var isAuthenticated: () -> Bool
public var send: MessageSender
}
extension Connection {
......@@ -9,7 +10,8 @@ extension Connection {
bindingsConnection: BindingsConnection
) -> Connection {
Connection(
isAuthenticated: { false }
isAuthenticated: { false },
send: .live(bindingsConnection: bindingsConnection)
)
}
......@@ -17,7 +19,8 @@ extension Connection {
bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
) -> Connection {
Connection(
isAuthenticated: bindingsAuthenticatedConnection.isAuthenticated
isAuthenticated: bindingsAuthenticatedConnection.isAuthenticated,
send: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection)
)
}
}
......@@ -25,7 +28,8 @@ extension Connection {
#if DEBUG
extension Connection {
public static let failing = Connection(
isAuthenticated: { false }
isAuthenticated: { false },
send: .failing
)
}
#endif
import Bindings
public struct MessageSender {
public var send: (Int, Data) throws -> Data
public func callAsFunction(
messageType: Int,
payload: Data
) throws -> Data {
try send(messageType, payload)
}
}
extension MessageSender {
public static func live(
bindingsConnection: BindingsConnection
) -> MessageSender {
MessageSender { messageType, payload in
try bindingsConnection.sendE2E(messageType, payload: payload)
}
}
public static func live(
bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
) -> MessageSender {
MessageSender { messageType, payload in
try bindingsAuthenticatedConnection.sendE2E(messageType, payload: payload)
}
}
}
#if DEBUG
extension MessageSender {
public static let failing = MessageSender { _, _ in
struct NotImplemented: Error {}
throw NotImplemented()
}
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment