Overview
Events enable your application to react dynamically to changes within user context.
These events are triggered automatically when a relevant change occurs.
You can subscribe to them by registering event listeners. This allows you to respond to changes as they happen in real-time.
Caveats
- All callback are related to the connection on which they were registered.
- Calling
endpointContainer.stopListening()
does not delete event listeners. - Disconnecting deletes all event listeners related to the connection.
Quick start
- Start the event loop:
endpointContainer.startListening()
- Add event listener for
StoreFileUpdatedEvent
related withcallbackID
:
var storeId = "STORE_ID"
_ = try? endpointContainer.getEndpoint()?.registerCallback(
for: privmx.endpoint.store.StoreFileUpdatedEvent.self,
from: EventChannel.storeFiles(storeID: storeId)
) {
eventData in
}
- Remove the event listener when no longer needed:
var storeId = "STORE_ID"
guard let callbackId = try? endpointContainer.getEndpoint()?.registerCallback(
for: privmx.endpoint.store.StoreFileUpdatedEvent.self,
from: EventChannel.storeFiles(storeID: storeId),
{ eventData in
}
) else {return}
// when no longer needed
endpointContainer.getEndpoint()?.deleteCallback(callbackId)
Unregister callbacks
Unregister specific callbacks from the connection:
endpointContainer.getEndpoint()?.clearCallbacks(for: .platform )