Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ extension PrivMXSnippetClass {

func handlingCustomEvents() throws{
try endpointSession?.registerCallback(
for: privmx.endpoint.event.ContextCustomEvent.self,
from: channel,
identified: "SOME_UNIQUE_IDENTIFIER",
{ data in
// some actions when a custom event is received
})
for: PMXEventCallbackRegistration(
cb: { data in
//
},
request: .custom(channelName: CHANNEL_NAME,
contextId: CONTEXT_ID),
group: "GROUP"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,52 @@ extension PrivMXSnippetClass {

func addEventListener(){
var storeId = "STORE_ID"
_ = try? endpointSession?.registerCallback(
for: privmx.endpoint.store.StoreFileUpdatedEvent.self,
from: EventChannel.storeFiles(storeID: storeId), identified: "some_id"
) {
eventData in
}
try? endpointSession?.registerCallback(
for: .init(
cb: {
eventData in
// some actions to take
},
request: .store(eventType: privmx.endpoint.store.StoreCreatedEvent.self,
selectorType: PMXEventSelectorType.Context,
selectorId: CONTEXT_ID),
group: "some_group")
)
}

func removeEventListener(){
var storeId = "STORE_ID"
guard let callbackId = try? endpointSession?.registerCallback(
for: privmx.endpoint.store.StoreFileUpdatedEvent.self,
from: EventChannel.storeFiles(storeID: storeId), identified: "some_id",
{ eventData in
}
) else {return}

endpointContainer?.getEndpoint(endpointId)?.deleteCallbacks(identified: "some_id")

}
func removeEventListenerByGroup(){
var storeId = "STORE_ID"
do{
try endpointSession?.registerCallback(
for: .init(
cb: {
eventData in
// some actions to take
},
request: .store(eventType: privmx.endpoint.store.StoreFileCreatedEvent.self,
selectorType: PMXEventSelectorType.Container,
selectorId: storeId),
group: "some_group")
)

try endpointContainer?.getEndpoint(endpointId)?.clearCallbacks(in: "some_group")
} catch {
print(error)
}

}

func unregisterCallbacks(){
endpointContainer?.getEndpoint(endpointId)?.clearCallbacks(for: .platform )


}
func unregisterCallbacksByRequest(){
let threadId = "THREAD_ID"
try? endpointContainer?.getEndpoint(endpointId)?.clearCallbacks(
for: .thread(
eventType: privmx.endpoint.thread.ThreadMessageUpdatedEvent.self,
selectorType: PMXEventSelectorType.Container,
selectorId: threadId))
}

func unregisterAllCallbacks(){
endpointContainer?.getEndpoint(endpointId)?.clearAllCallbacks()
try? endpointContainer?.getEndpoint(endpointId)?.clearAllCallbacks()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ extension PrivMXSnippetClass {

//3
try? publicEndpointSession?.inboxApi?.writeToFile(inboxFileHandle, of: entryHandle, uploading: data)
try? publicEndpointSession?.inboxApi?.closeFile(withHandle: inboxFileHandle)

//4
try? publicEndpointSession?.inboxApi?.sendEntry(entryHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ extension PrivMXSnippetClass {
in: storeID,
withPublicMeta: Data(),
withPrivateMeta: Data(),
ofSize: Int64(fileContentData.count))
ofSize: Int64(fileContentData.count),
randomWriteSupport: false)
else {return}
try? endpointSession?.storeApi?.writeToFile(withHandle: storeFileHandle, uploading: fileContentData)
try? endpointSession?.storeApi?.writeToFile(
withHandle: storeFileHandle,
uploading: fileContentData,
truncate: false)
let storeFileId = try? endpointSession?.storeApi?.closeFile(withHandle: storeFileHandle)
}

public func uploadWithFileMeta(){
Expand All @@ -46,9 +51,15 @@ extension PrivMXSnippetClass {
in: storeID,
withPublicMeta: Data(),
withPrivateMeta: filePrivateMetaData,
ofSize: Int64(fileContentData.count))
ofSize: Int64(fileContentData.count),
randomWriteSupport: false)
else {return}
try? endpointSession?.storeApi?.writeToFile(withHandle: storeFileHandle, uploading: fileContentData)
try? endpointSession?.storeApi?.writeToFile(
withHandle: storeFileHandle,
uploading: fileContentData,
truncate: false)

let storeFileId = try? endpointSession?.storeApi?.closeFile(withHandle: storeFileHandle)

}

Expand Down Expand Up @@ -115,16 +126,15 @@ extension PrivMXSnippetClass {
guard let newFilePrivateMetaData = try? JSONEncoder().encode(newFilePrivateMeta) else {return}
guard let filePublicMetaData = file.publicMeta.getData() else {return}
try? endpointSession?.storeApi?
.updateFile(fileID,
replacingPublicMeta: filePublicMetaData,
replacingPrivateMeta: newFilePrivateMetaData,
replacingSize: file.size)
.updateFileMeta(
of: fileID,
replacingPublicMeta: filePublicMetaData,
replacingPrivateMeta: newFilePrivateMetaData)
}

func deletingFile(){
var fileID = "FILE_ID"
try? endpointSession?.storeApi?.deleteFile(fileID)


}
}