Skip to content

Commit

Permalink
Add to callback queue to centrifuge client and socket
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Gorbachev committed Feb 20, 2019
1 parent 6bf07e0 commit b715e8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CentrifugeiOS/Classes/Centrifuge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public enum CentrifugeErrorCode: Int {
public typealias CentrifugeMessageHandler = (CentrifugeServerMessage?, Error?) -> Void

public final class Centrifuge {
public class func client(url: URL, creds: CentrifugeCredentials, delegate: CentrifugeClientDelegate) -> CentrifugeClient {
return CentrifugeClientImpl(url: url, credentials: creds, delegate: delegate)
public class func client(url: URL, creds: CentrifugeCredentials, delegate: CentrifugeClientDelegate, callBackQueue: DispatchQueue = DispatchQueue.main) -> CentrifugeClient {
return CentrifugeClientImpl(url: url, credentials: creds, delegate: delegate, callBackQueue: callBackQueue)
}

public class func createToken(string: String, key: String) -> String {
Expand Down
11 changes: 9 additions & 2 deletions CentrifugeiOS/Classes/CentrifugeClientImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import Starscream

final class CentrifugeClientImpl: CentrifugeClient {
init(url: URL, credentials: CentrifugeCredentials, delegate: CentrifugeClientDelegate) {
init(url: URL, credentials: CentrifugeCredentials, delegate: CentrifugeClientDelegate, callBackQueue: DispatchQueue) {
self.url = url
self.creds = credentials
self.delegate = delegate
self.callBackQueue = callBackQueue
self.builder = CentrifugeClientMessageBuilderImpl()
self.parser = CentrifugeServerMessageParserImpl()
}
Expand Down Expand Up @@ -87,7 +88,13 @@ final class CentrifugeClientImpl: CentrifugeClient {
send(message: message)
}

private lazy var webSocket = WebSocket(with: url, delegate: self)
private lazy var webSocket: WebSocket = {
let webSocket = WebSocket(with: url, delegate: self)
webSocket.delegate = self
webSocket.callbackQueue = callBackQueue
return webSocket
}()
private let callBackQueue: DispatchQueue
private let url: URL
private let creds: CentrifugeCredentials
private let builder: CentrifugeClientMessageBuilder
Expand Down

0 comments on commit b715e8f

Please sign in to comment.