Skip navigation links
ibt.ortc.extensibility

Class OrtcClient

    • Field Detail

      • MAX_CONNECTION_METADATA_SIZE

        public static final int MAX_CONNECTION_METADATA_SIZE
        See Also:
        Constant Field Values
      • CONNECTION_TIMEOUT_DEFAULT_VALUE

        protected static final int CONNECTION_TIMEOUT_DEFAULT_VALUE
        See Also:
        Constant Field Values
      • onConnected

        public OnConnected onConnected
        Event fired when a connection is established
      • onDisconnected

        public OnDisconnected onDisconnected
        Event fired when a connection is closed
      • onException

        public OnException onException
        Event fired when a exception occurs
      • onReconnected

        public OnReconnected onReconnected
        Event fired when a connection is reestablished after being closed unexpectedly
      • onReconnecting

        public OnReconnecting onReconnecting
        Event fired when a connection is trying to be reestablished after being closed unexpectedly
      • onSubscribed

        public OnSubscribed onSubscribed
        Event fired when a channel is subscribed
      • onUnsubscribed

        public OnUnsubscribed onUnsubscribed
        Event fired when a channel is unsubscribed
      • clusterUrl

        protected String clusterUrl
      • connectionMetadata

        protected String connectionMetadata
      • announcementSubChannel

        protected String announcementSubChannel
      • applicationKey

        protected String applicationKey
      • authenticationToken

        protected String authenticationToken
      • uri

        protected URI uri
      • connectionTimeout

        protected int connectionTimeout
      • id

        protected int id
      • isConnected

        protected boolean isConnected
      • isDisconnecting

        protected boolean isDisconnecting
      • isReconnecting

        protected boolean isReconnecting
      • isConnecting

        protected boolean isConnecting
      • proxy

        protected Proxy proxy
      • heartbeatActive

        protected boolean heartbeatActive
      • heartbeatFails

        protected int heartbeatFails
      • heartbeatTime

        protected int heartbeatTime
      • pendingPublishMessages

        protected HashMap pendingPublishMessages
    • Constructor Detail

      • OrtcClient

        public OrtcClient()
        Creates an instance of Ortc Client
    • Method Detail

      • connect

        public void connect(String applicationKey,
                            String authenticationToken)
        Connects the ortc client to the url previously specified
         client.setClusterUrl(defaultServerUrl);
         client.connect("APPKEY", "PVTKEY");
         
        Parameters:
        applicationKey - Application Key provided by the Ortc Services
        authenticationToken - Authentication Token representing the connection. This should be generated by the application, such as session id for example.
      • connect

        protected abstract void connect()
      • disconnect

        public void disconnect()
        Closes the current connection
      • disconnectIntern

        protected abstract void disconnectIntern()
      • send

        public void send(String channel,
                         String message)
        Sends a message to the specified channel.
        Parameters:
        channel - Channel to wich the message should be sent
        message - The content of the message to be sent
      • publish

        public void publish(String channel,
                            String message,
                            int ttl,
                            OnPublishResult callback)
        Publish a message to a channel.
        Parameters:
        channel - Channel to wich the message should be sent
        message - The content of the message to be sent
        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
      • publish

        protected abstract void publish(String channel,
                                        String message,
                                        int ttl,
                                        String messagePartIdentifier,
                                        String permission)
      • send

        protected abstract void send(String channel,
                                     String message,
                                     String messagePartIdentifier,
                                     String permission)
      • subscribe

        public void subscribe(String channel,
                              boolean subscribeOnReconnect,
                              OnMessage onMessage)
        Subscribe the specified channel in order to receive messages in that channel
        Parameters:
        channel - Channel to be subscribed
        subscribeOnReconnect - Indicates if the channel should be subscribe if the event on reconnected is fired
        onMessage - Event handler that will be called when a message will be received on the subscribed channel
      • subscribeWithFilter

        public void subscribeWithFilter(String channel,
                                        boolean subscribeOnReconnect,
                                        String filter,
                                        OnMessageWithFilter onMessageWithFilter)
        subscribeWithFilter the specified channel with a given filter in order to receive filtered messages in that channel
        Parameters:
        channel - Channel to be subscribed
        subscribeOnReconnect - Indicates if the channel should be subscribe if the event on reconnected is fired
        filter - The filter to apply to messages on the given channel
        onMessageWithFilter - Event handler that will be called when a message will be received on the subscribed channel
      • subscribeWithOptions

        public void subscribeWithOptions(Map options,
                                         OnMessageWithOptions onMessage)
        Subscribes to a channel to receive messages sent to it with given options.
        Parameters:
        options - The subscription options dictionary, EX: "options = { channel, subscribeOnReconnected, // optional, default = true, filter, // optional, default = "", the subscription filter as in subscribeWithFilter subscriberId // optional, default = "", the subscriberId as in subscribeWithBuffer }".
        onMessage - The callback called when a message arrives at the channel, data is provided in a dictionary.
      • subscribe

        protected abstract void subscribe(String channel,
                                          String permission,
                                          boolean withFilter,
                                          String filter)
      • _subscribeWithOptions

        protected abstract void _subscribeWithOptions(String channel,
                                                      String permission,
                                                      boolean subscribeOnReconnected,
                                                      String filter,
                                                      String subscriberId)
      • unsubscribe

        public void unsubscribe(String channel)
        Stop receiving messages in the specified channel
        Parameters:
        channel - Channel to be unsubscribed
      • unsubscribe

        protected abstract void unsubscribe(String channel,
                                            boolean isValid)
      • stopReconnecting

        protected void stopReconnecting()
      • cancelSubscription

        protected void cancelSubscription(String channel)
      • presence

        public void presence(String channel,
                             OnPresence callback)
                      throws OrtcNotConnectedException
        Gets the subscriptions in the specified channel and if active the first 100 unique metadata.
         Ortc.presence("CHANNEL", new onPresence() {
         
                public void run(Exception error, Presence presence) {
                        if (error != null) {
                                System.out.println(error.getMessage());
                        } else {
                                System.out.println("Subscriptions - " + presence.getSubscriptions());
         
                                Iterator<?> metadataIterator = presence.getMetadata().entrySet()
                                                .iterator();
                                while (metadataIterator.hasNext()) {
                                        Map.Entry<String, Long> entry = (Map.Entry<String, Long>) metadataIterator
                                                        .next();
                                        System.out.println(entry.getKey() + " - " + entry.getValue());
                                }
                        }
                }
         });
         
        Parameters:
        channel - Channel with presence data active.
        callback - Callback with error and result.
        Throws:
        OrtcNotConnectedException
      • enablePresence

        public void enablePresence(String privateKey,
                                   String channel,
                                   Boolean metadata,
                                   OnEnablePresence callback)
                            throws OrtcNotConnectedException
        Enables presence for the specified channel with first 100 unique metadata if metadata is set to true.
         Ortc.enablePresence("PRIVATE_KEY", "CHANNEL", true, new onEnablePresence() {
         
                public void run(Exception error, String result) {
                        if (error != null) {
                                System.out.println(error.getMessage());
                        } else {
                                System.out.println(result);
         
                        }
                }
         });
         
        Parameters:
        privateKey - The private key provided when the ORTC service is purchased.
        channel - Channel with presence data active.
        metadata - Defines if to collect first 100 unique metadata.
        callback - Callback with error and result.
        Throws:
        OrtcNotConnectedException
      • disablePresence

        public void disablePresence(String privateKey,
                                    String channel,
                                    OnDisablePresence callback)
                             throws OrtcNotConnectedException
        Disables presence for the specified channel.
         Ortc.disablePresence("PRIVATE_KEY", "CHANNEL", new onDisablePresence() {
         
                public void run(Exception error, String result) {
                        if (error != null) {
                                System.out.println(error.getMessage());
                        } else {
                                System.out.println(result);
         
                        }
                }
         });
         
        Parameters:
        privateKey - The private key provided when the ORTC service is purchased.
        channel - Channel to disable presence
        callback - Callback with error and result.
        Throws:
        OrtcNotConnectedException
      • isSubscribed

        public Boolean isSubscribed(String channel)
        Indicates if the channel is subscribed
        Parameters:
        channel - Channel to check
        Returns:
        boolean True if the channel is subscribed otherwise false
      • getConnectionMetadata

        public String getConnectionMetadata()
        Gets the Ortc client connection metadata
        Returns:
        String Connection metadata content
      • setConnectionMetadata

        public void setConnectionMetadata(String connectionMetadata)
        Sets the client connection metadata
        Parameters:
        connectionMetadata - Connection metada content
      • getAnnouncementSubChannel

        public String getAnnouncementSubChannel()
        Gets the announcement sub channel to where the announcement messages are going to be sent
        Returns:
        String The announcement sub channel
      • setAnnouncementSubChannel

        public void setAnnouncementSubChannel(String channel)
        Sets the announcement sub channel to where the announcement messages are going to be sent
        Parameters:
        channel - Announcement sub channel
      • getClusterUrl

        public String getClusterUrl()
        Gets the cluster gateway url to wich the Ortc client is connecting
        Returns:
        String The cluster gateway url
      • setClusterUrl

        public void setClusterUrl(String clusterUrl)
        Sets the cluster gateway url to wich the Ortc client should connect
        Parameters:
        clusterUrl - Ortc cluster gateway url
      • getUrl

        public String getUrl()
        Gets the Ortc server url to wich the Ortc client is connecting
        Returns:
        String Ortc server url
      • setUrl

        public void setUrl(String url)
        Sets the Ortc server url to wich the Ortc client should connect
        Parameters:
        url - Ortc server url
      • getConnectionTimeout

        public int getConnectionTimeout()
        Gets the connection timeout before trying a new reconnection attempt
        Returns:
        int Reconnect connection timeout
      • setConnectionTimeout

        public void setConnectionTimeout(int connectionTimeout)
        Sets the connection timeout before trying a new reconnection attempt
        Parameters:
        connectionTimeout - Reconnect connection timeout
      • getId

        public int getId()
        Gets Ortc client unique identifier
        Returns:
        int Ortc client unique identifier
      • setId

        public void setId(int id)
        Sets Ortc client unique identifier
        Parameters:
        id - Ortc client unique identifier
      • getIsConnected

        public boolean getIsConnected()
        Indicates if the ortc client is connected
        Returns:
        boolean True if is connected otherwise false
      • setProxy

        public void setProxy(String proxyHost,
                             int proxyPort)
        Defines the proxy connection settings for the ortc client
        Parameters:
        proxyHost - Proxy host
        proxyPort - Proxy port
      • setProxy

        public void setProxy(String host,
                             int port,
                             String user,
                             String pwd)
        sets proxy, optionally using basic authentication
        Parameters:
        host - proxy host
        port - proxy port
        user - proxy user or null when no authentication is needed
        pwd - proxy password or null when no authentication is needed
      • setProxy

        public void setProxy(Proxy proxy)
      • getPublishTimeout

        public int getPublishTimeout()
        Gets the publish operation timeout
        Returns:
        int Publish operation timeout in miliseconds (default 5000ms)
      • setPublishTimeout

        public void setPublishTimeout(int publishTimeout)
        Sets the publish operation timeout
        Parameters:
        publishTimeout - Publish operation timeout in miliseconds (default is 5000ms)
      • raiseOrtcEvent

        protected void raiseOrtcEvent(EventEnum eventToRaise,
                                      Object... args)
      • getHeartbeatActive

        public boolean getHeartbeatActive()
        Get if heartbeat active.
        Returns:
        if heartbeat is active.
      • setHeartbeatActive

        public void setHeartbeatActive(boolean active)
        Set heart beat active. Heart beat provides better accuracy for presence data.
        Parameters:
        active - true to activate heartbeat and false to deactivate.
      • getHeartbeatFails

        public int getHeartbeatFails()
        Get how many times can the client fail the heartbeat.
        Returns:
        amount of fails the heartbeat can have before disconnecting.
      • setHeartbeatFails

        public void setHeartbeatFails(int newHeartbeatFails)
        Set heartbeat fails. Defines how many times can the client fail the heartbeat.
        Parameters:
        newHeartbeatFails -
      • getHeartbeatTime

        public int getHeartbeatTime()
        Get heartbeat interval.
        Returns:
        interval between heartbeats.
      • setHeartbeatTime

        public void setHeartbeatTime(int newHeartbeatTime)
        Set heartbeat fails. Defines how many times can the client fail the heartbeat.
        Parameters:
        newHeartbeatTime -
      • startHeartBeatInterval

        public void startHeartBeatInterval()
      • stopHeartBeatInterval

        public void stopHeartBeatInterval()
      • sendHeartbeat

        protected abstract void sendHeartbeat()

Copyright © 2017. All rights reserved.