@mentra/glasses-media 3.5.0-dev.1270 → 3.5.0-dev.1274

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.
@@ -6,7 +6,8 @@ import android.os.Looper
6
6
  import android.os.PowerManager
7
7
  import android.provider.Settings
8
8
  import android.util.Base64
9
- import android.util.Log
9
+ import com.mentra.glassesmedia.trace.MediaLog
10
+ import com.mentra.glassesmedia.trace.MediaLog as Log
10
11
  import com.mentra.glassesmedia.network.*
11
12
  import com.mentra.glassesmedia.publisher.PhoneWhipPublisher
12
13
  import com.mentra.glassesmedia.publisher.RelayPcmInput
@@ -29,7 +30,9 @@ class GlassesMediaRelayModule : Module() {
29
30
 
30
31
  override fun definition() = ModuleDefinition {
31
32
  Name("MentraGlassesMediaRelay")
32
- Events("onRelayState")
33
+ Events("onRelayState", "onNativeLog")
34
+
35
+ OnCreate { MediaLog.sink = { message -> sendEvent("onNativeLog", mapOf("message" to message)) } }
33
36
 
34
37
  AsyncFunction("prepare") { options: Map<String, Any?>, promise: Promise ->
35
38
  worker.execute {
@@ -102,7 +105,10 @@ class GlassesMediaRelayModule : Module() {
102
105
  }
103
106
  }
104
107
 
105
- OnDestroy { worker.execute { runCatching { cleanup() }; worker.shutdown() } }
108
+ OnDestroy {
109
+ MediaLog.sink = null
110
+ worker.execute { runCatching { cleanup() }; worker.shutdown() }
111
+ }
106
112
  }
107
113
 
108
114
  private fun emit(id: String, state: String, reason: String) {
@@ -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
@@ -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.network.NetworkFacts
7
7
  import com.mentra.glassesmedia.network.ScopedNetworkChangeDetector
8
8
  import com.mentra.glassesmedia.network.ScopedSoftApNetwork
@@ -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,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.trace.SoftApTrace
5
5
  import java.io.BufferedInputStream
6
6
  import java.io.BufferedOutputStream
@@ -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
+ }
@@ -1,7 +1,7 @@
1
1
  package com.mentra.glassesmedia.trace
2
2
 
3
3
  import android.os.SystemClock
4
- import android.util.Log
4
+ import com.mentra.glassesmedia.trace.MediaLog as Log
5
5
 
6
6
  /**
7
7
  * Correlated stage logging for the SoftAP calling pipeline (phone side).
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(
@@ -8,4 +11,6 @@ export const glassesHotspot: {
8
11
  purpose?: "outgoing-client" | "incoming-server",
9
12
  ): Promise<string>
10
13
  leave(id: string, waitForInternet?: boolean): Promise<void>
14
+ /** A join with this id is waiting for Local Network access, which the person may have denied. */
15
+ onPermissionRequired(listener: (id: string) => void): {remove(): void}
11
16
  }
package/index.js CHANGED
@@ -3,8 +3,27 @@
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),
9
26
  leave: (id, waitForInternet = false) => native().leaveLocalHotspot(id, waitForInternet),
27
+ onPermissionRequired: (listener) =>
28
+ native().addListener("onLocalHotspotPermissionRequired", (event) => listener(event.id)),
10
29
  })
@@ -13,6 +13,10 @@ public struct HotspotJoinFailure {
13
13
  code = "ERR_HOTSPOT_JOIN"
14
14
  // These messages are authored by the owned hotspot implementation, not NSError.
15
15
  message = String(local.message.filter { !$0.unicodeScalars.contains(where: CharacterSet.controlCharacters.contains) }.prefix(512))
16
+ } else if (error as NSError).domain == "NEHotspotConfigurationErrorDomain", (error as NSError).code == 7 {
17
+ // NEHotspotConfigurationError.userDenied: the person declined the join prompt.
18
+ code = "ERR_HOTSPOT_USER_DENIED"
19
+ message = "The glasses hotspot join was declined"
16
20
  } else {
17
21
  code = "ERR_HOTSPOT_NATIVE"
18
22
  let native = error as NSError
@@ -9,7 +9,7 @@ public final class GlassesMediaRelayModule: Module {
9
9
 
10
10
  public func definition() -> ModuleDefinition {
11
11
  Name("MentraGlassesMediaRelay")
12
- Events("onRelayState")
12
+ Events("onRelayState", "onLocalHotspotPermissionRequired")
13
13
 
14
14
  AsyncFunction("joinLocalHotspot") { (id: String, ssid: String, password: String, gateway: String?, purpose: String, promise: Promise) in
15
15
  self.queue.async {
@@ -20,6 +20,10 @@ public final class GlassesMediaRelayModule: Module {
20
20
  promise.reject(LocalMediaError("Invalid hotspot access purpose")); return
21
21
  }
22
22
  self.localHotspotOwner = id
23
+ // The join waits while Local Network access is pending or denied; the caller explains it.
24
+ self.localHotspot.onPermissionRequired = { [weak self] in
25
+ self?.sendEvent("onLocalHotspotPermissionRequired", ["id": id])
26
+ }
23
27
  self.localHotspot.join(ssid: ssid, passphrase: password, gateway: gateway, purpose: accessPurpose) { result in
24
28
  switch result {
25
29
  case let .success(address): promise.resolve(address)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/glasses-media",
3
- "version": "3.5.0-dev.1270",
3
+ "version": "3.5.0-dev.1274",
4
4
  "description": "Shared native glasses media receivers and local network transport",
5
5
  "license": "MIT",
6
6
  "author": "Mentra Community",