ARTWebSocketDelegate

Objective-C

@protocol ARTWebSocketDelegate <NSObject>

Swift

protocol ARTWebSocketDelegate : NSObjectProtocol

The ARTWebSocketDelegate protocol describes the methods that ARTWebSocket objects call on their delegates to handle status and messsage events.

This protocol was previously in the SocketRocket library and named ARTSRWebSocketDelegate; all documentation comments have been copied verbatim.

Receive Messages

  • Called when any message was received from a web socket. This method is suboptimal and might be deprecated in a future release.

    Declaration

    Objective-C

    - (void)webSocket:(nonnull id<ARTWebSocket>)webSocket
        didReceiveMessage:(nonnull id)message;

    Swift

    optional func webSocket(_ webSocket: any ARTWebSocket, didReceiveMessage message: Any)

    Parameters

    webSocket

    An ARTWebSocket object that received a message.

    message

    Received message. Either a String or NSData.

  • Called when a frame was received from a web socket.

    Declaration

    Objective-C

    - (void)webSocket:(nonnull id<ARTWebSocket>)webSocket
        didReceiveMessageWithString:(nonnull NSString *)string;

    Swift

    optional func webSocket(_ webSocket: any ARTWebSocket, didReceiveMessageWith string: String)

    Parameters

    webSocket

    An ARTWebSocket object that received a message.

    string

    Received text in a form of UTF-8 String.

  • Called when a frame was received from a web socket.

    Declaration

    Objective-C

    - (void)webSocket:(nonnull id<ARTWebSocket>)webSocket
        didReceiveMessageWithData:(nonnull NSData *)data;

    Swift

    optional func webSocket(_ webSocket: any ARTWebSocket, didReceiveMessageWith data: Data)

    Parameters

    webSocket

    An ARTWebSocket object that received a message.

    data

    Received data in a form of NSData.

Status & Connection

  • Called when a given web socket was open and authenticated.

    Declaration

    Objective-C

    - (void)webSocketDidOpen:(nonnull id<ARTWebSocket>)webSocket;

    Swift

    optional func webSocketDidOpen(_ webSocket: any ARTWebSocket)

    Parameters

    webSocket

    An ARTWebSocket object that was open.

  • Called when a given web socket encountered an error.

    Declaration

    Objective-C

    - (void)webSocket:(nonnull id<ARTWebSocket>)webSocket
        didFailWithError:(nonnull NSError *)error;

    Swift

    optional func webSocket(_ webSocket: any ARTWebSocket, didFailWithError error: any Error)

    Parameters

    webSocket

    An ARTWebSocket object that failed with an error.

    error

    An instance of NSError.

  • Called when a given web socket was closed.

    Declaration

    Objective-C

    - (void)webSocket:(nonnull id<ARTWebSocket>)webSocket
        didCloseWithCode:(NSInteger)code
                  reason:(nullable NSString *)reason
                wasClean:(BOOL)wasClean;

    Swift

    optional func webSocket(_ webSocket: any ARTWebSocket, didCloseWithCode code: Int, reason: String?, wasClean: Bool)

    Parameters

    webSocket

    An ARTWebSocket object that was closed.

    code

    Code reported by the server.

    reason

    Reason in a form of a String that was reported by the server or nil.

    wasClean

    Boolean value indicating whether a socket was closed in a clean state.

  • Called on receive of a ping message from the server.

    Declaration

    Objective-C

    - (void)webSocket:(nonnull id<ARTWebSocket>)webSocket
        didReceivePingWithData:(nullable NSData *)data;

    Swift

    optional func webSocket(_ webSocket: any ARTWebSocket, didReceivePingWith data: Data?)

    Parameters

    webSocket

    An ARTWebSocket object that received a ping frame.

    data

    Payload that was received or nil if there was no payload.

  • Called when a pong data was received in response to ping.

    Declaration

    Objective-C

    - (void)webSocket:(nonnull id<ARTWebSocket>)webSocket
        didReceivePong:(nullable NSData *)pongData;

    Swift

    optional func webSocket(_ webSocket: any ARTWebSocket, didReceivePong pongData: Data?)

    Parameters

    webSocket

    An ARTWebSocket object that received a pong frame.

    pongData

    Payload that was received or nil if there was no payload.

  • Sent before reporting a text frame to be able to configure if it shuold be convert to a UTF-8 String or passed as NSData. If the method is not implemented - it will always convert text frames to String.

    Declaration

    Objective-C

    - (BOOL)webSocketShouldConvertTextFrameToString:
        (nonnull id<ARTWebSocket>)webSocket;

    Swift

    optional func webSocketShouldConvertTextFrameToString(_ webSocket: any ARTWebSocket) -> Bool

    Parameters

    webSocket

    An ARTWebSocket object that received a text frame.

    Return Value

    YES if text frame should be converted to UTF-8 String, otherwise - NO. Default: YES.