SocketManagerSpec
public protocol SocketManagerSpec : class, 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.
-
Returns the socket associated with the default namespace (
/
).Declaration
Swift
var defaultSocket: SocketIOClient
-
The engine for this manager.
Declaration
Swift
var engine: SocketEngineSpec?
-
If
true
then every timeconnect
is called, a new engine will be created.Declaration
Swift
var forceNew: Bool
-
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
-
The sockets in this manager indexed by namespace.
Declaration
Swift
var nsps: [String: SocketIOClient]
-
If
true
, this manager will try and reconnect on any disconnects.Declaration
Swift
var reconnects: Bool
-
The number of seconds to wait before attempting to reconnect.
Declaration
Swift
var reconnectWait: Int
-
The URL of the socket.io server.
Declaration
Swift
var socketURL: URL
-
The status of this manager.
Declaration
Swift
var status: SocketIOStatus
-
Connects the underlying transport.
Declaration
Swift
func connect()
-
Connects a socket through this manager’s engine.
Declaration
Swift
func connectSocket(_ socket: SocketIOClient)
Parameters
socket
The socket who we should connect through this manager.
-
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
forNamespace
The namespace to disconnect from.
-
Sends an event to the server on all namespaces in this manager.
Declaration
Swift
func emitAll(_ event: String, withItems items: [Any])
Parameters
event
The event to send.
withItems
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 anreconnectAttempt
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
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 callSocketIOClient.disconnect()
on the client.Declaration
Swift
func socket(forNamespace nsp: String) -> SocketIOClient
Parameters
forNamespace
The namespace for the socket.
Return Value
A
SocketIOClient
for the given namespace.