WebSocket
CLASS
WebSocket
1public final class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSocketStreamDelegate
Properties
delegate
1public weak var delegate: WebSocketClientDelegate?
Responds to callback about new messages coming in over the WebSocket and also connection/disconnect messages.
callbackQueue
1public var callbackQueue = DispatchQueue.main
onConnect
1public var onConnect: (() -> Void)?
onDisconnect
1public var onDisconnect: ((Error?) -> Void)?
onText
1public var onText: ((String) -> Void)?
onData
1public var onData: ((Data) -> Void)?
onPong
1public var onPong: ((Data?) -> Void)?
onHttpResponseHeaders
1public var onHttpResponseHeaders: (([String: String]) -> Void)?
disableSSLCertValidation
1public var disableSSLCertValidation = false
overrideTrustHostname
1public var overrideTrustHostname = false
desiredTrustHostname
1public var desiredTrustHostname: String? = nil
sslClientCertificate
1public var sslClientCertificate: SSLClientCertificate? = nil
enableCompression
1public var enableCompression = true
security
1public var security: SSLTrustValidator?
enabledSSLCipherSuites
1public var enabledSSLCipherSuites: [SSLCipherSuite]?
isConnected
1public var isConnected: Bool
request
1public var request: URLRequest
currentURL
1public var currentURL: URL
respondToPingWithPong
1public var respondToPingWithPong: Bool = true
Methods
init(request:protocol:)
1public init(request: URLRequest, protocol: WSProtocol)
Designated initializer.
Parameters:
request: A URL request object that provides request-specific information such as the URL.
protocol: Protocol to use for communication over the web socket.
Parameters
Name | Description |
---|---|
request | A URL request object that provides request-specific information such as the URL. |
protocol | Protocol to use for communication over the web socket. |
init(url:protocol:)
1public convenience init(url: URL, protocol: WSProtocol)
Convenience initializer to specify the URL and web socket protocol.
Parameters:
url: The destination URL to connect to.
protocol: Protocol to use for communication over the web socket.
Parameters
Name | Description |
---|---|
url | The destination URL to connect to. |
protocol | Protocol to use for communication over the web socket. |
init(url:writeQueueQOS:protocol:)
1public convenience init(
2 url: URL,
3 writeQueueQOS: QualityOfService,
4 protocol: WSProtocol
5)
Convenience initializer to specify the URL and web socket protocol with a specific quality of service on the write queue.
Parameters:
url: The destination URL to connect to.
writeQueueQOS: Specifies the quality of service for the write queue.
protocol: Protocol to use for communication over the web socket.
Parameters
Name | Description |
---|---|
url | The destination URL to connect to. |
writeQueueQOS | Specifies the quality of service for the write queue. |
protocol | Protocol to use for communication over the web socket. |
connect()
1public func connect()
Connect to the WebSocket server on a background thread.
disconnect()
1public func disconnect()
write(string:)
1public func write(string: String)
write(ping:completion:)
1public func write(ping: Data, completion: (() -> ())? = nil)
Write a ping to the websocket. This sends it as a control frame.
newBytesInStream()
1public func newBytesInStream()
Delegate for the stream methods. Processes incoming bytes
streamDidError(error:)
1public func streamDidError(error: Error?)
deinit
1deinit