feat(lib, android, ios): permissions clean up, add id to files pack

This commit is contained in:
ksenia312
2024-02-07 13:30:34 +01:00
parent 2541aa57d2
commit f18065db49
20 changed files with 313 additions and 220 deletions
+7 -4
View File
@@ -11,24 +11,27 @@ import MultipeerConnectivity
class NearbyStartCommand {
init(senderName: String, filesCount: Int) {
init(id: String, senderName: String, filesCount: Int) {
self.id = id
self.senderName = senderName
self.filesCount = filesCount
}
static func fromUserInfo(userInfo: NearbyUserInfo)-> NearbyStartCommand? {
if let name = userInfo.dictionary["name"] as? String,
let filesCount = userInfo.dictionary["filesCount"] as? Int
let filesCount = userInfo.dictionary["filesCount"] as? Int,
let id = userInfo.dictionary["id"] as? String
{
return NearbyStartCommand(senderName: name, filesCount: filesCount)
return NearbyStartCommand(id: id, senderName: name, filesCount: filesCount)
}
return nil
}
func toDictionary() -> [String: Any] {
return ["name": senderName, "filesCount": filesCount]
return ["name": senderName, "filesCount": filesCount, "id": id]
}
let id: String
let senderName: String
let filesCount: Int
}
+1
View File
@@ -129,6 +129,7 @@ class NearbyManager: NSObject {
let device = NearbyDevicesStore.instance.find(for: receiverId)
if let requireDevice = device {
let command = NearbyStartCommand(
id: id,
senderName: self.device.name,
filesCount: paths.count
).toDictionary()
+5 -1
View File
@@ -15,9 +15,11 @@ class NearbyFilesStore {
private var senderName: String? = nil
private var maxCount: Int = 0
private var count: Int = 0
private var id: String? = nil
func startReceiving(command: NearbyStartCommand) {
self.paths.removeAll()
self.id = command.id
self.senderName = command.senderName
self.maxCount = command.filesCount
self.count = 0
@@ -33,6 +35,7 @@ class NearbyFilesStore {
}
func clear() {
self.id = nil
self.paths.removeAll()
self.senderName = nil
self.maxCount = 0
@@ -40,8 +43,9 @@ class NearbyFilesStore {
}
func toDartFormat(peerID: MCPeerID) -> String? {
if (senderName != nil) {
if (senderName != nil && id != nil) {
let object = [
"id": id!,
"files": paths.map { ["path": $0]},
"sender": ["id": peerID.displayName, "displayName": senderName!]
] as [String : Any]