CLASS
WebSocket
public final class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSocketStreamDelegate
Properties
delegate
public weak var delegate: WebSocketClientDelegate?
Responds to callback about new messages coming in over the WebSocket and also connection/disconnect messages.
callbackQueue
public var callbackQueue = DispatchQueue.main
onConnect
public var onConnect: (() -> Void)?
onDisconnect
public var onDisconnect: ((Error?) -> Void)?
onText
public var onText: ((String) -> Void)?
onData
public var onData: ((Data) -> Void)?
onPong
public var onPong: ((Data?) -> Void)?
onHttpResponseHeaders
public var onHttpResponseHeaders: (([String: String]) -> Void)?
disableSSLCertValidation
public var disableSSLCertValidation = false
overrideTrustHostname
public var overrideTrustHostname = false
desiredTrustHostname
public var desiredTrustHostname: String? = nil
sslClientCertificate
public var sslClientCertificate: SSLClientCertificate? = nil
enableCompression
public var enableCompression = true
security
public var security: SSLTrustValidator?
enabledSSLCipherSuites
public var enabledSSLCipherSuites: [SSLCipherSuite]?
isConnected
public var isConnected: Bool
request
public var request: URLRequest
currentURL
public var currentURL: URL
respondToPingWithPong
public var respondToPingWithPong: Bool = true
Methods
init(request:protocol:)
public 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:)
public 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:)
public convenience init(url: URL,writeQueueQOS: QualityOfService,protocol: WSProtocol)
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()
public func connect()
Connect to the WebSocket server on a background thread.
disconnect()
public func disconnect()
write(string:)
public func write(string: String)
write(ping:completion:)
public func write(ping: Data, completion: (() -> ())? = nil)
Write a ping to the websocket. This sends it as a control frame.
newBytesInStream()
public func newBytesInStream()
Delegate for the stream methods. Processes incoming bytes
streamDidError(error:)
public func streamDidError(error: Error?)
deinit
deinit