SocketManagerSpec

public protocol SocketManagerSpec : AnyObject, SocketEngineClient

A manager for a socket.io connection.

A SocketManagerSpec is responsible for multiplexing multiple namespaces through a single SocketEngineSpec.

Example with SocketManager:

let manager = SocketManager(socketURL: URL(string:"http://localhost:8080/")!)
let defaultNamespaceSocket = manager.defaultSocket
let swiftSocket = manager.socket(forNamespace: "/swift")

// defaultNamespaceSocket and swiftSocket both share a single connection to the server

Sockets created through the manager are retained by the manager. So at the very least, a single strong reference to the manager must be maintained to keep sockets alive.

To disconnect a socket and remove it from the manager, either call SocketIOClient.disconnect() on the socket, or call one of the disconnectSocket methods on this class.

Properties

  • Returns the socket associated with the default namespace (“/”).

    Declaration

    Swift

    var defaultSocket: SocketIOClient { get }
  • The engine for this manager.

    Declaration

    Swift

    var engine: SocketEngineSpec? { get set }
  • If true then every time connect is called, a new engine will be created.

    Declaration

    Swift

    var forceNew: Bool { get set }
  • The queue that all interaction with the client should occur on. This is the queue that event handlers are called on.

    Declaration

    Swift

    var handleQueue: DispatchQueue { get set }
  • The sockets in this manager indexed by namespace.

    Declaration

    Swift

    var nsps: [String : SocketIOClient] { get set }
  • If true, this manager will try and reconnect on any disconnects.

    Declaration

    Swift

    var reconnects: Bool { get set }
  • The minimum number of seconds to wait before attempting to reconnect.

    Declaration

    Swift

    var reconnectWait: Int { get set }
  • The maximum number of seconds to wait before attempting to reconnect.

    Declaration

    Swift

    var reconnectWaitMax: Int { get set }
  • The randomization factor for calculating reconnect jitter.

    Declaration

    Swift

    var randomizationFactor: Double { get set }
  • The URL of the socket.io server.

    Declaration

    Swift

    var socketURL: URL { get }
  • The status of this manager.

    Declaration

    Swift

    var status: SocketIOStatus { get }
  • The version of socket.io in use.

    Declaration

    Swift

    var version: SocketIOVersion { get }

Methods

  • Connects the underlying transport.

    Declaration

    Swift

    func connect()
  • Connects a socket through this manager’s engine.

    Declaration

    Swift

    func connectSocket(_ socket: SocketIOClient, withPayload: [String : Any]?)

    Parameters

    socket

    The socket who we should connect through this manager.

    withPayload

    Optional payload to send on connect

  • Called when the manager has disconnected from socket.io.

    Declaration

    Swift

    func didDisconnect(reason: String)

    Parameters

    reason

    The reason for the disconnection.

  • Disconnects the manager and all associated sockets.

    Declaration

    Swift

    func disconnect()
  • Disconnects the given socket.

    Declaration

    Swift

    func disconnectSocket(_ socket: SocketIOClient)

    Parameters

    socket

    The socket to disconnect.

  • Disconnects the socket associated with forNamespace.

    Declaration

    Swift

    func disconnectSocket(forNamespace nsp: String)

    Parameters

    nsp

    The namespace to disconnect from.

  • Sends an event to the server on all namespaces in this manager.

    Declaration

    Swift

    func emitAll(_ event: String, _ items: SocketData...)

    Parameters

    event

    The event to send.

    items

    The data to send with this event.

  • Tries to reconnect to the server.

    This will cause a disconnect event to be emitted, as well as an reconnectAttempt event.

    Declaration

    Swift

    func reconnect()
  • Removes the socket from the manager’s control. After calling this method the socket should no longer be considered usable.

    Declaration

    Swift

    @discardableResult
    func removeSocket(_ socket: SocketIOClient) -> SocketIOClient?

    Parameters

    socket

    The socket to remove.

    Return Value

    The socket removed, if it was owned by the manager.

  • Returns a SocketIOClient for the given namespace. This socket shares a transport with the manager.

    Calling multiple times returns the same socket.

    Sockets created from this method are retained by the manager. Call one of the disconnectSocket methods on the implementing class to remove the socket from manager control. Or call SocketIOClient.disconnect() on the client.

    Declaration

    Swift

    func socket(forNamespace nsp: String) -> SocketIOClient

    Parameters

    nsp

    The namespace for the socket.

    Return Value

    A SocketIOClient for the given namespace.