Phoenix
public class Phoenix : NSObject, WebSocketDelegate
The Phoenix
class provides a convenient mechanism to communicate with Phoenix Framework Channels.
Seealso
Phoenix Framework Overview-
The WebSocket URL.
Declaration
Swift
public let url: String
-
The parameters, that will be added into the URL.
Declaration
Swift
public let urlParameters: [String : String]?
-
The response timeout (in seconds). The default value is 10 seconds.
Declaration
Swift
public var responseTimeout: Int
-
The heartbeat interval (in seconds). The default value is 20 seconds.
Declaration
Swift
public var heartbeatInterval: Int
-
A Boolean value that indicates a need of auto reconnections.
Declaration
Swift
public var autoReconnect: Bool
-
The auto reconnection delay intervals (in seconds). The first try, second, third and so on. The default value is 3, 3, 3, 3, 3, 3, 3, 3, 3, 3.
Declaration
Swift
public var autoReconnectIntervals: [Int]
-
A Boolean value that indicates a connection status.
Declaration
Swift
public var isConnected: Bool { get }
-
The queue will be used to call listeners methods.
Declaration
Swift
public var listenerQueue: DispatchQueue
-
The queue will be used to call send’s responses.
Declaration
Swift
public var responseQueue: DispatchQueue
-
Creates the
Phoenix
object.Declaration
Swift
public init(url: String, urlParameters: [String: String]? = nil)
Parameters
url
The URL of the WebSocket.
urlParameters
The parameters, that will be URL encoded and added into the URL.
Return Value
The
Phoenix
instance.
-
Connects
Phoenix
.Declaration
Swift
@objc public func connect()
-
Disconnects
Phoenix
. IfautoReconnect
is true, it will be set to false.Declaration
Swift
public func disconnect()
-
Joins the channel with specified topic.
Declaration
Swift
public func join(topic: String)
Parameters
topic
The channel topic.
-
Adds a message to the sending queue.
Declaration
Swift
public func send(_ message: PhoenixMessage, responseHandler: ((_ response: PhoenixMessage, _ error: Error?) -> Void)? = nil)
Parameters
message
The message to send.
responseHandler
The closure, which is called after message sending and receiving a response from the server. It will be executed in the
listenerQueue
.
-
Adds a listener object for the specified channel topic and event. Listener methods will be executed in the
listenerQueue
.Declaration
Swift
public func addListener(listener: PhoenixListener, forChannel topic: String, event: String? = nil)
Parameters
listener
The listener.
topic
The channel topic.
event
The event name. If is
nil
, then all events of the channel. -
Removes the listener object for the specified channel topic and event.
Declaration
Swift
public func removeListener(listener: PhoenixListener, forChannel topic: String, event: String? = nil)
Parameters
listener
The listener.
topic
The channel topic.
event
The event name;
nil
means all events of the channel.