Skip to main content
reference

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

NameTypeDescription
modulesSet<PrivMXModule>A set of modules to initialize (of type `PrivMXModule`).
userPrivKeyStringThe user’s private key in WIF format.
solutionIdStringThe unique identifier of PrivMX Solution.
platformUrlStringThe 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

NameTypeDescription
modulesSet<PrivMXModule>A set of modules to initialize (of type `PrivMXModule`).
solutionIdStringThe unique identifier of the PrivMX solution.
platformUrlStringThe 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

NameTypeDescription
fileFileHandleA local `FileHandle` representing the file to be uploaded.
storeStringThe identifier of the destination store.
publicMetaDataPublic, unencrypted metadata for the file.
privateMetaDataEncrypted metadata for the file.
sizeInt64The size of the file in bytes.
chunkSizeInt64
onChunkUploaded(@escaping @Sendable (Int) -> Void)A callback that is called after each chunk upload is completed.

TypeDescription
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

NameTypeDescription
bufferDataThe in-memory file content as `Data`.
storeStringThe identifier of the destination store.
publicMetaDataPublic, unencrypted metadata for the file.
privateMetaDataEncrypted metadata for the file.
sizeInt64The size of the file in bytes.
chunkSizeInt64The size of each chunk to be uploaded.
onChunkUploaded(@escaping @Sendable (Int) -> Void)A callback that is called after each chunk upload is completed.

TypeDescription
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

NameTypeDescription
fileFileHandleA local `FileHandle` representing the updated file.
storeFileStringThe identifier of the file in the store to be updated.
publicMetaDataPublic metadata to overwrite the existing metadata.
privateMetaDataEncrypted metadata to overwrite the existing metadata.
sizeInt64The size of the updated file in bytes.
chunkSizeInt64
onChunkUploaded(@escaping @Sendable (Int) -> Void)A callback that is called after each chunk upload is completed.

TypeDescription
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

NameTypeDescription
bufferDataThe in-memory content of the updated file as `Data`.
storeFileStringThe identifier of the file in the store to be updated.
publicMetaDataPublic metadata to overwrite the existing metadata.
privateMetaDataEncrypted metadata to overwrite the existing metadata.
sizeInt64The size of the updated file in bytes.
chunkSizeInt64The size of each chunk to be uploaded.
onChunkUploaded(@escaping @Sendable (Int) -> Void)A callback that is called after each chunk upload is completed.

TypeDescription
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

NameTypeDescription
fileFileHandleA local `FileHandle` representing the destination file.
fileIdStringThe identifier of the file to be downloaded.
chunkSizeInt64
onChunkDownloaded(@escaping @Sendable (Int) -> Void)A callback that is called after each chunk download is completed.

TypeDescription
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

NameTypeDescription
fileFileHandle
fileIdStringThe identifier of the file to be downloaded.
chunkSizeInt64
onChunkDownloaded(@escaping @Sendable (Int) -> Void)A callback that is called after each chunk download is completed.

TypeDescription
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

NameTypeDescription
typePMXEvent.Typetype of Event
channelEventChannel
idStringCustom 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

NameTypeDescription
idStringID 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

NameTypeDescription
typePMXEvent.Typethe 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

NameTypeDescription
channelEventChannelthe 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

NameTypeDescription
eventany PMXEvent
tany PMXEvent.Type