@mentra/glasses-media 3.5.0-dev.1271 → 3.5.0-dev.1276

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.
Files changed (35) hide show
  1. package/android/build.gradle +1 -0
  2. package/android/src/main/java/com/mentra/glassesmedia/GlassesMediaRelayModule.kt +11 -3
  3. package/android/src/main/java/com/mentra/glassesmedia/network/InternetHold.kt +1 -1
  4. package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkChangeDetector.kt +3 -1
  5. package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkObserver.kt +1 -1
  6. package/android/src/main/java/com/mentra/glassesmedia/publisher/PhoneWhipPublisher.kt +1 -1
  7. package/android/src/main/java/com/mentra/glassesmedia/source/CloudflareWhepSource.kt +1 -1
  8. package/android/src/main/java/com/mentra/glassesmedia/source/DecodedFrameTap.kt +1 -1
  9. package/android/src/main/java/com/mentra/glassesmedia/source/DecodedTrackRelay.kt +1 -1
  10. package/android/src/main/java/com/mentra/glassesmedia/source/GlassesMediaSource.kt +1 -1
  11. package/android/src/main/java/com/mentra/glassesmedia/source/LocalWhipIngestSource.kt +4 -4
  12. package/android/src/main/java/com/mentra/glassesmedia/source/SelectedIcePair.kt +1 -1
  13. package/android/src/main/java/com/mentra/glassesmedia/source/SoftApIceDiagnosis.kt +3 -2
  14. package/android/src/main/java/com/mentra/glassesmedia/source/SoftApSdpGuard.kt +1 -1
  15. package/android/src/main/java/com/mentra/glassesmedia/source/SyntheticI420Source.kt +1 -1
  16. package/android/src/main/java/com/mentra/glassesmedia/source/VideoSourceArm.kt +2 -0
  17. package/android/src/main/java/com/mentra/glassesmedia/source/WhipIngestServer.kt +3 -3
  18. package/android/src/main/java/com/mentra/glassesmedia/telemetry/AvSyncProbe.kt +1 -1
  19. package/android/src/main/java/com/mentra/glassesmedia/trace/MediaLog.kt +35 -0
  20. package/index.d.ts +3 -0
  21. package/index.js +17 -0
  22. package/ios/GlassesHotspotNetwork.swift +8 -10
  23. package/ios/GlassesMediaRelayModule.swift +6 -1
  24. package/ios/LocalWhipIngestSource.swift +2 -2
  25. package/ios/MediaLog.swift +13 -0
  26. package/ios/WhepVideoSource.swift +8 -8
  27. package/package.json +4 -1
  28. package/android/src/main/java/com/mentra/glassesmedia/network/Ipv4Prefix.kt +0 -51
  29. package/android/src/main/java/com/mentra/glassesmedia/network/NetworkFacts.kt +0 -81
  30. package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkError.kt +0 -109
  31. package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkReadiness.kt +0 -103
  32. package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkRequestSpec.kt +0 -53
  33. package/android/src/main/java/com/mentra/glassesmedia/network/ScopedNetworkState.kt +0 -127
  34. package/android/src/main/java/com/mentra/glassesmedia/network/ScopedSoftApNetwork.kt +0 -584
  35. package/android/src/main/java/com/mentra/glassesmedia/trace/SoftApTrace.kt +0 -143
@@ -66,6 +66,7 @@ afterEvaluate {
66
66
  }
67
67
 
68
68
  dependencies {
69
+ implementation project(':mentra-bluetooth-sdk')
69
70
  coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
70
71
  implementation 'com.squareup.okhttp3:okhttp:4.12.0'
71
72
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
@@ -1,12 +1,15 @@
1
1
  package com.mentra.glassesmedia
2
2
 
3
+ import com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork
4
+ import com.mentra.bluetoothsdk.hotspot.ScopedNetworkError
3
5
  import android.content.Intent
4
6
  import android.os.Handler
5
7
  import android.os.Looper
6
8
  import android.os.PowerManager
7
9
  import android.provider.Settings
8
10
  import android.util.Base64
9
- import android.util.Log
11
+ import com.mentra.glassesmedia.trace.MediaLog
12
+ import com.mentra.glassesmedia.trace.MediaLog as Log
10
13
  import com.mentra.glassesmedia.network.*
11
14
  import com.mentra.glassesmedia.publisher.PhoneWhipPublisher
12
15
  import com.mentra.glassesmedia.publisher.RelayPcmInput
@@ -29,7 +32,9 @@ class GlassesMediaRelayModule : Module() {
29
32
 
30
33
  override fun definition() = ModuleDefinition {
31
34
  Name("MentraGlassesMediaRelay")
32
- Events("onRelayState")
35
+ Events("onRelayState", "onNativeLog")
36
+
37
+ OnCreate { MediaLog.sink = { message -> sendEvent("onNativeLog", mapOf("message" to message)) } }
33
38
 
34
39
  AsyncFunction("prepare") { options: Map<String, Any?>, promise: Promise ->
35
40
  worker.execute {
@@ -102,7 +107,10 @@ class GlassesMediaRelayModule : Module() {
102
107
  }
103
108
  }
104
109
 
105
- OnDestroy { worker.execute { runCatching { cleanup() }; worker.shutdown() } }
110
+ OnDestroy {
111
+ MediaLog.sink = null
112
+ worker.execute { runCatching { cleanup() }; worker.shutdown() }
113
+ }
106
114
  }
107
115
 
108
116
  private fun emit(id: String, state: String, reason: String) {
@@ -8,7 +8,7 @@ import android.net.NetworkCapabilities
8
8
  import android.net.NetworkRequest
9
9
  import android.net.wifi.WifiManager
10
10
  import android.os.SystemClock
11
- import com.mentra.glassesmedia.trace.SoftApTrace
11
+ import com.mentra.bluetoothsdk.hotspot.SoftApTrace
12
12
  import java.net.Inet4Address
13
13
  import java.util.concurrent.CountDownLatch
14
14
  import java.util.concurrent.TimeUnit
@@ -1,8 +1,10 @@
1
1
  package com.mentra.glassesmedia.network
2
2
 
3
+ import com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork
4
+ import com.mentra.bluetoothsdk.hotspot.NetworkFacts
3
5
  import android.content.Context
4
6
  import android.net.ConnectivityManager
5
- import com.mentra.glassesmedia.trace.SoftApTrace
7
+ import com.mentra.bluetoothsdk.hotspot.SoftApTrace
6
8
  import java.net.Inet4Address
7
9
  import org.webrtc.NetworkChangeDetector
8
10
  import org.webrtc.NetworkMonitor
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.network
2
2
 
3
- import com.mentra.glassesmedia.trace.SoftApTrace
3
+ import com.mentra.bluetoothsdk.hotspot.SoftApTrace
4
4
  import org.webrtc.NetworkChangeDetector
5
5
 
6
6
  /**
@@ -5,7 +5,7 @@ import android.net.ConnectivityManager
5
5
  import android.os.Handler
6
6
  import android.os.HandlerThread
7
7
  import com.mentra.glassesmedia.network.InternetHold
8
- import com.mentra.glassesmedia.trace.SoftApTrace
8
+ import com.mentra.bluetoothsdk.hotspot.SoftApTrace
9
9
  import com.mentra.glassesmedia.source.I420Planes
10
10
  import java.io.IOException
11
11
  import java.util.concurrent.CountDownLatch
@@ -2,7 +2,7 @@ package com.mentra.glassesmedia.source
2
2
 
3
3
  import android.content.Context
4
4
  import android.media.AudioAttributes
5
- import android.util.Log
5
+ import com.mentra.glassesmedia.trace.MediaLog as Log
6
6
  import com.mentra.glassesmedia.telemetry.PipelineStats
7
7
  import com.mentra.glassesmedia.video.I420Packer
8
8
  import okhttp3.MediaType.Companion.toMediaType
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import android.util.Log
3
+ import com.mentra.glassesmedia.trace.MediaLog as Log
4
4
 
5
5
  /**
6
6
  * A second, optional consumer of decoded glasses video, sitting beside the ACS sender.
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import android.util.Log
3
+ import com.mentra.glassesmedia.trace.MediaLog as Log
4
4
  import com.mentra.glassesmedia.telemetry.PipelineStats
5
5
  import com.mentra.glassesmedia.video.FrameGeometry
6
6
  import org.webrtc.AudioTrackSink
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import com.mentra.glassesmedia.trace.SoftApTrace
3
+ import com.mentra.bluetoothsdk.hotspot.SoftApTrace
4
4
 
5
5
  enum class SourceKind {
6
6
  /** Subscribe to a Cloudflare WHEP endpoint. The phone is the offerer. */
@@ -2,12 +2,12 @@ package com.mentra.glassesmedia.source
2
2
 
3
3
  import android.content.Context
4
4
  import android.media.AudioAttributes
5
- import android.util.Log
6
- import com.mentra.glassesmedia.network.NetworkFacts
5
+ import com.mentra.glassesmedia.trace.MediaLog as Log
6
+ import com.mentra.bluetoothsdk.hotspot.NetworkFacts
7
7
  import com.mentra.glassesmedia.network.ScopedNetworkChangeDetector
8
- import com.mentra.glassesmedia.network.ScopedSoftApNetwork
8
+ import com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork
9
9
  import com.mentra.glassesmedia.telemetry.PipelineStats
10
- import com.mentra.glassesmedia.trace.SoftApTrace
10
+ import com.mentra.bluetoothsdk.hotspot.SoftApTrace
11
11
  import org.webrtc.AudioTrack
12
12
  import org.webrtc.DefaultVideoDecoderFactory
13
13
  import org.webrtc.DefaultVideoEncoderFactory
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import com.mentra.glassesmedia.network.Ipv4Prefix
3
+ import com.mentra.bluetoothsdk.hotspot.Ipv4Prefix
4
4
 
5
5
  /**
6
6
  * Reads the path media is *actually* taking out of a WebRTC stats sample.
@@ -1,6 +1,7 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import com.mentra.glassesmedia.network.Ipv4Prefix
3
+ import com.mentra.bluetoothsdk.hotspot.NetworkFacts
4
+ import com.mentra.bluetoothsdk.hotspot.Ipv4Prefix
4
5
  import com.mentra.glassesmedia.network.ScopedNetworkChangeDetector.PublishedEntry
5
6
 
6
7
  /**
@@ -64,7 +65,7 @@ object SoftApIceDiagnosis {
64
65
  get() = candidates.filterNot { it.onHotspot }
65
66
 
66
67
  /**
67
- * Flattened for [SoftApTrace][com.mentra.glassesmedia.trace.SoftApTrace] and the analyzer.
68
+ * Flattened for [SoftApTrace][com.mentra.bluetoothsdk.hotspot.SoftApTrace] and the analyzer.
68
69
  * Field names are the contract `softap-call-proof.mjs` reads, so they are stable.
69
70
  */
70
71
  fun fields(): Array<Pair<String, Any?>> =
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import com.mentra.glassesmedia.network.Ipv4Prefix
3
+ import com.mentra.bluetoothsdk.hotspot.Ipv4Prefix
4
4
 
5
5
  /**
6
6
  * Checks that a SoftAP negotiation is actually staying on the SoftAP.
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import android.util.Log
3
+ import com.mentra.glassesmedia.trace.MediaLog as Log
4
4
  import com.mentra.glassesmedia.telemetry.PipelineStats
5
5
  import com.mentra.glassesmedia.video.I420Packer
6
6
  import java.nio.ByteBuffer
@@ -1,5 +1,7 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
+ import com.mentra.bluetoothsdk.hotspot.NetworkFacts
4
+
3
5
  enum class VideoSourceArm { WHEP, SYNTHETIC }
4
6
 
5
7
  enum class SyntheticEntropy { CHEAP, MOTION, NOISE }
@@ -1,7 +1,7 @@
1
1
  package com.mentra.glassesmedia.source
2
2
 
3
- import android.util.Log
4
- import com.mentra.glassesmedia.trace.SoftApTrace
3
+ import com.mentra.glassesmedia.trace.MediaLog as Log
4
+ import com.mentra.bluetoothsdk.hotspot.SoftApTrace
5
5
  import java.io.BufferedInputStream
6
6
  import java.io.BufferedOutputStream
7
7
  import java.io.IOException
@@ -92,7 +92,7 @@ class WhipIngestServer(
92
92
  * Binds and begins accepting.
93
93
  *
94
94
  * @param address the phone's own address on the SoftAP, from
95
- * [com.mentra.glassesmedia.network.ScopedSoftApNetwork.localIpv4]
95
+ * [com.mentra.bluetoothsdk.hotspot.ScopedSoftApNetwork.localIpv4]
96
96
  * @param port 0 to let the OS choose, which is what production does; the fixed-port form exists
97
97
  * for tests
98
98
  */
@@ -1,6 +1,6 @@
1
1
  package com.mentra.glassesmedia.telemetry
2
2
 
3
- import android.util.Log
3
+ import com.mentra.glassesmedia.trace.MediaLog as Log
4
4
  import kotlin.math.abs
5
5
 
6
6
  /**
@@ -0,0 +1,35 @@
1
+ package com.mentra.glassesmedia.trace
2
+
3
+ import android.util.Log
4
+
5
+ /**
6
+ * Logcat plus the app's JavaScript console, which bug reports upload. glasses-media and
7
+ * acs-meeting import it as `Log`, so the relay, ingest, SoftAP and ACS traces reach a report.
8
+ */
9
+ object MediaLog {
10
+ /** Set by [com.mentra.glassesmedia.GlassesMediaRelayModule] while it exists. */
11
+ @Volatile
12
+ var sink: ((String) -> Unit)? = null
13
+
14
+ fun i(tag: String, message: String): Int = write(Log.INFO, tag, message, null)
15
+
16
+ fun w(tag: String, message: String, error: Throwable? = null): Int = write(Log.WARN, tag, message, error)
17
+
18
+ fun e(tag: String, message: String, error: Throwable? = null): Int = write(Log.ERROR, tag, message, error)
19
+
20
+ private fun write(priority: Int, tag: String, message: String, error: Throwable?): Int {
21
+ val text = if (error == null) message else "$message\n${Log.getStackTraceString(error)}"
22
+ val result = Log.println(priority, tag, text)
23
+ val level = when (priority) {
24
+ Log.ERROR -> "E"
25
+ Log.WARN -> "W"
26
+ else -> "I"
27
+ }
28
+ try {
29
+ sink?.invoke("[$level/$tag] $text")
30
+ } catch (_: Throwable) {
31
+ // A log line must never break the media path that wrote it.
32
+ }
33
+ return result
34
+ }
35
+ }
package/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /** Print glasses-media's and acs-meeting's native logs to the console, which bug reports upload. Idempotent. */
2
+ export function installNativeLogConsole(): void
3
+
1
4
  /** Shared native association owner for the local glasses hotspot. */
2
5
  export const glassesHotspot: {
3
6
  join(
package/index.js CHANGED
@@ -3,6 +3,23 @@
3
3
  // Load only when this transport is requested. Importing the package does not
4
4
  // start a native session or require Expo's application entry point.
5
5
  const native = () => require("expo-modules-core").requireNativeModule("MentraGlassesMediaRelay")
6
+
7
+ // Native relay, ingest, SoftAP and ACS traces go to the console, which bug reports upload.
8
+ // The module survives Fast Refresh, so a reload replaces the previous subscription.
9
+ const logSubscriptionKey = Symbol.for("mentra.glasses-media.native-log-console")
10
+ const credential =
11
+ /(?<![A-Za-z0-9])(?:token|password|passphrase|secret|authorization|key)(?![A-Za-z0-9])\s*["']?\s*[:=]\s*["']?\S+|(?<![A-Za-z0-9])bearer\s+\S+/i
12
+ // The host calls this at startup: with Metro's inline requires, importing this package
13
+ // does not run its body until something here is used.
14
+ export function installNativeLogConsole() {
15
+ const logSource = require("expo-modules-core").requireOptionalNativeModule("MentraGlassesMediaRelay")
16
+ if (!logSource) return
17
+ logSource[logSubscriptionKey]?.remove()
18
+ logSource[logSubscriptionKey] = logSource.addListener("onNativeLog", ({message}) => {
19
+ console.log("[native:glasses-media]", credential.test(message) ? "[REDACTED]" : message.slice(0, 16_384))
20
+ })
21
+ }
22
+
6
23
  export const glassesHotspot = Object.freeze({
7
24
  join: (id, ssid, password, gateway, purpose = "outgoing-client") =>
8
25
  native().joinLocalHotspot(id, ssid, password, gateway ?? null, purpose),
@@ -2,11 +2,9 @@ import Darwin
2
2
  import Foundation
3
3
  import Network
4
4
  import NetworkExtension
5
- import OSLog
6
5
 
7
6
  /// Shared hotspot association owner. Only local glasses traffic uses Wi-Fi.
8
7
  public final class GlassesHotspotNetwork {
9
- private let logger = Logger(subsystem: "com.mentra.glassesmedia", category: "hotspot")
10
8
  private let queue = DispatchQueue(label: "com.mentra.glassesmedia.hotspot")
11
9
  private var ssid: String?
12
10
  private var lastHotspotSSID: String?
@@ -333,7 +331,7 @@ public final class GlassesHotspotNetwork {
333
331
  applying = true
334
332
  ownsConfiguration = true
335
333
  applies += 1
336
- logger.info("HOTSPOT_JOIN apply_start attempt=\(self.applies) ios_on_mac=\(ProcessInfo.processInfo.isiOSAppOnMac)")
334
+ MediaLog.log("HOTSPOT_JOIN apply_start attempt=\(self.applies) ios_on_mac=\(ProcessInfo.processInfo.isiOSAppOnMac)")
337
335
  NEHotspotConfigurationManager.shared.apply(config) { error in
338
336
  self.queue.async {
339
337
  guard gen == self.generation else { return }
@@ -346,11 +344,11 @@ public final class GlassesHotspotNetwork {
346
344
  if !alreadyAssociated {
347
345
  // Error identifiers are useful without credentials or full userInfo.
348
346
  let underlying = nativeError.userInfo[NSUnderlyingErrorKey] as? NSError
349
- self.logger.error("HOTSPOT_JOIN apply_failed domain=\(nativeError.domain, privacy: .public) code=\(nativeError.code) underlying_domain=\(underlying?.domain ?? "none", privacy: .public) underlying_code=\(underlying.map { String($0.code) } ?? "none", privacy: .public)")
347
+ MediaLog.log("HOTSPOT_JOIN apply_failed domain=\(nativeError.domain) code=\(nativeError.code) underlying_domain=\(underlying?.domain ?? "none") underlying_code=\(underlying.map { String($0.code) } ?? "none")")
350
348
  self.finishJoin(.failure(error)); self.finishLeave(); return
351
349
  }
352
350
  }
353
- self.logger.info("HOTSPOT_JOIN apply_accepted")
351
+ MediaLog.log("HOTSPOT_JOIN apply_accepted")
354
352
  self.waitForAddress(ssid: ssid, passphrase: passphrase, generation: gen, remaining: remaining, pollsSinceApply: 0)
355
353
  }
356
354
  }
@@ -368,7 +366,7 @@ public final class GlassesHotspotNetwork {
368
366
  } else if remaining > 0, network?.ssid != ssid,
369
367
  self.reapplyPolicy.shouldReapply(applies: self.applies, pollsSinceApply: pollsSinceApply) {
370
368
  // iOS reports the request applied even when its one scan missed the hotspot.
371
- self.logger.info("HOTSPOT_JOIN reapply after_polls=\(pollsSinceApply)")
369
+ MediaLog.log("HOTSPOT_JOIN reapply after_polls=\(pollsSinceApply)")
372
370
  self.applyConfiguration(ssid: ssid, passphrase: passphrase, generation: gen, remaining: remaining)
373
371
  } else if remaining > 0 {
374
372
  self.queue.asyncAfter(deadline: .now() + 0.5) {
@@ -431,7 +429,7 @@ public final class GlassesHotspotNetwork {
431
429
  let evidence = wifiIdentity.trusted[selected.interface] == selected.index ? "wifi_report" : "hotspot_client"
432
430
  wifiIdentity.adopt(selected)
433
431
  binding = selected
434
- logger.info("HOTSPOT_JOIN address_verified interface=\(selected.interface, privacy: .public) evidence=\(evidence, privacy: .public)")
432
+ MediaLog.log("HOTSPOT_JOIN address_verified interface=\(selected.interface) evidence=\(evidence)")
435
433
  }
436
434
 
437
435
  /// Interface names and their IPv4 addresses only; never credentials or SSIDs.
@@ -463,13 +461,13 @@ public final class GlassesHotspotNetwork {
463
461
  localAccess = request
464
462
  request.start(onPermissionRequired: { [weak self] in
465
463
  guard let self, gen == generation, !cancelled else { return }
466
- NSLog("GLASSES-MEDIA local_network_permission=waiting")
464
+ MediaLog.log("GLASSES-MEDIA local_network_permission=waiting")
467
465
  onPermissionRequired?()
468
466
  }) { [weak self] result in
469
467
  guard let self, gen == generation, !cancelled else { return }
470
468
  switch result {
471
469
  case .success:
472
- NSLog("GLASSES-MEDIA local_network_permission=ready")
470
+ MediaLog.log("GLASSES-MEDIA local_network_permission=ready")
473
471
  finishJoin(.success(address))
474
472
  case let .failure(error):
475
473
  finishJoin(.failure(error))
@@ -542,7 +540,7 @@ public final class GlassesHotspotNetwork {
542
540
  // bounded observation ends. Route readiness is not HTTP success;
543
541
  // the following ordinary update check still owns that result.
544
542
  startInternetObservation(allowWifiAfterRelease: true) { ready, reason in
545
- self.logger.info("HOTSPOT_LEAVE internet_recovery ready=\(ready) reason=\(reason, privacy: .public)")
543
+ MediaLog.log("HOTSPOT_LEAVE internet_recovery ready=\(ready) reason=\(reason)")
546
544
  finish()
547
545
  }
548
546
  } else { finish() }
@@ -9,7 +9,11 @@ public final class GlassesMediaRelayModule: Module {
9
9
 
10
10
  public func definition() -> ModuleDefinition {
11
11
  Name("MentraGlassesMediaRelay")
12
- Events("onRelayState", "onLocalHotspotPermissionRequired")
12
+ Events("onRelayState", "onLocalHotspotPermissionRequired", "onNativeLog")
13
+
14
+ OnCreate {
15
+ MediaLog.sink = { [weak self] message in self?.sendEvent("onNativeLog", ["message": message]) }
16
+ }
13
17
 
14
18
  AsyncFunction("joinLocalHotspot") { (id: String, ssid: String, password: String, gateway: String?, purpose: String, promise: Promise) in
15
19
  self.queue.async {
@@ -92,6 +96,7 @@ public final class GlassesMediaRelayModule: Module {
92
96
  }
93
97
 
94
98
  OnDestroy {
99
+ MediaLog.sink = nil
95
100
  self.queue.async {
96
101
  self.session?.stop { result in
97
102
  if case .success = result { self.session = nil }
@@ -90,7 +90,7 @@ public final class LocalWhipIngestSource: NSObject, DecodedGlassesMediaSource {
90
90
  }
91
91
  self.forceCloseIngestLocked()
92
92
  let closed = self.awaitIngestClosedLocked(timeoutMs: timeoutMs)
93
- NSLog("SOFTAP_TRACE stage=ingest_rebind oldUrl=\(oldUrl ?? "none") newUrl=\(newUrl) closed=\(closed)")
93
+ MediaLog.log("SOFTAP_TRACE stage=ingest_rebind oldUrl=\(oldUrl ?? "none") newUrl=\(newUrl) closed=\(closed)")
94
94
  if !closed {
95
95
  completion(.failure(LocalMediaError("SoftAP ingest rebind did not release the old listener")))
96
96
  return
@@ -350,7 +350,7 @@ public final class LocalWhipIngestSource: NSObject, DecodedGlassesMediaSource {
350
350
  private func transition(_ state: SourceState, _ reason: String) {
351
351
  guard currentState != state else { return }
352
352
  currentState = state
353
- NSLog("GLASSES-MEDIA source=\(state.rawValue) reason=\(reason)")
353
+ MediaLog.log("GLASSES-MEDIA source=\(state.rawValue) reason=\(reason)")
354
354
  onStateChange?(state, reason)
355
355
  }
356
356
  }
@@ -0,0 +1,13 @@
1
+ import Foundation
2
+
3
+ /// The console plus the app's JavaScript console, which bug reports upload. glasses-media and
4
+ /// acs-meeting log through it, so the hotspot, relay, ingest and ACS traces reach a report.
5
+ public enum MediaLog {
6
+ /// Set by `GlassesMediaRelayModule` while it exists.
7
+ public static var sink: ((String) -> Void)?
8
+
9
+ public static func log(_ message: String) {
10
+ NSLog("%@", message)
11
+ sink?(message)
12
+ }
13
+ }
@@ -103,7 +103,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
103
103
  /// networks; ICE may not have noticed the dead candidate pair yet).
104
104
  public func forceRestart() {
105
105
  guard let url = currentUrl else { return }
106
- NSLog("ACS-SPIKE WHEP forced rebuild state=\(state.rawValue)")
106
+ MediaLog.log("ACS-SPIKE WHEP forced rebuild state=\(state.rawValue)")
107
107
  start(whepUrl: url)
108
108
  }
109
109
 
@@ -118,7 +118,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
118
118
  public func setPcmEnabled(_ enabled: Bool) {
119
119
  pcmEnabled = enabled
120
120
  audioTracks.forEach { $0.isEnabled = enabled }
121
- NSLog("ACS-SPIKE WHEP audio track enabled=\(enabled)")
121
+ MediaLog.log("ACS-SPIKE WHEP audio track enabled=\(enabled)")
122
122
  }
123
123
 
124
124
  public func stop() {
@@ -149,7 +149,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
149
149
  let previous = state
150
150
  state = next
151
151
  guard previous != next else { return }
152
- NSLog("ACS-SPIKE WHEP source \(previous.rawValue) -> \(next.rawValue) (\(reason))")
152
+ MediaLog.log("ACS-SPIKE WHEP source \(previous.rawValue) -> \(next.rawValue) (\(reason))")
153
153
  onStateChange?(next, reason)
154
154
  }
155
155
 
@@ -193,11 +193,11 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
193
193
  http.dataTask(with: request) { [weak self] data, response, error in
194
194
  guard let self, self.generation == gen else { return }
195
195
  let code = (response as? HTTPURLResponse)?.statusCode ?? -1
196
- NSLog("ACS-SPIKE P3 WHEP \(code) answer bytes=\(data?.count ?? 0)")
196
+ MediaLog.log("ACS-SPIKE P3 WHEP \(code) answer bytes=\(data?.count ?? 0)")
197
197
  guard error == nil, (200 ..< 300).contains(code),
198
198
  let data, let answer = String(data: data, encoding: .utf8)
199
199
  else {
200
- NSLog("ACS-SPIKE WHEP answer rejected code=\(code) error=\(error?.localizedDescription ?? "none")")
200
+ MediaLog.log("ACS-SPIKE WHEP answer rejected code=\(code) error=\(error?.localizedDescription ?? "none")")
201
201
  self.transition(.failed, reason: error != nil ? "whep_post_failed" : "whep_http_\(code)")
202
202
  return
203
203
  }
@@ -221,7 +221,7 @@ public final class WhepVideoSource: NSObject, DecodedGlassesMediaSource {
221
221
  guard let self else { return }
222
222
  self.firstFrameDeadline = nil
223
223
  guard self.generation == gen, self.firstFrameGeneration == gen, !self.firstFramePromoted else { return }
224
- NSLog("ACS-SPIKE WHEP answered but delivered no frame in \(Self.firstFrameTimeout)s")
224
+ MediaLog.log("ACS-SPIKE WHEP answered but delivered no frame in \(Self.firstFrameTimeout)s")
225
225
  self.transition(.failed, reason: "no_first_frame")
226
226
  }
227
227
  firstFrameDeadline = work
@@ -261,7 +261,7 @@ extension WhepVideoSource: RTCPeerConnectionDelegate {
261
261
  public func peerConnection(_: RTCPeerConnection, didRemove _: RTCMediaStream) {}
262
262
  public func peerConnectionShouldNegotiate(_: RTCPeerConnection) {}
263
263
  public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
264
- NSLog("ACS-SPIKE ICE \(newState.rawValue)")
264
+ MediaLog.log("ACS-SPIKE ICE \(newState.rawValue)")
265
265
  guard isCurrent(peerConnection) else { return }
266
266
  if newState == .failed || newState == .disconnected {
267
267
  transition(.failed, reason: newState == .failed ? "ice_failed" : "ice_disconnected")
@@ -305,7 +305,7 @@ extension WhepVideoSource: RTCVideoRenderer {
305
305
  frameCount += 1
306
306
  let now = Date()
307
307
  if now.timeIntervalSince(lastFpsLog) >= 1 {
308
- NSLog("ACS-SPIKE P3 video \(Int(frame.width))x\(Int(frame.height)) fps=\(frameCount)")
308
+ MediaLog.log("ACS-SPIKE P3 video \(Int(frame.width))x\(Int(frame.height)) fps=\(frameCount)")
309
309
  frameCount = 0
310
310
  lastFpsLog = now
311
311
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/glasses-media",
3
- "version": "3.5.0-dev.1271",
3
+ "version": "3.5.0-dev.1276",
4
4
  "description": "Shared native glasses media receivers and local network transport",
5
5
  "license": "MIT",
6
6
  "author": "Mentra Community",
@@ -15,6 +15,9 @@
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
+ "dependencies": {
19
+ "@mentra/bluetooth-sdk": "3.5.0-dev.1276"
20
+ },
18
21
  "peerDependencies": {
19
22
  "expo-modules-core": "~55.0.25"
20
23
  },
@@ -1,51 +0,0 @@
1
- package com.mentra.glassesmedia.network
2
-
3
- /**
4
- * An IPv4 subnet, taken from the phone's own address on a joined network.
5
- *
6
- * SoftAP correctness is an interface question, not an address-range question: the media path is
7
- * right when the selected candidate sits on the network we joined, and wrong otherwise. Matching
8
- * "looks RFC1918" or "starts with 192.168.43" answers a different question and stops being true the
9
- * moment an OEM picks another hotspot subnet, so every SoftAP check compares against the prefix
10
- * `LinkProperties` actually reported.
11
- */
12
- data class Ipv4Prefix(val address: String, val prefixLength: Int) {
13
-
14
- private val network: Int? = packIpv4(address)?.let { it and maskFor(prefixLength) }
15
-
16
- /** True when [candidate] is a dotted-quad IPv4 address inside this prefix. */
17
- fun contains(candidate: String?): Boolean {
18
- val base = network ?: return false
19
- val value = packIpv4(candidate) ?: return false
20
- return (value and maskFor(prefixLength)) == base
21
- }
22
-
23
- override fun toString(): String = "$address/$prefixLength"
24
-
25
- companion object {
26
- /**
27
- * Dotted-quad to a packed int, or null when [token] is not one. Deliberately strict: a
28
- * token like `192.168.43` or `candidate:1` must not be read as an address, because the
29
- * callers scan whitespace-split SDP lines where most tokens are not addresses at all.
30
- */
31
- fun packIpv4(token: String?): Int? {
32
- val text = token ?: return null
33
- val octets = text.split('.')
34
- if (octets.size != 4) return null
35
- var packed = 0
36
- for (octet in octets) {
37
- if (octet.isEmpty() || octet.length > 3) return null
38
- val value = octet.toIntOrNull() ?: return null
39
- if (value < 0 || value > 255) return null
40
- packed = (packed shl 8) or value
41
- }
42
- return packed
43
- }
44
-
45
- /** A /0 masks nothing; Kotlin's `shl 32` is a no-op, so that case is spelled out. */
46
- private fun maskFor(prefixLength: Int): Int {
47
- val bits = prefixLength.coerceIn(0, 32)
48
- return if (bits == 0) 0 else (-1 shl (32 - bits))
49
- }
50
- }
51
- }