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 profile changes listener

Register the delegate for the incoming profile related events with the CMPComapiChatClient object. The delegate should conform to the CMPProfileDelegate protocol.

[client addProfileDelegate:self];

To receive the event implement following method from CMPProfileDelegate protocol:

- (void) didUpdateProfile:(CMPProfileEventUpdate *)event {
  	// event sent when a user profile has been updated.
}

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. To remove a delegate call:

[client removeProfileDelegate:self];

Add conversation participants delegate

Register the delegate to listen to conversation participants added & removed events with the CMPComapiChatClient object. The delegate should conform to the CMPParticipantDelegate protocol.

// Add delegate
[client addParticipantDelegate:self];

// removed delegate
[client removeParticipantDelegate:self];

To receive the event implement following method from CMPParticipantDelegate protocol:

- (void)didAddParticipant:(CMPConversationEventParticipantAdded *)event {
  // event sent when participant joined a conversation
}

- (void)didRemoveParicipant:(CMPConversationEventParticipantRemoved *)event {
  // event sent when participant left a conversation
}

- (void)didUpdateParticipant:(CMPConversationEventParticipantUpdated *)event {
  // event sent when participant roles change in a conversation
}