Skip to content

Instantly share code, notes, and snippets.

@mischa-hildebrand
Created October 24, 2018 16:26
Show Gist options
  • Save mischa-hildebrand/8d656ce68bb4797dc45b8afdcebcb71a to your computer and use it in GitHub Desktop.
Save mischa-hildebrand/8d656ce68bb4797dc45b8afdcebcb71a to your computer and use it in GitHub Desktop.
Connect to Web Socket
private func connectWebSocket() {
let url = URL(string: "ws://localhost:8080/api/echo")!
var urlRequest = URLRequest(url: url)
guard let tokens = LoginSessionManager.shared.tokens else {
// Handle connection failure
return
}
urlRequest.setValue("Bearer \(tokens.access_token)", forHTTPHeaderField: "Authorization")
webSocket = WebSocket(request: urlRequest)
webSocket?.delegate = self
webSocket?.connect()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment