Back to Socket Io Client Swift

SocketEngine

docs/Classes/SocketEngine.html

16.1.110.7 KB
Original Source

SocketEngine

open class SocketEngine:
        NSObject, WebSocketDelegate, URLSessionDelegate, SocketEnginePollable, SocketEngineWebsocket, ConfigSettable

The class that handles the engine.io protocol and transports. See SocketEnginePollable and SocketEngineWebsocket for transport specific methods.

Properties

`

                engineQueue
                `

The queue that all engine actions take place on.

Declaration

Swift

public let engineQueue: DispatchQueue

`

                connectParams
                `

The connect parameters sent during a connect.

Declaration

Swift

public var connectParams: [String : Any]? { get set }

`

                extraHeaders
                `

A dictionary of extra http headers that will be set during connection.

Declaration

Swift

public var extraHeaders: [String : String]?

`

                postWait
                `

A queue of engine.io messages waiting for POSTing

You should not touch this directly

Declaration

Swift

public var postWait: [Post]

`

                waitingForPoll
                `

true if there is an outstanding poll. Trying to poll before the first is done will cause socket.io to disconnect us.

Do not touch this directly

Declaration

Swift

public var waitingForPoll: Bool

`

                waitingForPost
                `

true if there is an outstanding post. Trying to post before the first is done will cause socket.io to disconnect us.

Do not touch this directly

Declaration

Swift

public var waitingForPost: Bool

`

                closed
                `

true if this engine is closed.

Declaration

Swift

public private(set) var closed: Bool { get }

`

                compress
                `

If true the engine will attempt to use WebSocket compression.

Declaration

Swift

public private(set) var compress: Bool { get }

`

                connected
                `

true if this engine is connected. Connected means that the initial poll connect has succeeded.

Declaration

Swift

public private(set) var connected: Bool { get }

`

                cookies
                `

An array of HTTPCookies that are sent during the connection.

Declaration

Swift

public private(set) var cookies: [HTTPCookie]? { get }

`

                fastUpgrade
                `

When true, the engine is in the process of switching to WebSockets.

Do not touch this directly

Declaration

Swift

public private(set) var fastUpgrade: Bool { get }

`

                forcePolling
                `

When true, the engine will only use HTTP long-polling as a transport.

Declaration

Swift

public private(set) var forcePolling: Bool { get }

`

                forceWebsockets
                `

When true, the engine will only use WebSockets as a transport.

Declaration

Swift

public private(set) var forceWebsockets: Bool { get }

`

                invalidated
                `

true If engine’s session has been invalidated.

Declaration

Swift

public private(set) var invalidated: Bool { get }

`

                polling
                `

If true, the engine is currently in HTTP long-polling mode.

Declaration

Swift

public private(set) var polling: Bool { get }

`

                probing
                `

If true, the engine is currently seeing whether it can upgrade to WebSockets.

Declaration

Swift

public private(set) var probing: Bool { get }

`

                session
                `

The URLSession that will be used for polling.

Declaration

Swift

public private(set) var session: URLSession? { get }

`

                sid
                `

The session id for this engine.

Declaration

Swift

public private(set) var sid: String { get }

`

                socketPath
                `

The path to engine.io.

Declaration

Swift

public private(set) var socketPath: String { get }

`

                urlPolling
                `

The url for polling.

Declaration

Swift

public private(set) var urlPolling: URL { get }

`

                urlWebSocket
                `

The url for WebSockets.

Declaration

Swift

public private(set) var urlWebSocket: URL { get }

`

                version
                `

The version of engine.io being used. Default is three.

Declaration

Swift

public private(set) var version: SocketIOVersion { get }

`

                websocket
                `

If true, then the engine is currently in WebSockets mode.

Declaration

Swift

@available(*, deprecated, message: "No longer needed, if we're not polling, then we must be doing websockets")
public private(set) var websocket: Bool { get }

`

                enableSOCKSProxy
                `

When true, the WebSocket stream will be configured with the enableSOCKSProxy true.

Declaration

Swift

public private(set) var enableSOCKSProxy: Bool { get }

`

                ws
                `

The WebSocket for this engine.

Declaration

Swift

public private(set) var ws: WebSocket? { get }

`

                wsConnected
                `

Whether or not the WebSocket is currently connected.

Declaration

Swift

public private(set) var wsConnected: Bool { get }

`

                client
                `

The client for this engine.

Declaration

Swift

public weak var client: SocketEngineClient?

Initializers

`

                init(client:url:config:)
                `

Creates a new engine.

Declaration

Swift

public init(client: SocketEngineClient, url: URL, config: SocketIOClientConfiguration)

Parameters

| client |

The client for this engine.

| | url |

The url for this engine.

| | config |

An array of configuration options for this engine.

|

`

                init(client:url:options:)
                `

Creates a new engine.

Declaration

Swift

public required convenience init(client: SocketEngineClient, url: URL, options: [String : Any]?)

Parameters

| client |

The client for this engine.

| | url |

The url for this engine.

| | options |

The options for this engine.

|

Methods

`

                connect()
                `

Starts the connection to the server.

Declaration

Swift

open func connect()

`

                didError(reason:)
                `

Called when an error happens during execution. Causes a disconnection.

Declaration

Swift

open func didError(reason: String)

`

                disconnect(reason:)
                `

Disconnects from the server.

Declaration

Swift

open func disconnect(reason: String)

Parameters

| reason |

The reason for the disconnection. This is communicated up to the client.

|

`

                doFastUpgrade()
                `

Called to switch from HTTP long-polling to WebSockets. After calling this method the engine will be in WebSocket mode.

You shouldn’t call this directly

Declaration

Swift

open func doFastUpgrade()

`

                flushWaitingForPostToWebSocket()
                `

Causes any packets that were waiting for POSTing to be sent through the WebSocket. This happens because when the engine is attempting to upgrade to WebSocket it does not do any POSTing.

You shouldn’t call this directly

Declaration

Swift

open func flushWaitingForPostToWebSocket()

`

                parseEngineData(_:)
                `

Parses raw binary received from engine.io.

Declaration

Swift

open func parseEngineData(_ data: Data)

Parameters

| data |

The data to parse.

|

`

                parseEngineMessage(_:)
                `

Parses a raw engine.io packet.

Declaration

Swift

open func parseEngineMessage(_ message: String)

Parameters

| message |

The message to parse.

|

`

                setConfigs(_:)
                `

Called when the engine should set/update its configs from a given configuration.

parameter config: The SocketIOClientConfiguration that should be used to set/update configs.

Declaration

Swift

open func setConfigs(_ config: SocketIOClientConfiguration)

`

                write(_:withType:withData:completion:)
                `

Writes a message to engine.io, independent of transport.

Declaration

Swift

open func write(_ msg: String, withType type: SocketEnginePacketType, withData data: [Data], completion: (() -> ())? = nil)

Parameters

| msg |

The message to send.

| | type |

The type of this message.

| | data |

Any data that this message has.

| | completion |

Callback called on transport write completion.

|

URLSessionDelegate methods

`

                URLSession(session:didBecomeInvalidWithError:)
                `

Delegate called when the session becomes invalid.

Declaration

Swift

public func URLSession(session: URLSession, didBecomeInvalidWithError error: NSError?)

`

                didReceive(event:client:)
                `

Delegate method for WebSocketDelegate.

Declaration

Swift

public func didReceive(event: WebSocketEvent, client _: WebSocket)

Parameters

| event |

WS Event

| | _ |

|