PrivMX DOCS
Swift

Custom Events

Custom events allow emitting and receiving data of any shape in a secure, end-to-end encrypted way.

Custom events allow you to send information to specific groups of users. The data will not be stored anywhere. The recipient must be subscribed to the channel on which the event is emitted to receive it.

Before working with Custom Events, follow our Getting Started Guide. It will show you how to set up your project to work with PrivMX Bridge.

Sample code on this page is based on the initial assumptions.

Custom Events use is analogous to normal Event handling.

Working with Custom Events

Key Considerations

Please note the following:

  • Events will only trigger for active connections.
  • Events are not captured unless explicitly listened for.
  • A single instance of the eventQueue is shared across all connections.

Emitting and Handling Custom Events

Below there's an example of how to send a Custom Event to User1 and User2 on the channel context/CONTEXT_ID/CUSTOM_CHANNEL.

// ...

#import PrivMXEndpointNative
#import PrivMXEndpoint
#import PrivMXEndpointExtra
#import Foundation

// ...

let CHANNEL_NAME = "CUSTOM_CHANNEL"
let channel = EventChannel.custom(contextId: CONTEXT_ID , name: CHANNEL_NAME)

endpointSession?.eventApi?.emitEvent(
    in: CONTEXT_ID,
    to: [privmx.endpoint.core.UserWithPubKey(userId: USER1_ID, pubKey: USER1_PUBLIC_KEY),
    	 privmx.endpoint.core.UserWithPubKey(userId: USER2_ID, pubKey: USER2_PUBLIC_KEY),
    	]
    on: channel,
    containing: Data())

To handle an event you simply need to register a callback for it, the same way all other events are handled.

// ...

endpointSession?.registerCallback(
    for: privmx.endpoint.event.ContextCustomEvent.self,
    from: channel,
    identified: "SOME_UNIQUE_IDENTIFIER",
    { data in
    	// some actions when a custom event is received
    })

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.

PrivMX Endpoint Swift v2.3

This package is not up to date with the core documentation. Some of the features you've seen described in other parts of the documentation might not be mentioned here. Those changes do not influence compatibility, however

On this page