ARTSRWebSocket
Objective-C
@interface ARTSRWebSocket : NSObject <ARTWebSocket, NSStreamDelegate>
Swift
class ARTSRWebSocket : NSObject, ARTWebSocket, StreamDelegate
A ARTSRWebSocket object lets you connect, send and receive data to a remote Web Socket.
-
The delegate of the web socket.
The web socket delegate is notified on all state changes that happen to the web socket.
Declaration
Objective-C
@property (nonatomic, weak) id<ARTWebSocketDelegate> _Nullable delegate;Swift
weak var delegate: (any ARTWebSocketDelegate)? { get set } -
A dispatch queue for scheduling the delegate calls. The queue doesn’t need be a serial queue.
If
nilanddelegateOperationQueueisnil, the socket uses main queue for performing all delegate method calls.Declaration
Objective-C
@property (nonatomic, nullable) dispatch_queue_t delegateDispatchQueue;Swift
var delegateDispatchQueue: dispatch_queue_t? { get set } -
An operation queue for scheduling the delegate calls.
If
nilanddelegateOperationQueueisnil, the socket uses main queue for performing all delegate method calls.Declaration
Objective-C
@property (nonatomic, nullable) NSOperationQueue *delegateOperationQueue;Swift
var delegateOperationQueue: OperationQueue? { get set } -
Current ready state of the socket. Default:
ARTWebSocketReadyStateConnecting.This property is Key-Value Observable and fully thread-safe.
Declaration
Objective-C
@property (readonly) ARTWebSocketReadyState readyState;Swift
var readyState: ARTWebSocketReadyState { get } -
An instance of
NSURLthat this socket connects to.Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSURL *url;Swift
var url: URL? { get } -
All HTTP headers that were received by socket or
nilif none were received so far.Declaration
Objective-C
@property (nonatomic, readonly, nullable) CFHTTPMessageRef receivedHTTPHeaders;Swift
var receivedHTTPHeaders: CFHTTPMessage? { get } -
Array of
NSHTTPCookiecookies to apply to the connection.Declaration
Objective-C
@property (nonatomic, copy, nullable) NSArray<NSHTTPCookie *> *requestCookies;Swift
var requestCookies: [HTTPCookie]? { get set } -
The negotiated web socket protocol or
nilif handshake did not yet complete.Declaration
Objective-C
@property (nonatomic, copy, readonly, nullable) NSString *protocol;Swift
var `protocol`: String? { get } -
A boolean value indicating whether this socket will allow connection without SSL trust chain evaluation. For DEBUG builds this flag is ignored, and SSL connections are allowed regardless of the certificate trust configuration
Declaration
Objective-C
@property (nonatomic, readonly) BOOL allowsUntrustedSSLCertificates;Swift
var allowsUntrustedSSLCertificates: Bool { get }
-
Initializes a web socket with a given
NSURLRequest.Declaration
Objective-C
- (nonnull instancetype)initWithURLRequest:(nonnull NSURLRequest *)request logger:(nullable ARTInternalLog *)logger;Swift
convenience init(urlRequest request: URLRequest, logger: InternalLog?)Parameters
requestRequest to initialize with.
-
Initializes a web socket with a given
NSURLRequest, specifying a transport security policy (e.g. SSL configuration).Declaration
Objective-C
- (nonnull instancetype)initWithURLRequest:(nonnull NSURLRequest *)request securityPolicy: (nonnull ARTSRSecurityPolicy *)securityPolicy logger:(nullable ARTInternalLog *)logger;Swift
convenience init(urlRequest request: URLRequest, securityPolicy: ARTSRSecurityPolicy, logger: InternalLog?)Parameters
requestRequest to initialize with.
securityPolicyPolicy object describing transport security behavior.
-
Initializes a web socket with a given
NSURLRequestand list of sub-protocols.Declaration
Objective-C
- (nonnull instancetype)initWithURLRequest:(nonnull NSURLRequest *)request protocols: (nullable NSArray<NSString *> *)protocols logger:(nullable ARTInternalLog *)logger;Swift
convenience init(urlRequest request: URLRequest, protocols: [String]?, logger: InternalLog?)Parameters
requestRequest to initialize with.
protocolsAn array of strings that turn into
Sec-WebSocket-Protocol. Default:nil. -
Deprecated
Disabling certificate chain validation is unsafe. Please use a proper Certificate Authority to issue your TLS certificates.
Initializes a web socket with a given
NSURLRequest, list of sub-protocols and whether untrusted SSL certificates are allowed.Declaration
Objective-C
- (nonnull instancetype)initWithURLRequest:(nonnull NSURLRequest *)request protocols: (nullable NSArray<NSString *> *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates logger:(nullable ARTInternalLog *)logger;Swift
convenience init(urlRequest request: URLRequest, protocols: [String]?, allowsUntrustedSSLCertificates: Bool, logger: InternalLog?)Parameters
requestRequest to initialize with.
protocolsAn array of strings that turn into
Sec-WebSocket-Protocol. Default:nil.allowsUntrustedSSLCertificatesBoolean value indicating whether untrusted SSL certificates are allowed. Default:
false. -
Initializes a web socket with a given
NSURLRequest, list of sub-protocols and whether untrusted SSL certificates are allowed.Declaration
Objective-C
- (nonnull instancetype) initWithURLRequest:(nonnull NSURLRequest *)request protocols:(nullable NSArray<NSString *> *)protocols securityPolicy:(nonnull ARTSRSecurityPolicy *)securityPolicy logger:(nullable ARTInternalLog *)logger;Swift
init(urlRequest request: URLRequest, protocols: [String]?, securityPolicy: ARTSRSecurityPolicy, logger: InternalLog?)Parameters
requestRequest to initialize with.
protocolsAn array of strings that turn into
Sec-WebSocket-Protocol. Default:nil.securityPolicyPolicy object describing transport security behavior.
-
Initializes a web socket with a given
NSURL.Declaration
Objective-C
- (nonnull instancetype)initWithURL:(nonnull NSURL *)url logger:(nullable ARTInternalLog *)logger;Swift
convenience init(url: URL, logger: InternalLog?)Parameters
urlURL to initialize with.
-
Initializes a web socket with a given
NSURLand list of sub-protocols.Declaration
Objective-C
- (nonnull instancetype)initWithURL:(nonnull NSURL *)url protocols:(nullable NSArray<NSString *> *)protocols logger:(nullable ARTInternalLog *)logger;Swift
convenience init(url: URL, protocols: [String]?, logger: InternalLog?)Parameters
urlURL to initialize with.
protocolsAn array of strings that turn into
Sec-WebSocket-Protocol. Default:nil. -
Initializes a web socket with a given
NSURL, specifying a transport security policy (e.g. SSL configuration).Declaration
Objective-C
- (nonnull instancetype)initWithURL:(nonnull NSURL *)url securityPolicy: (nonnull ARTSRSecurityPolicy *)securityPolicy logger:(nullable ARTInternalLog *)logger;Swift
convenience init(url: URL, securityPolicy: ARTSRSecurityPolicy, logger: InternalLog?)Parameters
urlURL to initialize with.
securityPolicyPolicy object describing transport security behavior.
-
Deprecated
Disabling certificate chain validation is unsafe. Please use a proper Certificate Authority to issue your TLS certificates.
Initializes a web socket with a given
NSURL, list of sub-protocols and whether untrusted SSL certificates are allowed.Declaration
Objective-C
- (nonnull instancetype)initWithURL:(nonnull NSURL *)url protocols:(nullable NSArray<NSString *> *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates logger:(nullable ARTInternalLog *)logger;Swift
convenience init(url: URL, protocols: [String]?, allowsUntrustedSSLCertificates: Bool, logger: InternalLog?)Parameters
urlURL to initialize with.
protocolsAn array of strings that turn into
Sec-WebSocket-Protocol. Default:nil.allowsUntrustedSSLCertificatesBoolean value indicating whether untrusted SSL certificates are allowed. Default:
false. -
Unavailable
Unavailable initializer. Please use any other initializer.
Declaration
Objective-C
- (nonnull instancetype)init; -
Unavailable
Unavailable constructor. Please use any other initializer.
Declaration
Objective-C
+ (nonnull instancetype)new;
-
Schedules a received on a given run loop in a given mode. By default, a web socket will schedule itself on
+[NSRunLoop ARTSR_networkRunLoop]usingNSDefaultRunLoopMode.Declaration
Objective-C
- (void)scheduleInRunLoop:(nonnull NSRunLoop *)runLoop forMode:(nonnull NSString *)mode;Swift
func schedule(in runLoop: RunLoop, forMode mode: String)Parameters
runLoopThe run loop on which to schedule the receiver.
modeThe mode for the run loop.
-
Removes the receiver from a given run loop running in a given mode.
Declaration
Objective-C
- (void)unscheduleFromRunLoop:(nonnull NSRunLoop *)runLoop forMode:(nonnull NSString *)mode;Swift
func unschedule(from runLoop: RunLoop, forMode mode: String)Parameters
runLoopThe run loop on which the receiver was scheduled.
modeThe mode for the run loop.
-
Opens web socket, which will trigger connection, authentication and start receiving/sending events. An instance of
ARTSRWebSocketis intended for one-time-use only. This method should be called once and only once.Declaration
Objective-C
- (void)open;Swift
func open() -
Closes a web socket using
ARTSRStatusCodeNormalcode and no reason.Declaration
Objective-C
- (void)close;Swift
func close() -
Closes a web socket using a given code and reason.
Declaration
Objective-C
- (void)closeWithCode:(NSInteger)code reason:(nullable NSString *)reason;Swift
func close(withCode code: Int, reason: String?)Parameters
codeCode to close the socket with.
reasonReason to send to the server or
nil.
-
Send a UTF-8 string or binary data to the server.
Declaration
Objective-C
- (void)send:(nullable id)message;Swift
func send(_ message: Any?)Parameters
messageUTF-8 String or Data to send.
-
Send a UTF-8 String to the server.
Declaration
Objective-C
- (BOOL)sendString:(nonnull NSString *)string error:(NSError *_Nullable *_Nullable)error;Swift
func send(string: String) throwsParameters
stringString to send.
errorOn input, a pointer to variable for an
NSErrorobject. If an error occurs, this pointer is set to anNSErrorobject containing information about the error. You may specifynilto ignore the error information.Return Value
YESif the string was scheduled to send, otherwise -NO. -
Send binary data to the server.
Declaration
Objective-C
- (BOOL)sendData:(nullable NSData *)data error:(NSError *_Nullable *_Nullable)error;Swift
func send(data: Data?) throwsParameters
dataData to send.
errorOn input, a pointer to variable for an
NSErrorobject. If an error occurs, this pointer is set to anNSErrorobject containing information about the error. You may specifynilto ignore the error information.Return Value
YESif the string was scheduled to send, otherwise -NO. -
Send binary data to the server, without making a defensive copy of it first.
Declaration
Objective-C
- (BOOL)sendDataNoCopy:(nullable NSData *)data error:(NSError *_Nullable *_Nullable)error;Swift
func send(dataNoCopy data: Data?) throwsParameters
dataData to send.
errorOn input, a pointer to variable for an
NSErrorobject. If an error occurs, this pointer is set to anNSErrorobject containing information about the error. You may specifynilto ignore the error information.Return Value
YESif the string was scheduled to send, otherwise -NO. -
Send Ping message to the server with optional data.
Declaration
Objective-C
- (BOOL)sendPing:(nullable NSData *)data error:(NSError *_Nullable *_Nullable)error;Swift
func sendPing(_ data: Data?) throwsParameters
dataInstance of
NSDataornil.errorOn input, a pointer to variable for an
NSErrorobject. If an error occurs, this pointer is set to anNSErrorobject containing information about the error. You may specifynilto ignore the error information.Return Value
YESif the string was scheduled to send, otherwise -NO.