Created
March 9, 2018 16:07
-
-
Save dfalmeida/0388b6b48b9ac345854ecdf6cf05e1a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public func sendMessage(with channelId: String, | |
event: String, | |
payload: Socket.Payload, | |
onSuccess: @escaping (Socket.Payload) -> (), | |
onError: @escaping (Socket.Payload) -> ()) { | |
guard let socket = socket else { return } | |
if socket.isConnected { | |
socket.channels[channelId]?.send(event, payload: payload)? | |
.receive("ok", callback: onSuccess) | |
.receive("error", callback: onError) | |
} else { | |
// Call error callback when the socket is not connected | |
onError([:]) | |
socket.connect() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment