Skip to content

Commit 03c2690

Browse files
authored
Merge pull request #10 from maxxfrazer/patch-fix
v1.3.0 patch fix
2 parents 0f9202e + 3a2ad40 commit 03c2690

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

Sources/MultipeerHelper/MultipeerHelper.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import MultipeerConnectivity
9+
import Foundation
910
#if canImport(RealityKit)
1011
import RealityKit
1112
#endif
@@ -22,6 +23,10 @@ public class MultipeerHelper: NSObject {
2223
case both = 3
2324
}
2425

26+
public static let compTokenKey = "MPH_CompToken"
27+
public static let osVersionKey = "MPH_OSVersion"
28+
public static let platformKey = "MPH_Platform"
29+
2530
/// Detemines whether your service is advertising, browsing, or both.
2631
public let sessionType: SessionType
2732
public let serviceName: String
@@ -86,7 +91,10 @@ public class MultipeerHelper: NSObject {
8691
encryptionPreference: encryptionPreference
8792
)
8893
session.delegate = self
94+
self.setupSession()
95+
}
8996

97+
private func setupSession() {
9098
if (self.sessionType.rawValue & SessionType.host.rawValue) != 0 {
9199
var discoveryInfo = self.delegate?.setDiscoveryInfo?()
92100
?? [String: String]()
@@ -96,10 +104,21 @@ public class MultipeerHelper: NSObject {
96104
let networkLoc = NetworkCompatibilityToken.local
97105
let jsonData = try? JSONEncoder().encode(networkLoc)
98106
if let encodedToken = String(data: jsonData!, encoding: .utf8) {
99-
discoveryInfo["compatibility_token"] = encodedToken
107+
discoveryInfo[MultipeerHelper.compTokenKey] = encodedToken
100108
}
101109
}
102110
#endif
111+
#if os(iOS) || os(tvOS)
112+
discoveryInfo[MultipeerHelper.osVersionKey] = UIDevice.current.systemVersion
113+
#if os(iOS)
114+
discoveryInfo[MultipeerHelper.platformKey] = "iOS"
115+
#else
116+
discoveryInfo[MultipeerHelper.platformKey] = "tvOS"
117+
#endif
118+
#elseif os(macOS)
119+
discoveryInfo[MultipeerHelper.osVersionKey] = ProcessInfo.processInfo.operatingSystemVersionString
120+
discoveryInfo[MultipeerHelper.platformKey] = "macOS"
121+
#endif
103122
serviceAdvertiser = MCNearbyServiceAdvertiser(
104123
peer: myPeerID,
105124
discoveryInfo: discoveryInfo,
@@ -176,12 +195,12 @@ public class MultipeerHelper: NSObject {
176195

177196
/// Method used for disconnecting all services. Once completed,
178197
/// create a new MultipeerHelper if you want to connect to sessions again.
179-
func disconnectAll() {
198+
public func disconnectAll() {
180199
self.serviceAdvertiser?.stopAdvertisingPeer()
181200
self.serviceBrowser?.stopBrowsingForPeers()
182201
self.serviceAdvertiser = nil
183202
self.serviceBrowser = nil
184-
self.session.disconnect()
203+
self.session?.disconnect()
185204
}
186205
}
187206

Sources/MultipeerHelper/MultipeerHelperDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import MultipeerConnectivity
3737
@objc optional func shouldAcceptJoinRequest(peerID: MCPeerID, context: Data?) -> Bool
3838

3939
/// This will be set as the base for the discoveryInfo, which is sent out by the advertiser (host).
40-
/// The key "compatibility_token" is in use by MultipeerHelper, for checking the
40+
/// The key "MultipeerHelper.compTokenKey" is in use by MultipeerHelper, for checking the
4141
/// compatibility of RealityKit versions.
4242
@objc optional func setDiscoveryInfo() -> [String: String]
4343

@@ -60,7 +60,7 @@ extension MultipeerHelperDelegate {
6060
/// - Returns: Boolean representing whether or not the two devices
6161
/// have compatible versions of RealityKit.
6262
public static func checkPeerToken(with discoveryInfo: [String: String]?) -> Bool {
63-
guard let compTokenStr = discoveryInfo?["compatibility_token"]
63+
guard let compTokenStr = discoveryInfo?[MultipeerHelper.compTokenKey]
6464
else {
6565
return false
6666
}

0 commit comments

Comments
 (0)