docs/Protocols/SocketManagerSpec.html
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
`
defaultSocket
`
Returns the socket associated with the default namespace (“/”).
Swift
var defaultSocket: SocketIOClient { get }
`
engine
`
The engine for this manager.
Swift
var engine: SocketEngineSpec? { get set }
`
forceNew
`
If true then every time connect is called, a new engine will be created.
Swift
var forceNew: Bool { get set }
`
handleQueue
`
The queue that all interaction with the client should occur on. This is the queue that event handlers are called on.
Swift
var handleQueue: DispatchQueue { get set }
`
nsps
`
The sockets in this manager indexed by namespace.
Swift
var nsps: [String : SocketIOClient] { get set }
`
reconnects
`
If true, this manager will try and reconnect on any disconnects.
Swift
var reconnects: Bool { get set }
`
reconnectWait
`
The minimum number of seconds to wait before attempting to reconnect.
Swift
var reconnectWait: Int { get set }
`
reconnectWaitMax
`
The maximum number of seconds to wait before attempting to reconnect.
Swift
var reconnectWaitMax: Int { get set }
`
randomizationFactor
`
The randomization factor for calculating reconnect jitter.
Swift
var randomizationFactor: Double { get set }
`
socketURL
`
The URL of the socket.io server.
Swift
var socketURL: URL { get }
`
status
`
The status of this manager.
Swift
var status: SocketIOStatus { get }
`
version
`
The version of socket.io in use.
Swift
var version: SocketIOVersion { get }
Methods
`
connect()
`
Connects the underlying transport.
Swift
func connect()
`
connectSocket(_:withPayload:)
`
Connects a socket through this manager’s engine.
Swift
func connectSocket(_ socket: SocketIOClient, withPayload: [String : Any]?)
| socket |
The socket who we should connect through this manager.
|
| withPayload |
Optional payload to send on connect
|
`
didDisconnect(reason:)
`
Called when the manager has disconnected from socket.io.
Swift
func didDisconnect(reason: String)
| reason |
The reason for the disconnection.
|
`
disconnect()
`
Disconnects the manager and all associated sockets.
Swift
func disconnect()
`
disconnectSocket(_:)
`
Disconnects the given socket.
Swift
func disconnectSocket(_ socket: SocketIOClient)
| socket |
The socket to disconnect.
|
`
disconnectSocket(forNamespace:)
`
Disconnects the socket associated with forNamespace.
Swift
func disconnectSocket(forNamespace nsp: String)
| nsp |
The namespace to disconnect from.
|
`
emitAll(_:_:)
`
Sends an event to the server on all namespaces in this manager.
Swift
func emitAll(_ event: String, _ items: SocketData...)
| event |
The event to send.
|
| items |
The data to send with this event.
|
`
reconnect()
`
Tries to reconnect to the server.
This will cause a disconnect event to be emitted, as well as an reconnectAttempt event.
Swift
func reconnect()
`
removeSocket(_:)
`
Removes the socket from the manager’s control. After calling this method the socket should no longer be considered usable.
Swift
@discardableResult
func removeSocket(_ socket: SocketIOClient) -> SocketIOClient?
| socket |
The socket to remove.
|
The socket removed, if it was owned by the manager.
`
socket(forNamespace:)
`
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.
Swift
func socket(forNamespace nsp: String) -> SocketIOClient
| nsp |
The namespace for the socket.
|
A SocketIOClient for the given namespace.