VivochaContact

@interface VivochaContact : VivochaContactInfo

This object represent the actual contact.

  • @property BOOL isShowingChat;

    Returns YES if the chat view is showing

  • @property (nonatomic) BOOL isTerminated;

    Returns YES if the contact has been terminated

  • @property (nonatomic) BOOL chatEndedByAgent;

    Returns YES if the contact has been closed by the agent

  • @property (nonatomic, strong) NSDate *startDate;

    Returns the contact start date.

  • - (void)connect;

    Creates and connects the communication stream.

  • - (void)terminate;

    Terminates a contact, hides the chat view and disconnects the communication stream.

  • - (void)terminateHidingView:(BOOL)hide;

    Terminates a contact, disconnects the communication stream and if the passed parameter is YES, hides the chat view.

    Parameters

    hide

    YES to hide the chat, NO to keep it open.

  • - (BOOL)hasUserAuthorizedScreenshotSession;

    Returns YES if user has authorized screenshot session, NO otherwise

  • - (void)stopScreenshotSession;

    Stop the current screenshot session

  • - (void)sendBackground;

    Sends a background notification to the server in order to enable the push notifications.

  • - (void)showView:(BOOL)animated;

    Shows the chat view.

    Parameters

    animated

    YES if you want an animation, NO otherwise.

  • - (void)hideView:(BOOL)animated;

    Hides the chat view.

    Parameters

    animated

    YES if you want an animation, NO otherwise

  • - (void)sendTextMessage:(VivochaMessage *)message;

    Sends a VivochaMessage through the communication stream.

    Parameters

    message

    the message.

  • - (void)sendReadReceiptForMessage:(VivochaMessage *)message;

    Sends a READ receipt for the given VivochaMessage through the communication stream.

    Parameters

    message

    the message.

  • - (void)sendReadReceiptForMessageId:(NSString *)messageId;

    Sends a READ receipt for the given message ID through the communication stream.

    Parameters

    messageId

    the message ID.

  • - (void)sendReadReceiptForChatObject:(VivochaChatObject *)chatObject;

    Sends a READ receipt for the given VivochaChatObject through the communication stream.

    Parameters

    chatObject

    the chat object.

  • - (NSString *)sendMessage:(NSString *)body
                         type:(NSString *)type
                      payload:(NSString *)payload;

    Sends a message through the communication stream.

    Parameters

    body

    the text the message will be created with

    type

    the type of the message

    payload

    the additional payload that will be carried by the message

    Return Value

    the message id.

  • - (void)sendAttachmentWithUrl:(NSString *)url
                      referenceId:(NSString *)referenceId
                            title:(NSString *)title
                         mimetype:(NSString *)mimetype
                      description:(NSString *)description
                         fileSize:(int)fileSize;

    Sends an attachment through the connection stream

    Parameters

    url

    the attachment remote url

    referenceId

    a reference id for the attachment. If null, one will be generated.

    title

    the attachment original filename - mandatory

    mimetype

    the attachment mime-type - mandatory

    description

    the attachment description

    fileSize

    the attachment file size

  • - (void)sendChatState:(BOOL)isTyping;

    Sends a ‘composing’/‘paused’ message through the communication stream.

    Parameters

    isTyping

    If YES the message will be ‘composing’, otherwise it will be ‘paused’.

  • - (void)sendCustomAction:(VivochaCustomAction *)action;

    Sends a custom action to the agent desktop through the communication stream.

    Usage example:

    //Send a custom action
    VivochaCustomAction *userLoggedIn = [VivochaCustomAction actionWithName:@"userLoggedIn" andJSON:@{
                                                                                                    @"userID" : [MyApp getUserId],
                                                                                                    @"eventKind" : @"login",
                                                                                                    @"date" : [NSDate date]
                                                                                                    }];
    
    [[Vivocha contact] sendCustomAction:userLoggedIn];
    

    Parameters

    action

    the custom action.

  • - (VivochaAgent *)agent;

    If an agent accepts the contact, this method will return an object containing the name and the avatar (if present) of the current agent.

    Return Value

    the agent.

  • - (NSInteger)getUnreadMessagesCount;

    Returns the number of messages that are still not marked as read by the Agent.

  • - (void)addChatConnectionStateBlock:(VivochaChatConnectionStateBlock)block
                              withOwner:(id)owner;

    Adds a connection’s state change listener.

    Parameters

    block

    the listener block.

    owner

    the owner object, usually self, where you are calling this method.

  • - (void)unregisterFromConnectionStateBlock:(id)owner;

    Removes the connection’s state change listener registered from the owner object.

    Parameters

    owner

    the owner object, usually self, where you are calling this method.

  • - (BOOL)isWaitingForTransfer;

    Returns YES if the contact is being transfered to another Agent.

  • - (void)startWebRTCWithAudio:(BOOL)localAudio
                  andFrontCamera:(BOOL)frontCamera
                   andBackCamera:(BOOL)backCamera
                  andRemoteAudio:(BOOL)rAudio
                  andRemoteVideo:(BOOL)rVideo
                     andCallback:(VivochaMediaCallback *)cb;

    Initiate a WebRTC call with the Agent.

    Parameters

    localAudio

    the local audio is enabled

    frontCamera

    the local video is enabled and the source will be the front camera

    backCamera

    the local video is enabled and the source will be the back camera

    rAudio

    the agent audio is required

    rVideo

    the agent video is required

    cb

    the callback to be notified of every state of the current call

  • - (void)sendProtocolRequest:(VivochaProtocolRequest *)request
                      withBlock:(void (^)(VivochaProtocolRequest *,
                                          VivochaProtocolResponse *))block;

    Sends a request using the Vivocha Protocol.

    Parameters

    request

    the request object

    block

    the result block, it contains both the request and the response

  • - (void)sendProtocolRequest:(VivochaProtocolRequest *)request
                      withBlock:(void (^)(VivochaProtocolRequest *,
                                          VivochaProtocolResponse *))block
                       andQueue:(dispatch_queue_t)queue;

    Sends a request using the Vivocha Protocol. The result block will be executed in the given queue.

    Parameters

    request

    the request object

    block

    the result block, it contains both the request and the response

    queue

    the queue where the result block will be execute

  • - (void)sendProtocolRequest:(VivochaProtocolRequest *)request
                        timeout:(NSTimeInterval)timeout
                      withBlock:(void (^)(VivochaProtocolRequest *,
                                          VivochaProtocolResponse *))block
                       andQueue:(dispatch_queue_t)queue;

    Sends a request using the Vivocha Protocol. The result block will be executed in the given queue.

    Parameters

    request

    the request object

    timeout

    the request timeout, in seconds

    block

    the result block, it contains both the request and the response

    queue

    the queue where the result block will be execute

  • - (void)sendProtocolResponse:(VivochaProtocolResponse *)response;

    Sends a response using the Vivocha Protocol.

    Parameters

    response

    the response object

  • - (void)hideView:(BOOL)animated andCompletionBlock:(void (^)(void))completion;

    Hides the chat view.

    Parameters

    animated

    the chat view will be hidden with an animation

    completion

    the completion will be executed after the chat view hides.

  • - (void)manageBackground;

    Based on the contact duration and if the agent has joined, decides if the contact should be terminated or if the push notifications need to be enabled. It is called when a UIApplicationDidEnterBackgroundNotification notification is fired by the operating system.

  • - (NSInteger)getDuration;

    Returns the contact duration, in seconds.

  • - (VivochaMedia *)getMedia;

    Returns the current media state.