PrivMXEndpoint
A wrapper class that manages a connection to PrivMX Bridge and provides access to various APIs, including Threads, Stores, and Inboxes.
The PrivMXEndpoint
class is designed to encapsulate and manage a single connection to PrivMX. It provides access to different APIs for handling Threads, Stores, and Inboxes, based on the modules that are enabled during initialization. It also supports asynchronous operations like uploading and downloading files, and allows for managing callbacks for events.
The PrivMXEndpoint
class is initialized with a connection to PrivMX Bridge using user credentials, Solution ID, and platform URL. Based on the provided modules, it sets up the APIs for handling Threads, Stores, and Inboxes.
Fields
id
The stable identity of the entity associated with this instance.
public let id:Int64
anonymous
Marks the endpoint as connected using no authorisation.
public let anonymous: Bool
connection
Provides handling of network and events through `PrivMXConnection`.
public private(set) var connection : PrivMXConnection
threadApi
API for handling threads.
public private(set) var threadApi : PrivMXThread?
storeApi
API for handling stores.
public private(set) var storeApi : PrivMXStore?
inboxApi
API for handling inboxes.
public private(set) var inboxApi : PrivMXInbox?
Methods
init(modules:userPrivKey:solutionId:platformUrl:)
Initializes a new instance of `PrivMXEndpoint` with a connection to PrivMX Bridge and optional modules. This method sets up the connection and, based on the provided modules, initializes the APIs for handling Threads, Stores, and Inboxes.
public init(
modules:Set<PrivMXModule>,
userPrivKey:String,
solutionId:String,
platformUrl:String
) throws
Name | Type | Description |
---|---|---|
modules | Set<PrivMXModule> | A set of modules to initialize (of type `PrivMXModule`). |
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 instance. |
init(modules:solutionId:platformUrl:)
Initializes a new instance of `PrivMXEndpoint` with a public connection to the PrivMX Bridge and optional modules. This method sets up the connection and, based on the provided modules, initializes the APIs for handling threads, stores, and inboxes. Using a Public (anonymous) connection. Take note that this is only useful for Inboxes
public init(
modules:Set<PrivMXModule>,
solutionId:String,
platformUrl:String
) throws
Name | Type | Description |
---|---|---|
modules | Set<PrivMXModule> | A set of modules to initialize (of type `PrivMXModule`). |
solutionId | String | The unique identifier of the PrivMX solution. |
platformUrl | String | The URL of the PrivMX Bridge instance. |
startUploadingNewFile(_:to:withPublicMeta:withPrivateMeta:sized:withChunksOf:onChunkUploaded:)
Begins uploading a new file using `PrivMXStoreFileHandler`, which manages file uploads. This method uploads a file to a specified store using a `FileHandle`. It supports uploading large files in chunks and provides a callback for tracking the progress.
public func startUploadingNewFile(
_ file:FileHandle,
to store:String,
withPublicMeta publicMeta: Data,
withPrivateMeta privateMeta: Data,
sized size:Int64,
withChunksOf chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize,
onChunkUploaded: (@escaping @Sendable (Int) -> Void) = {_ in}
) async throws -> String
Name | Type | Description |
---|---|---|
file | FileHandle | A local `FileHandle` representing the file to be uploaded. |
store | String | The identifier of the destination store. |
publicMeta | Data | Public, unencrypted metadata for the file. |
privateMeta | Data | Encrypted metadata for the file. |
size | Int64 | The size of the file in bytes. |
chunkSize | Int64 | |
onChunkUploaded | (@escaping @Sendable (Int) -> Void) | A callback that is called after each chunk upload is completed. |
Type | Description |
---|---|
String | The identifier of the uploaded file as a `String`. |
startUploadingNewFileFromBuffer(_:to:withPublicMeta:withPrivateMeta:sized:withChunksOf:onChunkUploaded:)
Begins uploading a new file from an in-memory buffer using `PrivMXStoreFileHandler`. This method uploads file content from a `Data` buffer to a specified Store. It supports chunked uploads and provides a callback for progress tracking.
public func startUploadingNewFileFromBuffer(
_ buffer:Data,
to store:String,
withPublicMeta publicMeta: Data,
withPrivateMeta privateMeta: Data,
sized size:Int64,
withChunksOf chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize,
onChunkUploaded: (@escaping @Sendable (Int) -> Void) = {_ in}
) async throws -> String
Name | Type | Description |
---|---|---|
buffer | Data | The in-memory file content as `Data`. |
store | String | The identifier of the destination store. |
publicMeta | Data | Public, unencrypted metadata for the file. |
privateMeta | Data | Encrypted metadata for the file. |
size | Int64 | The size of the file in bytes. |
chunkSize | Int64 | The size of each chunk to be uploaded. |
onChunkUploaded | (@escaping @Sendable (Int) -> Void) | A callback that is called after each chunk upload is completed. |
Type | Description |
---|---|
String | The identifier of the uploaded file as a `String`. |
startUploadingUpdatedFile(_:as:replacingPublicMeta:replacingPrivateMeta:replacingSize:withChunksOf:onChunkUploaded:)
/ Begins uploading an updated file using `PrivMXStoreFileHandler`. This method updates an existing file in a store with new content and metadata, supporting chunked uploads for large files.
public func startUploadingUpdatedFile(
_ file:FileHandle,
as storeFile:String,
replacingPublicMeta publicMeta: Data,
replacingPrivateMeta privateMeta: Data,
replacingSize size:Int64,
withChunksOf chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize,
onChunkUploaded: (@escaping @Sendable (Int) -> Void) = {_ in}
) async throws -> String
Name | Type | Description |
---|---|---|
file | FileHandle | A local `FileHandle` representing the updated file. |
storeFile | String | The identifier of the file in the store to be updated. |
publicMeta | Data | Public metadata to overwrite the existing metadata. |
privateMeta | Data | Encrypted metadata to overwrite the existing metadata. |
size | Int64 | The size of the updated file in bytes. |
chunkSize | Int64 | |
onChunkUploaded | (@escaping @Sendable (Int) -> Void) | A callback that is called after each chunk upload is completed. |
Type | Description |
---|---|
String | The identifier of the updated file as a `String`. |
startUploadingUpdatedFileFromBuffer(_:as:replacingPublicMeta:replacingPrivateMeta:replacingSize:withChunksOf:onChunkUploaded:)
Begins uploading an updated file from an in-memory buffer using `PrivMXStoreFileHandler`. This method updates an existing file in a store with new content and metadata, supporting chunked uploads for large files.
public func startUploadingUpdatedFileFromBuffer(
_ buffer:Data,
as storeFile:String,
replacingPublicMeta publicMeta: Data,
replacingPrivateMeta privateMeta: Data,
replacingSize size:Int64,
withChunksOf chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize,
onChunkUploaded: (@escaping @Sendable (Int) -> Void) = {_ in}
) async throws -> String
Name | Type | Description |
---|---|---|
buffer | Data | The in-memory content of the updated file as `Data`. |
storeFile | String | The identifier of the file in the store to be updated. |
publicMeta | Data | Public metadata to overwrite the existing metadata. |
privateMeta | Data | Encrypted metadata to overwrite the existing metadata. |
size | Int64 | The size of the updated file in bytes. |
chunkSize | Int64 | The size of each chunk to be uploaded. |
onChunkUploaded | (@escaping @Sendable (Int) -> Void) | A callback that is called after each chunk upload is completed. |
Type | Description |
---|---|
String | The identifier of the updated file as a `String`. |
startDownloadingToFile(_:from:withChunksOf:onChunkDownloaded:)
Begins downloading a file to the local filesystem using `PrivMXStoreFileHandler`. This method downloads a file from a Store to the local filesystem using a `FileHandle`. It supports downloading files in chunks and provides a callback for progress tracking.
public func startDownloadingToFile(
_ file:FileHandle,
from fileId:String,
withChunksOf chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize,
onChunkDownloaded: (@escaping @Sendable (Int) -> Void) = {_ in}
) async throws -> String
Name | Type | Description |
---|---|---|
file | FileHandle | A local `FileHandle` representing the destination file. |
fileId | String | The identifier of the file to be downloaded. |
chunkSize | Int64 | |
onChunkDownloaded | (@escaping @Sendable (Int) -> Void) | A callback that is called after each chunk download is completed. |
Type | Description |
---|---|
String | The identifier of the downloaded file as a `String`. |
startDownloadingToBuffer(_:from:withChunksOf:onChunkDownloaded:)
Begins downloading a file to in-memory buffer. This method downloads a file from a store to the local in-memory buffer. It supports downloading files in chunks and provides a callback for progress tracking.
public func startDownloadingToBuffer(
_ file:FileHandle,
from fileId:String,
withChunksOf chunkSize: Int64 = PrivMXStoreFileHandler.RecommendedChunkSize,
onChunkDownloaded: (@escaping @Sendable (Int) -> Void) = {_ in}
) async throws -> Data
Name | Type | Description |
---|---|---|
file | FileHandle | |
fileId | String | The identifier of the file to be downloaded. |
chunkSize | Int64 | |
onChunkDownloaded | (@escaping @Sendable (Int) -> Void) | A callback that is called after each chunk download is completed. |
Type | Description |
---|---|
Data | The identifier of the downloaded file as a `String`. |
registerCallback(for:from:identified:_:)
Registers a callback for an Event from a particular Channel. This also causes events to start arriving from that channel.
public func registerCallback(
for type: PMXEvent.Type,
from channel:EventChannel,
identified id:String,
_ cb: (@escaping @Sendable (Any?) -> Void) = {_ in}
) throws -> Void
Name | Type | Description |
---|---|---|
type | PMXEvent.Type | type of Event |
channel | EventChannel | |
id | String | Custom identifier for managing Callbacks |
cb | (@escaping @Sendable (Any?) -> Void) |
deleteCallbacks(identified:)
Deletes a specific Callback. Note that this is an expensive operation. If there are no callbacks left for events from a particular channel, `Connection.unsubscribeFromChannel(_:)` is called, which means no Events from that Channel will arrive.
public func deleteCallbacks(
identified id:String
) -> Void
Name | Type | Description |
---|---|---|
id | String | ID of the callback to be deleted |
clearCallbacks(for:)
Removes all callbacks for a particular Event type. If there are no callbacks left for events from a particular channel, `Connection.unsubscribeFromChannel(_:)` is called, which means no Events from that Channel will arrive.
public func clearCallbacks(
for type:PMXEvent.Type
) -> Void
Name | Type | Description |
---|---|---|
type | PMXEvent.Type | the type of Event, for which callbacks should be removed. |
clearCallbacks(for:)
Removes all registered callbacks for Events from selected Channel Once all callbacks are removed, `Connection.unsubscribeFromChannel(_:)` is called, which means no Events from that Channel will arrive.
public func clearCallbacks(
for channel:EventChannel
) -> Void
Name | Type | Description |
---|---|---|
channel | EventChannel | the EventChannel, from which events should no longer be received |
clearAllCallbacks()
Removes all registered callbacks for Events and unsubscribes from all channels
public func clearAllCallbacks(
) -> Void
handleEvent(_:ofType:)
public func handleEvent (
_ event: any PMXEvent,
ofType t: any PMXEvent.Type
) async throws
Name | Type | Description |
---|---|---|
event | any PMXEvent | |
t | any PMXEvent.Type |