WebSocketConnectionDelegate
public protocol WebSocketConnectionDelegate : AnyObject
Defines a delegate for a WebSocket connection.
-
Tells the delegate that the WebSocket did connect successfully.
Declaration
Swift
func webSocketDidConnect(connection: WebSocketConnection)Parameters
connectionThe active
WebSocketConnection. -
Tells the delegate that the WebSocket did disconnect.
Declaration
Swift
func webSocketDidDisconnect(connection: WebSocketConnection, closeCode: NWProtocolWebSocket.CloseCode, reason: Data?)Parameters
connectionThe
WebSocketConnectionthat disconnected.closeCodeA
NWProtocolWebSocket.CloseCodedescribing how the connection closed.reasonOptional extra information explaining the disconnection. (Formatted as UTF-8 encoded
Data). -
Tells the delegate that the WebSocket connection viability has changed.
An example scenario of when this method would be called is a Wi-Fi connection being lost due to a device moving out of signal range, and then the method would be called again once the device moved back in range.
Declaration
Swift
func webSocketViabilityDidChange(connection: WebSocketConnection, isViable: Bool)Parameters
connectionThe
WebSocketConnectionwhose viability has changed.isViableA
Boolindicating if the connection is viable or not. -
Tells the delegate that the WebSocket has attempted a migration based on a better network path becoming available.
An example of when this method would be called is if a device is using a cellular connection, and a Wi-Fi connection becomes available. This method will also be called if a device loses a Wi-Fi connection, and a cellular connection is available.
Declaration
Swift
func webSocketDidAttemptBetterPathMigration(result: Result<WebSocketConnection, NWError>)Parameters
resultA
Resultcontaining theWebSocketConnectionif the migration was successful, or aNWErrorif the migration failed for some reason. -
Tells the delegate that the WebSocket received an error.
An error received by a WebSocket is not necessarily fatal.
Declaration
Swift
func webSocketDidReceiveError(connection: WebSocketConnection, error: NWError)Parameters
connectionThe
WebSocketConnectionthat received an error.errorThe
NWErrorthat was received. -
Tells the delegate that the WebSocket received a ‘pong’ from the server.
Declaration
Swift
func webSocketDidReceivePong(connection: WebSocketConnection)Parameters
connectionThe active
WebSocketConnection. -
Tells the delegate that the WebSocket received a
Stringmessage.Declaration
Swift
func webSocketDidReceiveMessage(connection: WebSocketConnection, string: String)Parameters
connectionThe active
WebSocketConnection.stringThe UTF-8 formatted
Stringthat was received. -
Tells the delegate that the WebSocket received a binary
Datamessage.Declaration
Swift
func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data)Parameters
connectionThe active
WebSocketConnection.dataThe
Datathat was received.
View on GitHub
WebSocketConnectionDelegate Protocol Reference