PrivMXEndpointContainer
The PrivMXEndpointContainer
class serves as the central management component for handling multiple PrivMXEndpoint
instances within PrivMX system. It is responsible for initializing, managing, and disconnecting endpoints, as well as providing cryptographic services and event handling capabilities.
This class operates in a concurrent environment with support for handling cryptographic operations, managing secure communication endpoints, and listening for events. It also supports asynchronous endpoint creation, disconnection, and event processing.
Fields
cryptoApi
Provides access to cryptographic operations via `PrivMXCrypto`.
public private(set) var cryptoApi:PrivMXCrypto = CryptoApi.create()
Methods
init()
public init()
getEndpoint(_:)
Retrieves an `PrivMXEndpoint` instance from the container based on its ID.
public func getEndpoint(
_ id: Int64
) -> PrivMXEndpoint?
Name | Type | Description |
---|---|---|
id | Int64 | The connection ID of the desired `PrivMXEndpoint`. |
Type | Description |
---|---|
PrivMXEndpoint? | The `PrivMXEndpoint` with the specified ID, if it exists; otherwise, returns `nil`. |
getEndpointIds()
Returns an array of all connected endpoint IDs. This is useful when managing multiple endpoints and retrieving their connection IDs.
public func getEndpointIds(
) -> [Int64]
Type | Description |
---|---|
[Int64] | An array of connection IDs for all connected endpoints. |
newEndpoint(enabling:connectingAs:to🔛)
Initializes a new `PrivMXEndpoint` and adds it to the container. This method creates a new `PrivMXEndpoint` with the specified modules, user credentials, and platform details, and adds it to the `endpoints` dictionary.
public func newEndpoint(
enabling modules:Set<PrivMXModule>,
connectingAs userPrivKey:String,
to solutionId:String,
on platformUrl:String
) async throws -> PrivMXEndpoint
Name | Type | Description |
---|---|---|
modules | Set<PrivMXModule> | A set of modules to be initialized with the new endpoint. |
userPrivKey | String | The user’s private key in WIF format. |
solutionId | String | The unique identifier of PrivMX solution. |
platformUrl | String | The URL of PrivMX Bridge. |
Type | Description |
---|---|
PrivMXEndpoint | The newly created `PrivMXEndpoint` instance. |
newPublicEndpoint(enabling:to🔛)
Initializes a new `PrivMXEndpoint` and adds it to the container. This method creates a new `PrivMXEndpoint` with the specified modules and platform details, and adds it to the `endpoints` dictionary. Note it is only useful for
public func newPublicEndpoint(
enabling modules:Set<PrivMXModule>,
to solutionId:String,
on platformUrl:String
) async throws -> PrivMXEndpoint
Name | Type | Description |
---|---|---|
modules | Set<PrivMXModule> | A set of modules to be initialized with the new endpoint. |
solutionId | String | The unique identifier of the PrivMX solution. |
platformUrl | String | The URL of the PrivMX Bridge. |
Type | Description |
---|---|
PrivMXEndpoint | The newly created `PrivMXEndpoint` instance. |
disconnect(endpoint:)
Disconnects and removes an endpoint from the container. This method terminates the connection of the specified endpoint and removes it from the container.
public func disconnect(
endpoint: Int64
) throws -> Void
Name | Type | Description |
---|---|---|
endpoint | Int64 | The connection ID of the endpoint to be disconnected. |
disconnectAll()
Disconnects and removes all endpoints from the container. This method terminates the connections of all endpoints managed by the container and clears the container.
public func disconnectAll(
) throws -> Void
setCertsPath(to:)
Sets the path to the `.pem` file containing the certificates required for establishing secure connections. This method configures the path to the certificates needed for secure communication with PrivMX Bridge. The exact certificates depend on your Bridge setup.
public func setCertsPath(
to path: String
) throws -> Void
Name | Type | Description |
---|---|---|
path | String | The file path to the `.pem` certificate file. |
stopListening()
Stops listening for events but does not remove event listeners. This method emits a “break” event to pause event listening without removing the registered listeners.
public func stopListening(
) async throws -> Void
startListening()
Starts listening for events in PrivMX system. This method begins listening for events such as updates or notifications within PrivMX system. If the listener is already running, an error will be thrown.
public func startListening() async throws