Socket
public class Socketextension Socket: WebSocketDelegateSocket Connection
A single connection is established to the server and
channels are multiplexed over the connection.
Connect to the server using the Socket class:
let socket = new Socket("/socket", paramsClosure: { ["userToken": "123" ] })
socket.connect()
The Socket constructor takes the mount point of the socket,
the authentication params, as well as options that can be found in
the Socket docs, such as configuring the heartbeat.
- 
                  
                  The string WebSocket endpoint (ie "ws://example.com/socket","wss://example.com", etc.) That was passed to the Socket during initialization. The URL endpoint will be modified by the Socket to include"/websocket"if missing.DeclarationSwift public let endPoint: String
- 
                  
                  The fully qualified socket URL DeclarationSwift public private(set) var endPointUrl: URL
- 
                  
                  Resolves to return the paramsClosureresult at the time of calling. If theSocketwas created with static params, then those will be returned every time.DeclarationSwift public var params: Payload? { get }
- 
                  
                  The optional params closure used to get params whhen connecting. Must be set when initializaing the Socket. DeclarationSwift public let paramsClosure: PayloadClosure?
- 
                  
                  Override to provide custom encoding of data before writing to the socket DeclarationSwift public var encode: ([String : Any]) -> Data
- 
                  
                  Override to provide customd decoding of data read from the socket DeclarationSwift public var decode: (Data) -> [String : Any]?
- 
                  
                  Timeout to use when opening connections DeclarationSwift public var timeout: TimeInterval
- 
                  
                  Interval between sending a heartbeat DeclarationSwift public var heartbeatInterval: TimeInterval
- 
                  
                  Interval between socket reconnect attempts, in seconds DeclarationSwift public var reconnectAfter: (Int) -> TimeInterval
- 
                  
                  Interval between channel rejoin attempts, in seconds DeclarationSwift public var rejoinAfter: (Int) -> TimeInterval
- 
                  
                  The optional function to receive logs DeclarationSwift public var logger: ((String) -> Void)?
- 
                  
                  Disables heartbeats from being sent. Default is false. DeclarationSwift public var skipHeartbeat: Bool
- 
                  
                  Enable/Disable SSL certificate validation. Default is false. This must be set before calling socket.connect()in order to be appliedDeclarationSwift public var disableSSLCertValidation: Bool
- 
                  
                  Configure custom SSL validation logic, eg. SSL pinning. This must be set before calling socket.connect()in order to apply.DeclarationSwift public var security: SSLTrustValidator?
- 
                  
                  Configure the encryption used by your client by setting the allowed cipher suites supported by your server. This must be set before calling socket.connect()in order to apply.DeclarationSwift public var enabledSSLCipherSuites: [SSLCipherSuite]?
- 
                  
                  Undocumented DeclarationSwift public convenience init(_ endPoint: String, params: Payload? = nil)
- 
                  
                  Undocumented DeclarationSwift public convenience init(_ endPoint: String, paramsClosure: PayloadClosure?)
- 
                  
                  - return: The socket protocol, wss or ws
 DeclarationSwift public var websocketProtocol: String { get }
- 
                  
                  - return: True if the socket is connected
 DeclarationSwift public var isConnected: Bool { get }
- 
                  
                  Connects the Socket. The params passed to the Socket on initialization will be sent through the connection. If the Socket is already connected, then this call will be ignored. DeclarationSwift public func connect()
- 
                  
                  Disconnects the socket - paramter callback: Optional. Called when disconnected
 DeclarationSwift public func disconnect(code: CloseCode = CloseCode.normal, callback: (() -> Void)? = nil)ParameterscodeOptional. Closing status code 
- 
                  
                  Registers callbacks for connection open events. Does not handle retain cycles. Use delegateOnOpen(to:)for automatic handling of retain cycles.Example: socket.onOpen() { [weak self] in self?.print("Socket Connection Open") }DeclarationSwift public func onOpen(callback: @escaping () -> Void)ParameterscallbackCalled when the Socket is opened 
- 
                  
                  Registers callbacks for connection open events. Automatically handles retain cycles. Use onOpen()to handle yourself.Example: socket.delegateOnOpen(to: self) { self in self.print("Socket Connection Open") }DeclarationSwift public func delegateOnOpen<T: AnyObject>(to owner: T, callback: @escaping ((T) -> Void))ParametersownerClass registering the callback. Usually selfcallbackCalled when the Socket is opened 
- 
                  
                  Registers callbacks for connection close events. Does not handle retain cycles. Use delegateOnClose(_:)for automatic handling of retain cycles.Example: socket.onClose() { [weak self] in self?.print("Socket Connection Close") }DeclarationSwift public func onClose(callback: @escaping () -> Void)ParameterscallbackCalled when the Socket is closed 
- 
                  
                  Registers callbacks for connection close events. Automatically handles retain cycles. Use onClose()to handle yourself.Example: socket.delegateOnClose(self) { self in self.print("Socket Connection Close") }DeclarationSwift public func delegateOnClose<T: AnyObject>(to owner: T, callback: @escaping ((T) -> Void))ParametersownerClass registering the callback. Usually selfcallbackCalled when the Socket is closed 
- 
                  
                  Registers callbacks for connection error events. Does not handle retain cycles. Use delegateOnError(to:)for automatic handling of retain cycles.Example: socket.onError() { [weak self] (error) in self?.print("Socket Connection Error", error) }DeclarationSwift public func onError(callback: @escaping (Error) -> Void)ParameterscallbackCalled when the Socket errors 
- 
                  
                  Registers callbacks for connection error events. Automatically handles retain cycles. Use manualOnError()to handle yourself.Example: socket.delegateOnError(to: self) { (self, error) in self.print("Socket Connection Error", error) }DeclarationSwift public func delegateOnError<T: AnyObject>(to owner: T, callback: @escaping ((T, Error) -> Void))ParametersownerClass registering the callback. Usually selfcallbackCalled when the Socket errors 
- 
                  
                  Registers callbacks for connection message events. Does not handle retain cycles. Use delegateOnMessage(_to:)for automatic handling of retain cycles.Example: socket.onMessage() { [weak self] (message) in self?.print("Socket Connection Message", message) }DeclarationSwift public func onMessage(callback: @escaping (Message) -> Void)ParameterscallbackCalled when the Socket receives a message event 
- 
                  
                  Registers callbacks for connection message events. Automatically handles retain cycles. Use onMessage()to handle yourself.Example: socket.delegateOnMessage(self) { (self, message) in self.print("Socket Connection Message", message) }DeclarationSwift public func delegateOnMessage<T: AnyObject>(to owner: T, callback: @escaping ((T, Message) -> Void))ParametersownerClass registering the callback. Usually selfcallbackCalled when the Socket receives a message event 
- 
                  
                  Releases all stored callback hooks (onError, onOpen, onClose, etc.) You should call this method when you are finished when the Socket in order to release any references held by the socket. DeclarationSwift public func releaseCallbacks()
- 
                  
                  Initialize a new Channel Example: let channel = socket.channel("rooms", params: ["user_id": "abc123"])- return: A new channel
 DeclarationSwift public func channel(_ topic: String, params: [String: Any] = [:]) -> ChannelParameterstopicTopic of the channel paramsOptional. Parameters for the channel 
- 
                  
                  Removes the Channel from the socket. This does not cause the channel to inform the server that it is leaving. You should call channel.leave() prior to removing the Channel. Example: channel.leave() socket.remove(channel)DeclarationSwift public func remove(_ channel: Channel)ParameterschannelChannel to remove 
- 
                  
                  - return: the next message ref, accounting for overflows
 DeclarationSwift public func makeRef() -> String
- 
                  
                  Undocumented DeclarationSwift public func websocketDidConnect(socket: WebSocketClient)
- 
                  
                  Undocumented DeclarationSwift public func websocketDidDisconnect(socket: WebSocketClient, error: Error?)
- 
                  
                  Undocumented DeclarationSwift public func websocketDidReceiveMessage(socket: WebSocketClient, text: String)
- 
                  
                  Undocumented DeclarationSwift public func websocketDidReceiveData(socket: WebSocketClient, data: Data)
 Socket Class Reference
        Socket Class Reference