@mentra/glasses-media 3.5.0-dev.1316 → 3.5.0-dev.1322
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const glassesHotspot: {
|
|
|
11
11
|
purpose?: "outgoing-client" | "incoming-server",
|
|
12
12
|
): Promise<string>
|
|
13
13
|
leave(id: string, waitForInternet?: boolean): Promise<void>
|
|
14
|
-
/** A join with this id
|
|
15
|
-
|
|
14
|
+
/** A join with this id has waited a few seconds for Local Network access, which the person may have denied.
|
|
15
|
+
* `systemAnswer` is the connection state and path reason that left it waiting, for logs. */
|
|
16
|
+
onPermissionRequired(listener: (id: string, systemAnswer: string) => void): {remove(): void}
|
|
16
17
|
}
|
package/index.js
CHANGED
|
@@ -25,5 +25,7 @@ export const glassesHotspot = Object.freeze({
|
|
|
25
25
|
native().joinLocalHotspot(id, ssid, password, gateway ?? null, purpose),
|
|
26
26
|
leave: (id, waitForInternet = false) => native().leaveLocalHotspot(id, waitForInternet),
|
|
27
27
|
onPermissionRequired: (listener) =>
|
|
28
|
-
native().addListener("onLocalHotspotPermissionRequired", (event) =>
|
|
28
|
+
native().addListener("onLocalHotspotPermissionRequired", (event) =>
|
|
29
|
+
listener(event.id, event.systemAnswer ?? "unknown"),
|
|
30
|
+
),
|
|
29
31
|
})
|
|
@@ -11,8 +11,12 @@ protocol LocalNetworkAccessConnection: AnyObject {
|
|
|
11
11
|
/// Connect to the glasses' existing gallery HTTP endpoint to prove local access (TN3179).
|
|
12
12
|
/// Network.framework retries when access is granted. A denied path can also mean that the
|
|
13
13
|
/// alert is still open, so it must not be treated as a terminal error or given a media timeout.
|
|
14
|
+
/// macOS also reports a denied path for about a second and a half right after the Mac joins the
|
|
15
|
+
/// glasses' hotspot, with access granted, while it re-applies its policies to the new network.
|
|
16
|
+
/// The caller is told only when the path stays denied for `permissionGrace`.
|
|
14
17
|
/// Ordinary connection setup has a 30-second budget, paused while permission is required.
|
|
15
18
|
public final class LocalNetworkAccessRequest {
|
|
19
|
+
static let permissionGrace: TimeInterval = 5
|
|
16
20
|
private let queue: DispatchQueue
|
|
17
21
|
private let connection: LocalNetworkAccessConnection
|
|
18
22
|
private let now: () -> TimeInterval
|
|
@@ -21,7 +25,8 @@ public final class LocalNetworkAccessRequest {
|
|
|
21
25
|
private var timeoutDeadline: TimeInterval?
|
|
22
26
|
private var timeoutWork: DispatchWorkItem?
|
|
23
27
|
private var completion: ((Result<Void, Error>) -> Void)?
|
|
24
|
-
private var waiting: (() -> Void)?
|
|
28
|
+
private var waiting: ((String) -> Void)?
|
|
29
|
+
private var permissionWork: DispatchWorkItem?
|
|
25
30
|
private var finished = false
|
|
26
31
|
private var reportedPermission = false
|
|
27
32
|
|
|
@@ -39,7 +44,10 @@ public final class LocalNetworkAccessRequest {
|
|
|
39
44
|
self.scheduleTimeout = scheduleTimeout ?? { delay, work in queue.asyncAfter(deadline: .now() + delay, execute: work) }
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
/// `onPermissionRequired` gets the system's answer, for logs, once the path has stayed denied.
|
|
48
|
+
public func start(onPermissionRequired: @escaping (_ systemAnswer: String) -> Void,
|
|
49
|
+
completion: @escaping (Result<Void, Error>) -> Void)
|
|
50
|
+
{
|
|
43
51
|
queue.async {
|
|
44
52
|
guard !self.finished, self.completion == nil else { return }
|
|
45
53
|
self.completion = completion
|
|
@@ -50,13 +58,12 @@ public final class LocalNetworkAccessRequest {
|
|
|
50
58
|
case .ready: self.finish(.success(()))
|
|
51
59
|
case .waiting where reason == .localNetworkDenied:
|
|
52
60
|
self.pauseConnectivityTimeout()
|
|
53
|
-
|
|
54
|
-
self.reportedPermission = true
|
|
55
|
-
self.waiting?()
|
|
56
|
-
}
|
|
61
|
+
self.reportPermissionIfStillDenied(state)
|
|
57
62
|
// Waiting errors are nonfatal; NWConnection retries when its path recovers.
|
|
58
63
|
// A nil path is not proof of denied permission, but must not fail immediately.
|
|
59
|
-
case .setup, .preparing, .waiting:
|
|
64
|
+
case .setup, .preparing, .waiting:
|
|
65
|
+
self.cancelPermissionReport()
|
|
66
|
+
self.resumeConnectivityTimeout()
|
|
60
67
|
case let .failed(error): self.finish(.failure(error))
|
|
61
68
|
case .cancelled: self.finish(.failure(CancellationError()))
|
|
62
69
|
@unknown default: break
|
|
@@ -71,6 +78,24 @@ public final class LocalNetworkAccessRequest {
|
|
|
71
78
|
queue.async { self.finish(.failure(CancellationError())) }
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
private func reportPermissionIfStillDenied(_ state: NWConnection.State) {
|
|
82
|
+
guard !reportedPermission, permissionWork == nil else { return }
|
|
83
|
+
let grace = Self.permissionGrace
|
|
84
|
+
let work = DispatchWorkItem { [weak self] in
|
|
85
|
+
guard let self, !self.finished, self.permissionWork != nil else { return }
|
|
86
|
+
self.permissionWork = nil
|
|
87
|
+
self.reportedPermission = true
|
|
88
|
+
self.waiting?("NWConnection \(state) unsatisfiedReason=localNetworkDenied for \(Int(grace))s")
|
|
89
|
+
}
|
|
90
|
+
permissionWork = work
|
|
91
|
+
scheduleTimeout(grace, work)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private func cancelPermissionReport() {
|
|
95
|
+
permissionWork?.cancel()
|
|
96
|
+
permissionWork = nil
|
|
97
|
+
}
|
|
98
|
+
|
|
74
99
|
private func resumeConnectivityTimeout() {
|
|
75
100
|
guard timeoutDeadline == nil else { return }
|
|
76
101
|
let deadline = now() + remainingConnectivityTime
|
|
@@ -94,6 +119,7 @@ public final class LocalNetworkAccessRequest {
|
|
|
94
119
|
guard !finished else { return }
|
|
95
120
|
finished = true
|
|
96
121
|
pauseConnectivityTimeout()
|
|
122
|
+
cancelPermissionReport()
|
|
97
123
|
connection.onState = nil
|
|
98
124
|
connection.cancel()
|
|
99
125
|
let reply = completion
|
|
@@ -40,7 +40,8 @@ public final class GlassesHotspotNetwork {
|
|
|
40
40
|
private var waitForInternetAfterLeave = false
|
|
41
41
|
private let internetObservationOwner = HotspotInternetObservationOwner()
|
|
42
42
|
public var onLost: ((String) -> Void)?
|
|
43
|
-
|
|
43
|
+
/// Gets the system's answer that left the join waiting for Local Network access.
|
|
44
|
+
public var onPermissionRequired: ((String) -> Void)?
|
|
44
45
|
public init() {}
|
|
45
46
|
|
|
46
47
|
public func join(ssid: String, passphrase: String, gateway: String? = nil, purpose: HotspotAccessPurpose = .outgoingClient, completion: @escaping (Result<String, Error>) -> Void) {
|
|
@@ -484,10 +485,10 @@ public final class GlassesHotspotNetwork {
|
|
|
484
485
|
let gateway = gatewayAddress ?? address.split(separator: ".").prefix(3).joined(separator: ".") + ".1"
|
|
485
486
|
let request = LocalNetworkAccessRequest(localAddress: address, gateway: gateway, queue: queue)
|
|
486
487
|
localAccess = request
|
|
487
|
-
request.start(onPermissionRequired: { [weak self] in
|
|
488
|
+
request.start(onPermissionRequired: { [weak self] systemAnswer in
|
|
488
489
|
guard let self, gen == generation, !cancelled else { return }
|
|
489
|
-
MediaLog.log("GLASSES-MEDIA local_network_permission=waiting")
|
|
490
|
-
onPermissionRequired?()
|
|
490
|
+
MediaLog.log("GLASSES-MEDIA local_network_permission=waiting \(systemAnswer)")
|
|
491
|
+
onPermissionRequired?(systemAnswer)
|
|
491
492
|
}) { [weak self] result in
|
|
492
493
|
guard let self, gen == generation, !cancelled else { return }
|
|
493
494
|
switch result {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import ExpoModulesCore
|
|
2
2
|
import Foundation
|
|
3
|
+
import OSLog
|
|
4
|
+
|
|
5
|
+
private let permissionLog = Logger(subsystem: "com.mentra.mentra", category: "Permission")
|
|
3
6
|
|
|
4
7
|
public final class GlassesMediaRelayModule: Module {
|
|
5
8
|
private let queue = DispatchQueue(label: "com.mentra.glassesmedia.relay")
|
|
@@ -15,6 +18,11 @@ public final class GlassesMediaRelayModule: Module {
|
|
|
15
18
|
MediaLog.sink = { [weak self] message in self?.sendEvent("onNativeLog", ["message": message]) }
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
// The app's `[Permission]` lines, readable in the unified log: NSLog and the JS console are not.
|
|
22
|
+
Function("logPermission") { (line: String) in
|
|
23
|
+
permissionLog.notice("\(line, privacy: .public)")
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
AsyncFunction("joinLocalHotspot") { (id: String, ssid: String, password: String, gateway: String?, purpose: String, promise: Promise) in
|
|
19
27
|
self.queue.async {
|
|
20
28
|
guard self.localHotspotOwner == nil else {
|
|
@@ -25,8 +33,8 @@ public final class GlassesMediaRelayModule: Module {
|
|
|
25
33
|
}
|
|
26
34
|
self.localHotspotOwner = id
|
|
27
35
|
// The join waits while Local Network access is pending or denied; the caller explains it.
|
|
28
|
-
self.localHotspot.onPermissionRequired = { [weak self] in
|
|
29
|
-
self?.sendEvent("onLocalHotspotPermissionRequired", ["id": id])
|
|
36
|
+
self.localHotspot.onPermissionRequired = { [weak self] systemAnswer in
|
|
37
|
+
self?.sendEvent("onLocalHotspotPermissionRequired", ["id": id, "systemAnswer": systemAnswer])
|
|
30
38
|
}
|
|
31
39
|
self.localHotspot.join(ssid: ssid, passphrase: password, gateway: gateway, purpose: accessPurpose) { result in
|
|
32
40
|
switch result {
|
|
@@ -128,7 +136,7 @@ private final class ManagedRelaySession {
|
|
|
128
136
|
{
|
|
129
137
|
ready = completion
|
|
130
138
|
hotspot.onLost = { reason in onState("failed", reason) }
|
|
131
|
-
hotspot.onPermissionRequired = { [weak self] in
|
|
139
|
+
hotspot.onPermissionRequired = { [weak self] _ in
|
|
132
140
|
self?.queue.async {
|
|
133
141
|
guard let self, !self.stopped else { return }
|
|
134
142
|
onState("permission_required", "Allow Local Network access to connect to your glasses. If you previously denied access, enable it in Settings, or cancel to return home.")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/glasses-media",
|
|
3
|
-
"version": "3.5.0-dev.
|
|
3
|
+
"version": "3.5.0-dev.1322",
|
|
4
4
|
"description": "Shared native glasses media receivers and local network transport",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mentra Community",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@mentra/bluetooth-sdk": "3.5.0-dev.
|
|
19
|
+
"@mentra/bluetooth-sdk": "3.5.0-dev.1322"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"expo-modules-core": "~55.0.25"
|