Listen to events

WebSocket

Whenever ComapiClient is configured and authenticated, a new session is started which opens a WebSocket connection. This allows for a two-way real-time communication between the client and the server. For more information on WebSocket visit the official RFC site. When open, the socket provides live updates for the profile and conversations which you are a participant of. You can subscribe for these updates to update your views and models.

Add event listener

Register the delegate for the incoming events with the CMPComapiClient object. The delegate should conform to the CMPEventListener protocol.

[client addEventDelegate:self];
client.add(self)

To receive the event implement following method from CMPEventListener protocol:

- (void)client:(CMPComapiClient *)client didReceiveEvent:(CMPEvent *)event {
  	switch (event.type) {
        case CMPEventTypeConversationMessageSent:
      			// message sent event received
            break;
        case CMPEventTypeConversationParticipantTypingOff:
      			// participant typing off event received
            break;
        case CMPEventTypeConversationParticipantTyping:
      			// participant typing event received
            break;
        case CMPEventTypeConversationMessageRead:
      			// message read event received
            break;
      	// case .other events:
        default:
      			// unknown event type
            break;
    }
}
func client(_ client: ComapiClient, didReceive event: Event) {
		switch event.type {
        case .conversationMessageSent:
            // message sent event received
        case .conversationParticipantTypingOff:
            // participantTypingOff event received
        case .conversationParticipantTyping:
            // participantTyping event received
        case .conversationMessageRead:
        		// message read event received
        // case .other events:
        
        default:
            // unknown event type
		}
}

Please note that you can register multiple listeners in your code, to handle events in different parts of your application. The events are broadcasted to all registered delegates.

[client removeEventDelegate:self];
client.remove(self)

Available events

Event typeEvent subtype
profileupdateSent when a user's profile is updated.
conversationparticipantAddedSent when a participant is added to a conversation. When a conversation is created, this event will also fire with the owner's profileId.
conversationparticipantUpdatedSent when a participant role is updated in a conversation.
conversationparticipantRemovedSent when a participant is removed from a conversation.
conversationdeleteSent when a conversation is deleted.
conversationupdateSent when a conversation details were updated.
conversationundeleteSent when a conversation is restored.
conversationcreateSent when new conversation was created.
conversationparticipantTypingSent when one of the participants is typing new message
conversationparticipantTypingOffSent when the other participant stopped typing
conversationMessagedeliveredSent when one of participants updated the message status to 'delivered'.
conversationMessagereadSent when one of participants updated the message status to 'read'.
conversationMessagesentSent when a new message appeared in a conversation. This event will also be delivered to the message sender.

For all events you can access id, apiSpace and name and context properties.

For other events, there are other properties you can access, as follows:

profile.profileId

Conversation

Below are listed properties specific for the conversation event subtypes.

conversation.conversationId
conversation.payload.profileId
conversation.payload.role
conversation.conversationId
conversation.payload.profileId
conversation.payload.role
conversation.conversationId
conversation.payload.profileId
conversation.payload.role
conversation.conversationId
conversation.payload.date
conversation.profileId
conversation.payload.roles
conversation.payload.isPublic
conversation.payload.participants
conversation.conversationId
conversation.payload.description
conversation.payload.roles
conversation.profileId
conversation.payload.roles
conversation.payload.isPublic
conversation.payload.participants
conversation.account
conversation.payload.profileId
covenrsation.payload.conversationId
conversation.account
conversation.payload.profileId
covenrsation.payload.conversationId

ConversationMessage

conversationMessage.messageId
conversationMessage.conversationId
conversationMessage.profileId
conversationMessage.timestamp
conversationMessage.messageId
conversationMessage.conversationId
conversationMessage.profileId
conversationMessage.timestamp
conversationMessage.messageId
conversationMessage.metadata
conversationMessage.parts
conversationMessage.alert