@glassly/bluetooth-sdk 0.1.0-dev.26
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/README.md +563 -0
- package/android/build.gradle +450 -0
- package/android/gradle.properties.example +9 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +212 -0
- package/android/lc3Lib/proguard-rules.pro +33 -0
- package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
- package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
- package/android/lc3Lib/src/main/java/com/glassly/lc3Lib/Lc3Cpp.java +38 -0
- package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
- package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
- package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
- package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
- package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
- package/android/settings.gradle +4 -0
- package/android/silero/LICENSE.md +17 -0
- package/android/silero/build.gradle +50 -0
- package/android/silero/proguard-rules.pro +24 -0
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +79 -0
- package/android/silero/src/main/assets/LICENSE +21 -0
- package/android/silero/src/main/assets/silero_vad.onnx +0 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +160 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +449 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +15 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +14 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +12 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +47 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +41 -0
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +44 -0
- package/android/src/main/AndroidManifest.xml +42 -0
- package/android/src/main/assets/G2Firmware/README.md +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdk.kt +2325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkAnalytics.kt +216 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDebug.kt +14 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDefaults.kt +7 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkModule.kt +1088 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/Bridge.kt +953 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceManager.kt +2528 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceStore.kt +360 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedChangelogCatalog.kt +8 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedReleaseMetadata.kt +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/LocalNetworkModule.kt +414 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ObservableStore.kt +88 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/OtaManifest.kt +191 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ReleaseChangelog.kt +61 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ScopedNetworkReadiness.kt +17 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/audio/AudioModels.kt +144 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/camera/CameraModels.kt +486 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/connection/ConnectionModels.kt +78 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/R1.kt +937 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/debug/BleTraceLogger.kt +165 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/events/BluetoothEvents.kt +178 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/internal/MapParsing.kt +140 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/net/LocalIpv4.kt +57 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServer.kt +304 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/OtaServerModule.kt +120 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistry.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoUploadServer.kt +622 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/PhotoReceiverModule.kt +156 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/requests/DisplayRequests.kt +56 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/Foreground.kt +272 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/PhoneMic.kt +1195 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Ar99.java +2653 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuard.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapper.kt +27 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1.kt +3878 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizer.kt +38 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2.kt +6428 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassification.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwRenderer.kt +1241 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCache.kt +270 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocol.kt +291 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2Flasher.kt +411 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/GlasslyBle.java +43189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Mach1.kt +1280 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLive.kt +10817 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLiveL2capChannel.kt +274 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +54 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraNex.kt +2011 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Nimo.kt +2532 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/SGCManager.kt +470 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Simulated.kt +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/Ar99OtaManager.java +566 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaByteUtils.java +18 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCommandConstants.java +35 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCrc32Util.java +13 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaGattTransport.java +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaProtocol.java +92 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/speakerid/SpeakerIdEngine.kt +525 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/DeviceStatus.kt +669 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/RuntimeState.kt +201 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/WifiHotspotStatus.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/streaming/StreamModels.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/STTTools.kt +391 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/VadGateSpeechPolicy.kt +229 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/tts/TTSTools.kt +248 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/types/DeviceModels.kt +96 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AvifExifStripper.java +573 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleJsonCompact.java +496 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadService.java +677 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleWireProtocol.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/Constants.kt +46 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/HeifExifTagReader.java +199 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleUploadService.java +77 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900LengthCodec.java +115 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtils.java +827 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunkReassembler.java +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunker.java +325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/NexSGCUtils.kt +698 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitor.kt +348 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Ar99OpusPcmDecoder.java +398 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +328 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/BluetoothSdkExceptionTest.kt +18 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaManifestDowngradeTest.kt +86 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaStartResponsePolicyTest.kt +30 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ReleaseChangelogTest.kt +13 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ScopedNetworkReadinessTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/StreamStatusEventTest.kt +29 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/camera/PhotoRequestTest.kt +141 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServerTest.kt +82 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistryTest.java +75 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/services/ForegroundServiceTypeTest.kt +69 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/Ar99AdvertisementMatcherTest.java +22 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuardTest.kt +73 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapperTest.kt +67 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/EvenRleTest.kt +63 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +31 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassificationTest.kt +89 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwRendererTest.kt +344 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCacheTest.kt +200 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocolTest.kt +131 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLiveGattCharacteristicsTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +133 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/NimoProtocolTest.kt +333 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/AvifExifStripperTest.java +46 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BinaryMessageChunkerTest.java +84 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BleJsonCompactTest.java +319 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadServiceTest.java +107 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsEndiannessTest.java +172 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsTest.java +24 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitorTest.kt +45 -0
- package/android/src/test/resources/avif_with_exif.avif +0 -0
- package/app.plugin.js +3 -0
- package/build/BluetoothSdk.types.d.ts +1354 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +41 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/_internal.d.ts +17 -0
- package/build/_internal.d.ts.map +1 -0
- package/build/_internal.js +16 -0
- package/build/_internal.js.map +1 -0
- package/build/_private/BluetoothSdkModule.d.ts +172 -0
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -0
- package/build/_private/BluetoothSdkModule.js +300 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -0
- package/build/_private/LocalNetworkModule.d.ts +38 -0
- package/build/_private/LocalNetworkModule.d.ts.map +1 -0
- package/build/_private/LocalNetworkModule.js +3 -0
- package/build/_private/LocalNetworkModule.js.map +1 -0
- package/build/_private/cameraRequestPayload.d.ts +4 -0
- package/build/_private/cameraRequestPayload.d.ts.map +1 -0
- package/build/_private/cameraRequestPayload.js +32 -0
- package/build/_private/cameraRequestPayload.js.map +1 -0
- package/build/_private/photoRequestPayload.d.ts +6 -0
- package/build/_private/photoRequestPayload.d.ts.map +1 -0
- package/build/_private/photoRequestPayload.js +86 -0
- package/build/_private/photoRequestPayload.js.map +1 -0
- package/build/_private/sdkOtaManifest.d.ts +11 -0
- package/build/_private/sdkOtaManifest.d.ts.map +1 -0
- package/build/_private/sdkOtaManifest.js +15 -0
- package/build/_private/sdkOtaManifest.js.map +1 -0
- package/build/changelogs.d.ts +7 -0
- package/build/changelogs.d.ts.map +1 -0
- package/build/changelogs.js +46 -0
- package/build/changelogs.js.map +1 -0
- package/build/debug.d.ts +3 -0
- package/build/debug.d.ts.map +1 -0
- package/build/debug.js +8 -0
- package/build/debug.js.map +1 -0
- package/build/generated/changelogCatalog.d.ts +9 -0
- package/build/generated/changelogCatalog.d.ts.map +1 -0
- package/build/generated/changelogCatalog.js +12 -0
- package/build/generated/changelogCatalog.js.map +1 -0
- package/build/generated/releaseMetadata.d.ts +12 -0
- package/build/generated/releaseMetadata.d.ts.map +1 -0
- package/build/generated/releaseMetadata.js +10 -0
- package/build/generated/releaseMetadata.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +171 -0
- package/build/index.js.map +1 -0
- package/build/ota-server/OtaServer.types.d.ts +14 -0
- package/build/ota-server/OtaServer.types.d.ts.map +1 -0
- package/build/ota-server/OtaServer.types.js +2 -0
- package/build/ota-server/OtaServer.types.js.map +1 -0
- package/build/ota-server/OtaServerModule.d.ts +21 -0
- package/build/ota-server/OtaServerModule.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.js +3 -0
- package/build/ota-server/OtaServerModule.js.map +1 -0
- package/build/ota-server/OtaServerModule.web.d.ts +10 -0
- package/build/ota-server/OtaServerModule.web.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.web.js +12 -0
- package/build/ota-server/OtaServerModule.web.js.map +1 -0
- package/build/ota-server/index.d.ts +3 -0
- package/build/ota-server/index.d.ts.map +1 -0
- package/build/ota-server/index.js +3 -0
- package/build/ota-server/index.js.map +1 -0
- package/build/ota-transport/index.d.ts +67 -0
- package/build/ota-transport/index.d.ts.map +1 -0
- package/build/ota-transport/index.js +58 -0
- package/build/ota-transport/index.js.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts +18 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.js +2 -0
- package/build/photo-receiver/PhotoReceiver.types.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.js +3 -0
- package/build/photo-receiver/PhotoReceiverModule.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js +12 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js.map +1 -0
- package/build/photo-receiver/index.d.ts +3 -0
- package/build/photo-receiver/index.d.ts.map +1 -0
- package/build/photo-receiver/index.js +3 -0
- package/build/photo-receiver/index.js.map +1 -0
- package/build/react/index.d.ts +5 -0
- package/build/react/index.d.ts.map +1 -0
- package/build/react/index.js +4 -0
- package/build/react/index.js.map +1 -0
- package/build/react/useBluetooth.d.ts +100 -0
- package/build/react/useBluetooth.d.ts.map +1 -0
- package/build/react/useBluetooth.js +167 -0
- package/build/react/useBluetooth.js.map +1 -0
- package/build/react/useBluetoothEvent.d.ts +6 -0
- package/build/react/useBluetoothEvent.d.ts.map +1 -0
- package/build/react/useBluetoothEvent.js +21 -0
- package/build/react/useBluetoothEvent.js.map +1 -0
- package/build/react/useBluetoothScan.d.ts +22 -0
- package/build/react/useBluetoothScan.d.ts.map +1 -0
- package/build/react/useBluetoothScan.js +135 -0
- package/build/react/useBluetoothScan.js.map +1 -0
- package/build/react/useBluetoothStatus.d.ts +16 -0
- package/build/react/useBluetoothStatus.d.ts.map +1 -0
- package/build/react/useBluetoothStatus.js +137 -0
- package/build/react/useBluetoothStatus.js.map +1 -0
- package/build/react/useGlassesConnection.d.ts +29 -0
- package/build/react/useGlassesConnection.d.ts.map +1 -0
- package/build/react/useGlassesConnection.js +153 -0
- package/build/react/useGlassesConnection.js.map +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +2 -0
- package/build/types/index.js.map +1 -0
- package/expo-module.config.json +14 -0
- package/ios/BackgroundOtaArtifactDownloader.swift +125 -0
- package/ios/BluetoothSdkModule.swift +1034 -0
- package/ios/GlasslyBluetoothSDK.podspec +106 -0
- package/ios/LocalIPv4.swift +150 -0
- package/ios/LocalOtaServer.swift +309 -0
- package/ios/LocalPhotoUploadServer.swift +754 -0
- package/ios/OtaServerModule.swift +147 -0
- package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
- package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
- package/ios/Packages/CoreObjC/attdet.c +92 -0
- package/ios/Packages/CoreObjC/attdet.h +44 -0
- package/ios/Packages/CoreObjC/bits.c +375 -0
- package/ios/Packages/CoreObjC/bits.h +315 -0
- package/ios/Packages/CoreObjC/bwdet.c +129 -0
- package/ios/Packages/CoreObjC/bwdet.h +69 -0
- package/ios/Packages/CoreObjC/common.h +151 -0
- package/ios/Packages/CoreObjC/energy.c +70 -0
- package/ios/Packages/CoreObjC/energy.h +43 -0
- package/ios/Packages/CoreObjC/fastmath.h +158 -0
- package/ios/Packages/CoreObjC/include/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/lc3.c +704 -0
- package/ios/Packages/CoreObjC/lc3.h +313 -0
- package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
- package/ios/Packages/CoreObjC/lc3_private.h +163 -0
- package/ios/Packages/CoreObjC/ltpf.c +905 -0
- package/ios/Packages/CoreObjC/ltpf.h +111 -0
- package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
- package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
- package/ios/Packages/CoreObjC/makefile.mk +35 -0
- package/ios/Packages/CoreObjC/mdct.c +469 -0
- package/ios/Packages/CoreObjC/mdct.h +57 -0
- package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
- package/ios/Packages/CoreObjC/meson.build +61 -0
- package/ios/Packages/CoreObjC/plc.c +61 -0
- package/ios/Packages/CoreObjC/plc.h +57 -0
- package/ios/Packages/CoreObjC/rnnoise.h +114 -0
- package/ios/Packages/CoreObjC/sns.c +880 -0
- package/ios/Packages/CoreObjC/sns.h +103 -0
- package/ios/Packages/CoreObjC/spec.c +907 -0
- package/ios/Packages/CoreObjC/spec.h +119 -0
- package/ios/Packages/CoreObjC/tables.c +3457 -0
- package/ios/Packages/CoreObjC/tables.h +94 -0
- package/ios/Packages/CoreObjC/tns.c +457 -0
- package/ios/Packages/CoreObjC/tns.h +99 -0
- package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
- package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +2383 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +48 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/PhotoReceiverModule.swift +129 -0
- package/ios/Source/BluetoothSDK.swift +2303 -0
- package/ios/Source/BluetoothSDKDebug.swift +12 -0
- package/ios/Source/BluetoothSdkDefaults.swift +29 -0
- package/ios/Source/Bridge.swift +708 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +2109 -0
- package/ios/Source/DeviceStore.swift +336 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +7 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +11 -0
- package/ios/Source/ObservableStore.swift +118 -0
- package/ios/Source/OtaManifest.swift +211 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/ReleaseChangelog.swift +65 -0
- package/ios/Source/Resources/G2Firmware/README.md +10 -0
- package/ios/Source/audio/AudioModels.swift +178 -0
- package/ios/Source/audio/PcmStreamPlayer.swift +410 -0
- package/ios/Source/camera/CameraModels.swift +866 -0
- package/ios/Source/connection/ScanSession.swift +27 -0
- package/ios/Source/controllers/ControllerManager.swift +184 -0
- package/ios/Source/controllers/R1.swift +829 -0
- package/ios/Source/errors/BluetoothSdkError.swift +19 -0
- package/ios/Source/events/BluetoothEvents.swift +342 -0
- package/ios/Source/internal/BleTraceLogger.swift +192 -0
- package/ios/Source/internal/BluetoothAvailability.swift +78 -0
- package/ios/Source/internal/BluetoothSdkAnalytics.swift +199 -0
- package/ios/Source/internal/ValueParsing.swift +99 -0
- package/ios/Source/requests/DisplayRequests.swift +82 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Ar99.swift +2451 -0
- package/ios/Source/sgcs/Frame.swift +649 -0
- package/ios/Source/sgcs/G1.swift +2554 -0
- package/ios/Source/sgcs/G2.swift +6887 -0
- package/ios/Source/sgcs/G2CfwClassification.swift +43 -0
- package/ios/Source/sgcs/G2CfwRenderer.swift +1279 -0
- package/ios/Source/sgcs/G2CfwTextureCache.swift +233 -0
- package/ios/Source/sgcs/G2FlashProtocol.swift +312 -0
- package/ios/Source/sgcs/G2Flasher.swift +773 -0
- package/ios/Source/sgcs/Mach1.swift +541 -0
- package/ios/Source/sgcs/MentraLive.swift +7011 -0
- package/ios/Source/sgcs/MentraLiveL2capChannel.swift +183 -0
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +64 -0
- package/ios/Source/sgcs/MentraNex.swift +3221 -0
- package/ios/Source/sgcs/Nimo.swift +1886 -0
- package/ios/Source/sgcs/SGCManager.swift +608 -0
- package/ios/Source/sgcs/Simulated.swift +274 -0
- package/ios/Source/sgcs/ar99/ota/Ar99OtaManager.swift +637 -0
- package/ios/Source/sgcs/glassly_ble.pb.swift +4354 -0
- package/ios/Source/speakerid/SpeakerIdEngine.swift +573 -0
- package/ios/Source/status/DeviceStatus.swift +981 -0
- package/ios/Source/status/RuntimeState.swift +359 -0
- package/ios/Source/status/WifiHotspotStatus.swift +345 -0
- package/ios/Source/streaming/StreamModels.swift +693 -0
- package/ios/Source/stt/STTTools.swift +191 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +466 -0
- package/ios/Source/tts/TTSTools.swift +171 -0
- package/ios/Source/types/DeviceModels.swift +177 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/BinaryCodec.swift +61 -0
- package/ios/Source/utils/BleJsonCompact.swift +405 -0
- package/ios/Source/utils/BleWireProtocol.swift +92 -0
- package/ios/Source/utils/Constants.swift +78 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2096 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunkReassembler.swift +190 -0
- package/ios/Source/utils/MessageChunker.swift +294 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +230 -0
- package/ios/Source/utils/TarBz2Extractor.swift +257 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwClassificationTests.swift +78 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwRendererTests.swift +372 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwTextureCacheTests.swift +162 -0
- package/ios/Tests/BluetoothSDKTests/G2FlashProtocolTests.swift +182 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +160 -0
- package/ios/Tests/ReleaseChangelogTests.swift +13 -0
- package/package.json +129 -0
- package/plugin/build/index.d.ts +10 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +3 -0
- package/plugin/build/withAndroid.js +190 -0
- package/plugin/build/withIos.d.ts +5 -0
- package/plugin/build/withIos.js +108 -0
- package/scripts/inject-ios-sdk-version.mjs +65 -0
- package/scripts/public-ota-api.test.mjs +37 -0
- package/scripts/verify-release-package.mjs +45 -0
- package/scripts/write-release-metadata.mjs +152 -0
- package/scripts/write-release-metadata.test.mjs +37 -0
- package/src/BluetoothSdk.types.ts +1623 -0
- package/src/_internal.ts +16 -0
- package/src/_private/BluetoothSdkModule.ts +684 -0
- package/src/_private/LocalNetworkModule.ts +50 -0
- package/src/_private/cameraRequestPayload.ts +34 -0
- package/src/_private/photoRequestPayload.ts +90 -0
- package/src/_private/sdkOtaManifest.ts +18 -0
- package/src/changelogs.ts +46 -0
- package/src/debug.ts +9 -0
- package/src/generated/changelogCatalog.ts +13 -0
- package/src/generated/releaseMetadata.ts +20 -0
- package/src/index.ts +321 -0
- package/src/ota-server/OtaServer.types.ts +10 -0
- package/src/ota-server/OtaServerModule.ts +23 -0
- package/src/ota-server/OtaServerModule.web.ts +17 -0
- package/src/ota-server/index.ts +2 -0
- package/src/ota-transport/index.ts +116 -0
- package/src/photo-receiver/PhotoReceiver.types.ts +20 -0
- package/src/photo-receiver/PhotoReceiverModule.ts +11 -0
- package/src/photo-receiver/PhotoReceiverModule.web.ts +17 -0
- package/src/photo-receiver/index.ts +2 -0
- package/src/react/index.ts +21 -0
- package/src/react/useBluetooth.ts +309 -0
- package/src/react/useBluetoothEvent.ts +35 -0
- package/src/react/useBluetoothScan.ts +173 -0
- package/src/react/useBluetoothStatus.ts +180 -0
- package/src/react/useGlassesConnection.ts +202 -0
- package/src/types/index.ts +12 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
include_expo_adapter = ENV['GLASSLY_BLUETOOTH_SDK_INCLUDE_EXPO_ADAPTER'] == '1'
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = 'GlasslyBluetoothSDK'
|
|
8
|
+
s.version = package['version']
|
|
9
|
+
s.summary = package['description']
|
|
10
|
+
s.description = package['description']
|
|
11
|
+
s.license = package['license']
|
|
12
|
+
s.author = package['author']
|
|
13
|
+
s.homepage = package['homepage']
|
|
14
|
+
s.platforms = {
|
|
15
|
+
:ios => '15.1'
|
|
16
|
+
}
|
|
17
|
+
s.swift_version = '5.9'
|
|
18
|
+
s.source = {
|
|
19
|
+
:git => 'https://github.com/tetramo-labs/glassly.git',
|
|
20
|
+
:tag => "bluetooth-sdk-v#{s.version}"
|
|
21
|
+
}
|
|
22
|
+
s.static_framework = true
|
|
23
|
+
|
|
24
|
+
# External dependencies required by Bluetooth SDK native code
|
|
25
|
+
s.dependency 'ExpoModulesCore' if include_expo_adapter
|
|
26
|
+
s.dependency 'SWCompression', '~> 4.8.0'
|
|
27
|
+
s.dependency 'SwiftProtobuf', '~> 1.0'
|
|
28
|
+
# Supplies ONNX Runtime for iOS. The vendored sherpa-onnx.xcframework links ORT
|
|
29
|
+
# *externally*: its only undefined ORT symbol is _OrtGetApiBase, which this pod
|
|
30
|
+
# provides.
|
|
31
|
+
#
|
|
32
|
+
# This version MUST be >= the ORT version sherpa-onnx was built against, and so
|
|
33
|
+
# must be bumped in lockstep with the xcframework (mirroring the Android pins in
|
|
34
|
+
# android/build.gradle and android/silero/build.gradle). ORT's C API is backward
|
|
35
|
+
# compatible but NOT forward compatible: sherpa calls
|
|
36
|
+
# OrtGetApiBase()->GetApi(ORT_API_VERSION) with the version baked in at its
|
|
37
|
+
# compile time, and GetApi returns NULL when asked for a version newer than the
|
|
38
|
+
# runtime provides. sherpa does not null-check that result, so a too-old pod
|
|
39
|
+
# crashes with EXC_BAD_ACCESS inside the first OrtApi call
|
|
40
|
+
# (Ort::detail::Global<void>::api is a guarded function-local static, hence the
|
|
41
|
+
# __cxa_guard_release frame). sherpa-onnx 1.13.4 requests API version 27.
|
|
42
|
+
#
|
|
43
|
+
# To re-derive after a future xcframework bump, read the immediate passed to
|
|
44
|
+
# GetApi (0x1b == 27 for ORT 1.27):
|
|
45
|
+
# ar x .../ios-arm64/libsherpa-onnx.a && otool -tvV cat.cc.o | grep -A2 'ldr.*x8, \[x0\]'
|
|
46
|
+
s.dependency 'onnxruntime-objc', '1.27.0'
|
|
47
|
+
s.dependency 'UltraliteSDK'
|
|
48
|
+
|
|
49
|
+
# Swift/Objective-C compatibility
|
|
50
|
+
s.pod_target_xcconfig = {
|
|
51
|
+
'DEFINES_MODULE' => 'YES',
|
|
52
|
+
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
|
|
53
|
+
'CLANG_CXX_LIBRARY' => 'libc++',
|
|
54
|
+
'SWIFT_INCLUDE_PATHS' => '$(PODS_TARGET_SRCROOT)/Packages/libbz2'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# iOS frameworks required by Bluetooth SDK
|
|
58
|
+
ios_frameworks = ['AVFoundation', 'CoreBluetooth', 'UIKit', 'CoreGraphics']
|
|
59
|
+
ios_frameworks << 'Network' if include_expo_adapter
|
|
60
|
+
s.frameworks = ios_frameworks
|
|
61
|
+
|
|
62
|
+
# System libraries required by Glassly
|
|
63
|
+
# Compression is a .tbd library, not a framework (import Compression autolinks it)
|
|
64
|
+
s.libraries = 'bz2', 'compression'
|
|
65
|
+
|
|
66
|
+
# Vendored frameworks
|
|
67
|
+
s.vendored_frameworks = 'Packages/SherpaOnnx/sherpa-onnx.xcframework'
|
|
68
|
+
|
|
69
|
+
s.resource_bundles = {
|
|
70
|
+
'BluetoothSDKPrivacy' => ['Source/PrivacyInfo.xcprivacy'],
|
|
71
|
+
'BluetoothSDKG2Firmware' => ['Source/Resources/G2Firmware/*']
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
native_source_files = [
|
|
75
|
+
"Source/**/*.{h,m,mm,swift,hpp,cpp,c}",
|
|
76
|
+
"Packages/CoreObjC/**/*.{h,m,mm,hpp,cpp,c}",
|
|
77
|
+
"Packages/SherpaOnnx/SherpaOnnx.swift",
|
|
78
|
+
"Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/**/*.{h,hpp}",
|
|
79
|
+
"Packages/VAD/**/*.swift",
|
|
80
|
+
"Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/**/*.{h,hpp}",
|
|
81
|
+
"Packages/libbz2/shim.h"
|
|
82
|
+
]
|
|
83
|
+
native_source_files.concat([
|
|
84
|
+
"BluetoothSdkModule.swift",
|
|
85
|
+
"LocalPhotoUploadServer.swift",
|
|
86
|
+
"PhotoReceiverModule.swift",
|
|
87
|
+
"LocalIPv4.swift",
|
|
88
|
+
"LocalOtaServer.swift",
|
|
89
|
+
"BackgroundOtaArtifactDownloader.swift",
|
|
90
|
+
"OtaServerModule.swift"
|
|
91
|
+
]) if include_expo_adapter
|
|
92
|
+
s.source_files = native_source_files
|
|
93
|
+
|
|
94
|
+
# Explicitly mark C++ headers and internal headers as private to prevent exposure in public interface
|
|
95
|
+
s.private_header_files = [
|
|
96
|
+
"Packages/CoreObjC/lc3_cpp.h",
|
|
97
|
+
"Packages/CoreObjC/mdct_neon.h",
|
|
98
|
+
"Packages/CoreObjC/ltpf_neon.h",
|
|
99
|
+
"Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/cxx-api.h",
|
|
100
|
+
"Packages/libbz2/shim.h",
|
|
101
|
+
"Source/Bridging-Header.h"
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
# Exclude legacy Obj-C bridge files.
|
|
105
|
+
s.exclude_files = ["Source/BridgeModule.{h,m}", "Source/Bridge.m"]
|
|
106
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import Darwin
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
/// Best-effort local IPv4 discovery for phone-hosted servers the glasses reach over WiFi
|
|
5
|
+
/// (photo upload receiver, hotspot-served OTA). Prefers WiFi-ish interfaces carrying RFC1918
|
|
6
|
+
/// addresses — under a glasses-hotspot session en0 holds the 192.168.43.x client address.
|
|
7
|
+
enum LocalIPv4 {
|
|
8
|
+
/// Return the active Wi-Fi address only when it is on the glasses gateway's /24.
|
|
9
|
+
/// iPhone Wi-Fi is `en0`; accepting AWDL, VPN, cellular, or another private
|
|
10
|
+
/// interface can publish an endpoint that the glasses cannot reach.
|
|
11
|
+
static func wifiIPv4Address(matchingGateway gateway: String) -> String? {
|
|
12
|
+
guard let gatewayPrefix = subnet24Prefix(gateway) else {
|
|
13
|
+
return nil
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var interfaces: UnsafeMutablePointer<ifaddrs>?
|
|
17
|
+
guard getifaddrs(&interfaces) == 0, let first = interfaces else {
|
|
18
|
+
return nil
|
|
19
|
+
}
|
|
20
|
+
defer { freeifaddrs(interfaces) }
|
|
21
|
+
|
|
22
|
+
var cursor: UnsafeMutablePointer<ifaddrs>? = first
|
|
23
|
+
while let current = cursor {
|
|
24
|
+
defer { cursor = current.pointee.ifa_next }
|
|
25
|
+
let interface = current.pointee
|
|
26
|
+
guard String(cString: interface.ifa_name) == "en0",
|
|
27
|
+
let addressPointer = interface.ifa_addr,
|
|
28
|
+
addressPointer.pointee.sa_family == UInt8(AF_INET),
|
|
29
|
+
(interface.ifa_flags & UInt32(IFF_UP)) != 0
|
|
30
|
+
else {
|
|
31
|
+
continue
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var address = addressPointer.pointee
|
|
35
|
+
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
|
|
36
|
+
guard getnameinfo(
|
|
37
|
+
&address,
|
|
38
|
+
socklen_t(address.sa_len),
|
|
39
|
+
&hostname,
|
|
40
|
+
socklen_t(hostname.count),
|
|
41
|
+
nil,
|
|
42
|
+
0,
|
|
43
|
+
NI_NUMERICHOST
|
|
44
|
+
) == 0 else {
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let ip = String(cString: hostname)
|
|
49
|
+
if subnet24Prefix(ip) == gatewayPrefix {
|
|
50
|
+
return ip
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return nil
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static func bestLocalIPv4Address() -> String? {
|
|
57
|
+
var interfaces: UnsafeMutablePointer<ifaddrs>?
|
|
58
|
+
guard getifaddrs(&interfaces) == 0, let first = interfaces else {
|
|
59
|
+
return nil
|
|
60
|
+
}
|
|
61
|
+
defer { freeifaddrs(interfaces) }
|
|
62
|
+
|
|
63
|
+
var preferredPrivate: String?
|
|
64
|
+
var preferred: String?
|
|
65
|
+
var privateFallback: String?
|
|
66
|
+
var fallback: String?
|
|
67
|
+
var cursor: UnsafeMutablePointer<ifaddrs>? = first
|
|
68
|
+
while let current = cursor {
|
|
69
|
+
defer { cursor = current.pointee.ifa_next }
|
|
70
|
+
let interface = current.pointee
|
|
71
|
+
guard let addressPointer = interface.ifa_addr,
|
|
72
|
+
addressPointer.pointee.sa_family == UInt8(AF_INET)
|
|
73
|
+
else {
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let name = String(cString: interface.ifa_name)
|
|
78
|
+
let flags = interface.ifa_flags
|
|
79
|
+
guard (flags & UInt32(IFF_UP)) != 0,
|
|
80
|
+
(flags & UInt32(IFF_LOOPBACK)) == 0
|
|
81
|
+
else {
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var address = addressPointer.pointee
|
|
86
|
+
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
|
|
87
|
+
let result = getnameinfo(
|
|
88
|
+
&address,
|
|
89
|
+
socklen_t(address.sa_len),
|
|
90
|
+
&hostname,
|
|
91
|
+
socklen_t(hostname.count),
|
|
92
|
+
nil,
|
|
93
|
+
0,
|
|
94
|
+
NI_NUMERICHOST
|
|
95
|
+
)
|
|
96
|
+
guard result == 0 else {
|
|
97
|
+
continue
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let ip = String(cString: hostname)
|
|
101
|
+
guard ip != "127.0.0.1", !isLinkLocalIPv4(ip) else {
|
|
102
|
+
continue
|
|
103
|
+
}
|
|
104
|
+
if isPreferredLocalInterface(name), isPrivateIPv4(ip) {
|
|
105
|
+
preferredPrivate = preferredPrivate ?? ip
|
|
106
|
+
} else if isPreferredLocalInterface(name) {
|
|
107
|
+
preferred = preferred ?? ip
|
|
108
|
+
} else if isPrivateIPv4(ip) {
|
|
109
|
+
privateFallback = privateFallback ?? ip
|
|
110
|
+
} else {
|
|
111
|
+
fallback = fallback ?? ip
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return preferredPrivate ?? preferred ?? privateFallback ?? fallback
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private static func isPreferredLocalInterface(_ name: String) -> Bool {
|
|
119
|
+
name == "en0" ||
|
|
120
|
+
name.hasPrefix("bridge") ||
|
|
121
|
+
name.hasPrefix("ap") ||
|
|
122
|
+
name.hasPrefix("awdl") ||
|
|
123
|
+
name.hasPrefix("llw")
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private static func isPrivateIPv4(_ ip: String) -> Bool {
|
|
127
|
+
if ip.hasPrefix("192.168.") || ip.hasPrefix("10.") {
|
|
128
|
+
return true
|
|
129
|
+
}
|
|
130
|
+
let parts = ip.split(separator: ".").compactMap { Int($0) }
|
|
131
|
+
return parts.count == 4 && parts[0] == 172 && (16 ... 31).contains(parts[1])
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private static func isLinkLocalIPv4(_ ip: String) -> Bool {
|
|
135
|
+
ip.hasPrefix("169.254.")
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private static func subnet24Prefix(_ ip: String) -> String? {
|
|
139
|
+
let parts = ip.split(separator: ".")
|
|
140
|
+
guard parts.count == 4,
|
|
141
|
+
parts.allSatisfy({ part in
|
|
142
|
+
guard let value = Int(part) else { return false }
|
|
143
|
+
return (0 ... 255).contains(value)
|
|
144
|
+
})
|
|
145
|
+
else {
|
|
146
|
+
return nil
|
|
147
|
+
}
|
|
148
|
+
return parts.prefix(3).joined(separator: ".")
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Network
|
|
3
|
+
|
|
4
|
+
struct OtaServerError: LocalizedError {
|
|
5
|
+
let message: String
|
|
6
|
+
|
|
7
|
+
init(_ message: String) {
|
|
8
|
+
self.message = message
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var errorDescription: String? { message }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/// Static HTTP server for hotspot-served glasses OTA (OS-1676).
|
|
15
|
+
///
|
|
16
|
+
/// Serves the rewritten OTA manifest at /version.json and pre-downloaded artifacts at
|
|
17
|
+
/// /artifacts/<sha256> to the glasses over the glasses-hotspot link. Mirrors
|
|
18
|
+
/// LocalPhotoUploadServer's NWListener structure.
|
|
19
|
+
final class LocalOtaServer {
|
|
20
|
+
private let queue = DispatchQueue(label: "com.glassly.ota-server")
|
|
21
|
+
private let onLog: (String) -> Void
|
|
22
|
+
private var listener: NWListener?
|
|
23
|
+
private var listenerGeneration = 0
|
|
24
|
+
private(set) var activePort: UInt16?
|
|
25
|
+
|
|
26
|
+
private var manifestJson = "{}"
|
|
27
|
+
private var artifacts: [String: URL] = [:]
|
|
28
|
+
|
|
29
|
+
private static let maxHeaderBytes = 64 * 1024
|
|
30
|
+
private static let streamChunkBytes = 256 * 1024
|
|
31
|
+
|
|
32
|
+
init(onLog: @escaping (String) -> Void) {
|
|
33
|
+
self.onLog = onLog
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Swap the served manifest and artifact set. Safe while the server is running.
|
|
37
|
+
func configure(manifestJson: String, artifacts: [String: URL]) {
|
|
38
|
+
queue.sync {
|
|
39
|
+
self.manifestJson = manifestJson
|
|
40
|
+
self.artifacts = artifacts
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func start(host: String, port: UInt16) throws -> UInt16 {
|
|
45
|
+
if listener != nil, activePort == port {
|
|
46
|
+
onLog("Already listening on \(host):\(port)")
|
|
47
|
+
return port
|
|
48
|
+
}
|
|
49
|
+
stop()
|
|
50
|
+
|
|
51
|
+
let parameters = NWParameters.tcp
|
|
52
|
+
parameters.allowLocalEndpointReuse = true
|
|
53
|
+
guard let endpointPort = NWEndpoint.Port(rawValue: port) else {
|
|
54
|
+
throw OtaServerError("Invalid port \(port)")
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
parameters.requiredLocalEndpoint = .hostPort(host: NWEndpoint.Host(host), port: endpointPort)
|
|
58
|
+
let listener = try NWListener(using: parameters)
|
|
59
|
+
listenerGeneration += 1
|
|
60
|
+
let generation = listenerGeneration
|
|
61
|
+
let started = DispatchSemaphore(value: 0)
|
|
62
|
+
var startError: Error?
|
|
63
|
+
var isReady = false
|
|
64
|
+
|
|
65
|
+
listener.stateUpdateHandler = { [weak self] state in
|
|
66
|
+
guard let self, self.listenerGeneration == generation else {
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
switch state {
|
|
70
|
+
case .ready:
|
|
71
|
+
isReady = true
|
|
72
|
+
self.activePort = port
|
|
73
|
+
self.onLog("OTA server listening on \(host):\(port)")
|
|
74
|
+
started.signal()
|
|
75
|
+
case .failed(let error):
|
|
76
|
+
startError = error
|
|
77
|
+
self.activePort = nil
|
|
78
|
+
self.listener = nil
|
|
79
|
+
self.onLog("OTA server failed on \(port): \(error)")
|
|
80
|
+
started.signal()
|
|
81
|
+
case .cancelled:
|
|
82
|
+
self.activePort = nil
|
|
83
|
+
if !isReady {
|
|
84
|
+
startError = OtaServerError("Listener cancelled")
|
|
85
|
+
started.signal()
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
break
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
listener.newConnectionHandler = { [weak self] connection in
|
|
93
|
+
self?.handle(connection)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
self.listener = listener
|
|
97
|
+
listener.start(queue: queue)
|
|
98
|
+
|
|
99
|
+
if started.wait(timeout: .now() + 2) == .timedOut {
|
|
100
|
+
self.listener = nil
|
|
101
|
+
listener.cancel()
|
|
102
|
+
throw OtaServerError("Timed out starting listener")
|
|
103
|
+
}
|
|
104
|
+
if let startError {
|
|
105
|
+
self.listener = nil
|
|
106
|
+
listener.cancel()
|
|
107
|
+
throw startError
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return port
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
func stop() {
|
|
114
|
+
listenerGeneration += 1
|
|
115
|
+
listener?.cancel()
|
|
116
|
+
listener = nil
|
|
117
|
+
activePort = nil
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private final class RequestReadState {
|
|
121
|
+
var buffer = Data()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private func handle(_ connection: NWConnection) {
|
|
125
|
+
connection.start(queue: queue)
|
|
126
|
+
receive(connection, state: RequestReadState())
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private func receive(_ connection: NWConnection, state: RequestReadState) {
|
|
130
|
+
connection.receive(minimumIncompleteLength: 1, maximumLength: 64 * 1024) {
|
|
131
|
+
[weak self] data, _, isComplete, error in
|
|
132
|
+
guard let self else {
|
|
133
|
+
connection.cancel()
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
if let error {
|
|
137
|
+
self.onLog("request failed: \(error.localizedDescription)")
|
|
138
|
+
connection.cancel()
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
if let data, !data.isEmpty {
|
|
142
|
+
state.buffer.append(data)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if let headerRange = state.buffer.range(of: Data([13, 10, 13, 10])) {
|
|
146
|
+
let headerData = state.buffer.subdata(in: state.buffer.startIndex..<headerRange.lowerBound)
|
|
147
|
+
let headerText = String(data: headerData, encoding: .isoLatin1) ?? ""
|
|
148
|
+
self.route(connection, headerText: headerText)
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
if state.buffer.count > Self.maxHeaderBytes {
|
|
152
|
+
self.writeJson(connection, status: 400, body: #"{"ok":false,"error":"headers_too_large"}"#)
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
if isComplete {
|
|
156
|
+
connection.cancel()
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
self.receive(connection, state: state)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private func route(_ connection: NWConnection, headerText: String) {
|
|
164
|
+
let lines = headerText.components(separatedBy: "\r\n").filter { !$0.isEmpty }
|
|
165
|
+
let requestParts = lines.first?.components(separatedBy: " ") ?? []
|
|
166
|
+
let method = requestParts.count > 0 ? requestParts[0].uppercased() : ""
|
|
167
|
+
let rawPath = requestParts.count > 1 ? requestParts[1] : ""
|
|
168
|
+
let path = rawPath.components(separatedBy: "?")[0]
|
|
169
|
+
onLog("\(method) \(path)")
|
|
170
|
+
|
|
171
|
+
guard method == "GET" else {
|
|
172
|
+
writeJson(connection, status: 405, body: #"{"ok":false,"error":"method_not_allowed"}"#)
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if path == "/version.json" {
|
|
177
|
+
writeBody(
|
|
178
|
+
connection,
|
|
179
|
+
status: 200,
|
|
180
|
+
contentType: "application/json",
|
|
181
|
+
body: Data(manifestJson.utf8)
|
|
182
|
+
)
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if path.hasPrefix("/artifacts/") {
|
|
187
|
+
let key = String(path.dropFirst("/artifacts/".count))
|
|
188
|
+
guard let fileUrl = artifacts[key],
|
|
189
|
+
let fileSize = try? fileUrl.resourceValues(forKeys: [.fileSizeKey]).fileSize
|
|
190
|
+
else {
|
|
191
|
+
writeJson(connection, status: 404, body: #"{"ok":false,"error":"artifact_not_found"}"#)
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
sendFile(connection, fileUrl: fileUrl, fileLength: Int64(fileSize))
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
writeJson(connection, status: 404, body: #"{"ok":false,"error":"not_found"}"#)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private func sendFile(
|
|
202
|
+
_ connection: NWConnection,
|
|
203
|
+
fileUrl: URL,
|
|
204
|
+
fileLength: Int64
|
|
205
|
+
) {
|
|
206
|
+
let header =
|
|
207
|
+
"HTTP/1.1 200 OK\r\n" +
|
|
208
|
+
"Content-Type: application/octet-stream\r\n" +
|
|
209
|
+
"Content-Length: \(fileLength)\r\n" +
|
|
210
|
+
"Connection: close\r\n\r\n"
|
|
211
|
+
|
|
212
|
+
guard let fileHandle = try? FileHandle(forReadingFrom: fileUrl) else {
|
|
213
|
+
writeJson(connection, status: 500, body: #"{"ok":false,"error":"artifact_unreadable"}"#)
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
connection.send(content: Data(header.utf8), completion: .contentProcessed { [weak self] error in
|
|
218
|
+
guard let self, error == nil else {
|
|
219
|
+
try? fileHandle.close()
|
|
220
|
+
connection.cancel()
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
self.streamChunks(connection, fileHandle: fileHandle, remaining: fileLength)
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private func streamChunks(_ connection: NWConnection, fileHandle: FileHandle, remaining: Int64) {
|
|
228
|
+
if remaining <= 0 {
|
|
229
|
+
try? fileHandle.close()
|
|
230
|
+
connection.send(content: nil, contentContext: .finalMessage, isComplete: true, completion: .contentProcessed { _ in
|
|
231
|
+
connection.cancel()
|
|
232
|
+
})
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
let chunkSize = Int(min(Int64(Self.streamChunkBytes), remaining))
|
|
236
|
+
let chunk: Data
|
|
237
|
+
do {
|
|
238
|
+
guard let data = try fileHandle.read(upToCount: chunkSize), !data.isEmpty else {
|
|
239
|
+
throw OtaServerError("artifact truncated while streaming")
|
|
240
|
+
}
|
|
241
|
+
chunk = data
|
|
242
|
+
} catch {
|
|
243
|
+
onLog("stream failed: \(error.localizedDescription)")
|
|
244
|
+
try? fileHandle.close()
|
|
245
|
+
connection.cancel()
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
connection.send(content: chunk, completion: .contentProcessed { [weak self] error in
|
|
249
|
+
guard let self else {
|
|
250
|
+
try? fileHandle.close()
|
|
251
|
+
connection.cancel()
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
if let error {
|
|
255
|
+
self.onLog("stream failed: \(error.localizedDescription)")
|
|
256
|
+
try? fileHandle.close()
|
|
257
|
+
connection.cancel()
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
self.streamChunks(connection, fileHandle: fileHandle, remaining: remaining - Int64(chunk.count))
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private func writeJson(
|
|
265
|
+
_ connection: NWConnection,
|
|
266
|
+
status: Int,
|
|
267
|
+
body: String
|
|
268
|
+
) {
|
|
269
|
+
writeBody(
|
|
270
|
+
connection,
|
|
271
|
+
status: status,
|
|
272
|
+
contentType: "application/json",
|
|
273
|
+
body: Data(body.utf8)
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private func writeBody(
|
|
278
|
+
_ connection: NWConnection,
|
|
279
|
+
status: Int,
|
|
280
|
+
contentType: String,
|
|
281
|
+
body: Data
|
|
282
|
+
) {
|
|
283
|
+
let reason: String
|
|
284
|
+
switch status {
|
|
285
|
+
case 200:
|
|
286
|
+
reason = "OK"
|
|
287
|
+
case 400:
|
|
288
|
+
reason = "Bad Request"
|
|
289
|
+
case 404:
|
|
290
|
+
reason = "Not Found"
|
|
291
|
+
case 405:
|
|
292
|
+
reason = "Method Not Allowed"
|
|
293
|
+
default:
|
|
294
|
+
reason = "Internal Server Error"
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let header =
|
|
298
|
+
"HTTP/1.1 \(status) \(reason)\r\n" +
|
|
299
|
+
"Content-Type: \(contentType)\r\n" +
|
|
300
|
+
"Content-Length: \(body.count)\r\n" +
|
|
301
|
+
"Connection: close\r\n" +
|
|
302
|
+
"\r\n"
|
|
303
|
+
var response = Data(header.utf8)
|
|
304
|
+
response.append(body)
|
|
305
|
+
connection.send(content: response, completion: .contentProcessed { _ in
|
|
306
|
+
connection.cancel()
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
}
|