OrtcClient

open class OrtcClient: NSObject, WebSocketDelegate

*Part of the The Realtime® Framework, Realtime Cloud Messaging (aka ORTC) is a secure, fast and highly scalable cloud-hosted Pub/Sub real-time message broker for web and mobile apps. * *If your website or mobile app has data that needs to be updated in the user’s interface as it changes (e.g. real-time stock quotes or ever changing social news feed) Realtime Cloud Messaging is the reliable, easy, unbelievably fast, “works everywhere” solution.

Example:

import RealtimeMessaging_iOS_Swift

class OrtcClass: NSObject, OrtcClientDelegate{
let APPKEY = "<INSERT_YOUR_APP_KEY>"
let TOKEN = "guest"
let METADATA = "swift example"
let URL = "https://ortc-developers.realtime.co/server/ssl/2.1/"
var ortc: OrtcClient?

func connect()
{
self.ortc = OrtcClient.ortcClientWithConfig(self)
self.ortc!.connectionMetadata = METADATA
self.ortc!.clusterUrl = URL
self.ortc!.connect(APPKEY, authenticationToken: TOKEN)
}

func onConnected(ortc: OrtcClient){
NSLog("CONNECTED")
ortc.subscribe("SOME_CHANNEL", subscribeOnReconnected: true, onMessage: { (ortcClient:OrtcClient!, channel:String!, message:String!) -> Void in
NSLog("Receive message: %@ on channel: %@", message!, channel!)
})
}

func onDisconnected(ortc: OrtcClient){
// Disconnected
}

func onSubscribed(ortc: OrtcClient, channel: String){
// Subscribed to the channel

// Send a message
ortc.send(channel, "Hello world!!!")
}

func onUnsubscribed(ortc: OrtcClient, channel: String){
// Unsubscribed from the channel 'channel'
}

func onException(ortc: OrtcClient, error: NSError){
// Exception occurred
}

func onReconnecting(ortc: OrtcClient){
// Reconnecting
}

func onReconnected(ortc: OrtcClient){
// Reconnected
}
}
  • Is the acount application key

    Declaration

    Swift

    open var applicationKey: String?
  • Is the authentication token for this client

    Declaration

    Swift

    open var authenticationToken: String?
  • Sets if client url is from cluster

    Declaration

    Swift

    open var isCluster: Bool? = true
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate
  • url

    Client url connection

    Declaration

    Swift

    open var url: NSString?
  • Client url connection

    Declaration

    Swift

    open var clusterUrl: NSString?
  • Client connection metadata

    Declaration

    Swift

    open var connectionMetadata: NSString?
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate
  • Initializes a new instance of the ORTC class.

    Declaration

    Swift

    open static func ortcClientWithConfig(_ delegate: OrtcClientDelegate) -> OrtcClient

    Parameters

    delegate

    The object holding the ORTC callbacks, usually ‘self’.

    Return Value

    New instance of the OrtcClient class.

  • Connects with the application key and authentication token.

    Declaration

    Swift

    open func connect(_ applicationKey:NSString?, authenticationToken:NSString?)

    Parameters

    applicationKey

    The application key.

    authenticationToken

    The authentication token.

  • Disconnects.

    Declaration

    Swift

    open func disconnect()
  • Publish a message to a channel.

    Declaration

    Swift

    open func publish(_ channel:NSString, message:NSString, ttl:NSNumber, callback:@escaping (_ error:NSError?,_ seqId:NSString?)->Void)

    Parameters

    channel

    The channel name.

    message

    The message to publish.

    ttl

    The message expiration time in seconds (0 for maximum allowed ttl).

    callback

    Returns error if message publish was not successful or published message unique id (seqId) if sucessfully published

  • Sends a message to a channel.

    Declaration

    Swift

    open func send(_ channel:NSString, message:NSString)

    Parameters

    channel

    The channel name.

    message

    The message to send.

  • Subscribes to a channel to receive messages sent to it.

    Declaration

    Swift

    open func subscribe(_ channel:String, subscribeOnReconnected:Bool, onMessage:@escaping (_ ortc:OrtcClient, _ channel:String, _ message:String)->Void)

    Parameters

    channel

    The channel name.

    subscribeOnReconnected

    Indicates whether the client should subscribe to the channel when reconnected (if it was previously subscribed when connected).

    onMessage

    The callback called when a message arrives at the channel.

  • Subscribes to a channel to receive messages sent to it with given options.

    Options dictionary example:

            var options:[String : Any] = ["channel":channel,
                                            "subscribeOnReconnected":true,
                                            "subscriberId":subscriberId]
    
            self.subscribeWithOptions(options as NSDictionary?) { (client, dictionary) in
               //your code
            }
    

    Declaration

    Swift

    open func subscribeWithOptions(_ options:NSDictionary? ,onMessageWithOptionsCallback:@escaping (_ ortc:OrtcClient, _ msgOptions:NSDictionary)->Void)

    Parameters

    options

    The subscription options dictionary,
    options = {
         channel,
         subscribeOnReconnected, // optional, default = true
         withNotifications (Bool), // optional, default = false, push notifications as in subscribeWithNotifications
         filter, // optional, default = “”, the subscription filter as in subscribeWithFilter
         subscriberId // optional, default = “”, the subscriberId as in subscribeWithBuffer
    }

    onMessageWithOptionsCallback

    The callback called when a message arrives at the channel, data is provided in a dictionary.

  • Subscribes to a channel to receive messages published to it.

    Declaration

    Swift

    open func subscribeWithBuffer(channel:String, subscriberId:String, onMessageWithBufferCallback:@escaping (_ ortc:OrtcClient, _ channel:String, _ seqId:String, _ message:String)->Void)

    Parameters

    channel

    The channel name.

    subscriberId

    The subscriberId associated to the channel.

    onMessageWithBufferCallback

    The callback called when a message arrives at the channel and message seqId number.

  • Subscribes to a channel to receive messages sent to it.

    Declaration

    Swift

    open func subscribeWithFilter(_ channel:String, subscribeOnReconnected:Bool, filter:String ,onMessageWithFilter:@escaping (_ ortc:OrtcClient, _ channel:String, _ filtered:Bool, _ message:String)->Void)

    Parameters

    channel

    The channel name.

    subscribeOnReconnected

    Indicates whether the client should subscribe to the channel when reconnected (if it was previously subscribed when connected).

    filter

    The filter to apply to the channel messages.

    onMessageWithFilter

    The callback called when a message arrives at the channel.

  • Subscribes to a channel, with Push Notifications Service, to receive messages sent to it.

    Declaration

    Swift

    open func subscribeWithNotifications(_ channel:String, subscribeOnReconnected:Bool, onMessage:@escaping (_ ortc:OrtcClient, _ channel:String, _ message:String)->Void)

    Parameters

    channel

    The channel name. Only channels with alphanumeric name and the following characters: “_” “-” “:” are allowed.

    subscribeOnReconnected

    Indicates whether the client should subscribe to the channel when reconnected (if it was previously subscribed when connected).

    onMessage

    The callback called when a message or a Push Notification arrives at the channel.

  • Unsubscribes from a channel to stop receiving messages sent to it.

    Declaration

    Swift

    open func unsubscribe(_ channel:String)

    Parameters

    channel

    The channel name.

  • Indicates whether is subscribed to a channel or not.

    Declaration

    Swift

    open func isSubscribed(_ channel:String) -> NSNumber?

    Parameters

    channel

    The channel name.

    Return Value

    TRUE if subscribed to the channel or FALSE if not.

  • Saves the channels and its permissions for the authentication token in the ORTC server. @warning This function will send your private key over the internet. Make sure to use secure connection. - parameter url: ORTC server URL. - parameter isCluster: Indicates whether the ORTC server is in a cluster. - parameter authenticationToken: The authentication token generated by an application server (for instance: a unique session ID). - parameter authenticationTokenIsPrivate: Indicates whether the authentication token is private (1) or not (0). - parameter applicationKey: The application key provided together with the ORTC service purchasing. - parameter timeToLive: The authentication token time to live (TTL), in other words, the allowed activity time (in seconds). - parameter privateKey: The private key provided together with the ORTC service purchasing. - parameter permissions: The channels and their permissions (w: write, r: read, p: presence, case sensitive). - return: TRUE if the authentication was successful or FALSE if it was not.

    Declaration

    Swift

    open func saveAuthentication(_ aUrl:String,
                                     isCluster:Bool,
                                     authenticationToken:String,
                                     authenticationTokenIsPrivate:Bool,
                                     applicationKey:String,
                                     timeToLive:Int,
                                     privateKey:String,
                                     permissions:NSMutableDictionary?)->Bool
  • Enables presence for the specified channel with first 100 unique metadata if true.

    @warning This function will send your private key over the internet. Make sure to use secure connection. - parameter url: Server containing the presence service. - parameter isCluster: Specifies if url is cluster. - parameter applicationKey: Application key with access to presence service. - parameter privateKey: The private key provided when the ORTC service is purchased. - parameter channel: Channel with presence data active. - parameter metadata: Defines if to collect first 100 unique metadata. - parameter callback: Callback with error (NSError) and result (NSString) parameters

    Declaration

    Swift

    open func enablePresence(_ aUrl:String, isCluster:Bool,
                                 applicationKey:String,
                                 privateKey:String,
                                 channel:String,
                                 metadata:Bool,
                                 callback:@escaping (_ error:NSError?, _ result:NSString?)->Void)
  • Disables presence for the specified channel.

    @warning This function will send your private key over the internet. Make sure to use secure connection. - parameter url: Server containing the presence service. - parameter isCluster: Specifies if url is cluster. - parameter applicationKey: Application key with access to presence service. - parameter privateKey: The private key provided when the ORTC service is purchased. - parameter channel: Channel with presence data active. - parameter callback: Callback with error (NSError) and result (NSString) parameters

    Declaration

    Swift

    open func disablePresence(_ aUrl:String,
                                  isCluster:Bool,
                                  applicationKey:String,
                                  privateKey:String,
                                  channel:String,
                                  callback:@escaping (_ error:NSError?, _ result:NSString?)->Void)
  • Gets a NSDictionary indicating the subscriptions in the specified channel and if active the first 100 unique metadata.

    Declaration

    Swift

    open func presence(_ aUrl:String,
                           isCluster:Bool,
                           applicationKey:String,
                           authenticationToken:String,
                           channel:String,
                           callback:@escaping (_ error:NSError?, _ result:NSDictionary?)->Void)

    Parameters

    url

    Server containing the presence service.

    isCluster

    Specifies if url is cluster.

    applicationKey

    Application key with access to presence service.

    authenticationToken

    Authentication token with access to presence service.

    channel

    Channel with presence data active.

    callback

    Callback with error (NSError) and result (NSDictionary) parameters

  • Sets publish timeout. - parameter timeout: publish messages timeout.

    Declaration

    Swift

    open func setPublishTimeout(_ timeout:Double)

    Parameters

    timeout

    publish messages timeout.

  • Returns publishTimeout: publish timeout.

    Declaration

    Swift

    open func getPublishTimeout() -> Double
  • Get heartbeat interval.

    Declaration

    Swift

    open func getHeartbeatTime()->Int?
  • Set heartbeat interval.

    Declaration

    Swift

    open func setHeartbeatTime(_ time:Int)
  • Get how many times can the client fail the heartbeat.

    Declaration

    Swift

    open func getHeartbeatFails()->Int?
  • Set heartbeat fails. Defines how many times can the client fail the heartbeat.

    Declaration

    Swift

    open func setHeartbeatFails(_ time:Int)
  • Indicates whether heartbeat is active or not.

    Declaration

    Swift

    open func isHeartbeatActive()->Bool
  • Enables the client heartbeat

    Declaration

    Swift

    open func enableHeartbeat()
  • Disables the client heartbeat

    Declaration

    Swift

    open func disableHeartbeat()
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate
  • Undocumented

    Declaration

    Swift

    open class OrtcClient: NSObject, WebSocketDelegate