From 85453854dced85228e952e69516c0fdad81952f0 Mon Sep 17 00:00:00 2001 From: pax-k Date: Thu, 18 Apr 2024 13:51:07 +0300 Subject: [PATCH] fix audioSession --- example/App.tsx | 2 +- example/ios/Podfile.lock | 2 +- example/metro.config.js | 16 ++++++++-------- example/tsconfig.json | 4 ++-- example/webpack.config.js | 10 +++++----- ios/ExpoAudioStreamModule.swift | 6 ++---- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/example/App.tsx b/example/App.tsx index 1966997..ae8185f 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -1,5 +1,5 @@ import { StyleSheet, Text, View } from "react-native"; -import { ExpoAudioStream } from "expo-audio-stream"; +import { ExpoAudioStream } from "@mykin-ai/expo-audio-stream"; import { useEffect } from "react"; import { sampleA } from "./samples/sample-a"; import { sampleB } from "./samples/sample-b"; diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index c653fc3..f95f943 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1260,7 +1260,7 @@ SPEC CHECKSUMS: EXConstants: 988aa430ca0f76b43cd46b66e7fae3287f9cc2fc EXFont: f20669cb266ef48b004f1eb1f2b20db96cd1df9f Expo: e01a77c6fa4bc80a6d1bb949cda1d12d21044abd - ExpoAudioStream: 3072cd8bdca4f0b951cc92f0610ef711724cbe5a + ExpoAudioStream: 43fea6cfb926879caf0c6e90abc99ee855ae52bd ExpoFileSystem: eecaf6796aed0f4dd20042dc2ca2cac6c4bc1185 ExpoKeepAwake: 0f5cad99603a3268e50af9a6eb8b76d0d9ac956c ExpoModulesCore: 61dc57c6e2a35f2f84baf488146db624e03af4cd diff --git a/example/metro.config.js b/example/metro.config.js index 2ca9972..58ebb86 100644 --- a/example/metro.config.js +++ b/example/metro.config.js @@ -1,6 +1,6 @@ // Learn more https://docs.expo.io/guides/customizing-metro -const { getDefaultConfig } = require('expo/metro-config'); -const path = require('path'); +const { getDefaultConfig } = require("expo/metro-config"); +const path = require("path"); const config = getDefaultConfig(__dirname); @@ -9,20 +9,20 @@ const config = getDefaultConfig(__dirname); // excludes the one from the parent folder when bundling. config.resolver.blockList = [ ...Array.from(config.resolver.blockList ?? []), - new RegExp(path.resolve('..', 'node_modules', 'react')), - new RegExp(path.resolve('..', 'node_modules', 'react-native')), + new RegExp(path.resolve("..", "node_modules", "react")), + new RegExp(path.resolve("..", "node_modules", "react-native")), ]; config.resolver.nodeModulesPaths = [ - path.resolve(__dirname, './node_modules'), - path.resolve(__dirname, '../node_modules'), + path.resolve(__dirname, "./node_modules"), + path.resolve(__dirname, "../node_modules"), ]; config.resolver.extraNodeModules = { - 'expo-audio-stream': '..', + "@mykin-ai/expo-audio-stream": "..", }; -config.watchFolders = [path.resolve(__dirname, '..')]; +config.watchFolders = [path.resolve(__dirname, "..")]; config.transformer.getTransformOptions = async () => ({ transform: { diff --git a/example/tsconfig.json b/example/tsconfig.json index 223cbbd..3483de1 100644 --- a/example/tsconfig.json +++ b/example/tsconfig.json @@ -4,10 +4,10 @@ "strict": true, "allowJs": true, "paths": { - "expo-audio-stream": [ + "@mykin-ai/expo-audio-stream": [ "../src/index" ], - "expo-audio-stream/*": [ + "@mykin-ai/expo-audio-stream/*": [ "../src/*" ] } diff --git a/example/webpack.config.js b/example/webpack.config.js index 2bceb6c..62568da 100644 --- a/example/webpack.config.js +++ b/example/webpack.config.js @@ -1,19 +1,19 @@ -const createConfigAsync = require('@expo/webpack-config'); -const path = require('path'); +const createConfigAsync = require("@expo/webpack-config"); +const path = require("path"); module.exports = async (env, argv) => { const config = await createConfigAsync( { ...env, babel: { - dangerouslyAddModulePathsToTranspile: ['expo-audio-stream'], + dangerouslyAddModulePathsToTranspile: ["@mykin-ai/expo-audio-stream"], }, }, argv ); config.resolve.modules = [ - path.resolve(__dirname, './node_modules'), - path.resolve(__dirname, '../node_modules'), + path.resolve(__dirname, "./node_modules"), + path.resolve(__dirname, "../node_modules"), ]; return config; diff --git a/ios/ExpoAudioStreamModule.swift b/ios/ExpoAudioStreamModule.swift index eca448e..d1741cf 100644 --- a/ios/ExpoAudioStreamModule.swift +++ b/ios/ExpoAudioStreamModule.swift @@ -6,8 +6,6 @@ public class ExpoAudioStreamModule: Module { private let audioFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 16000.0, channels: 1, interleaved: false) private var audioEngine = AVAudioEngine() private var playerNode = AVAudioPlayerNode() - private var audioSessionCategory: AVAudioSession.Category = .playback - private var audioSessionMode: AVAudioSession.Mode = .default // Two buffer queues for alternating playback, storing tuples of buffers and promises private var bufferQueueA: [(buffer: AVAudioPCMBuffer, promise: RCTPromiseResolveBlock)] = [] @@ -31,8 +29,8 @@ public class ExpoAudioStreamModule: Module { private func configureAudioSession() { do { let audioSession = AVAudioSession.sharedInstance() - try audioSession.setCategory(self.audioSessionCategory, mode: self.audioSessionMode, options: []) - try audioSession.setActive(true) + try audioSession.setCategory(.playback, mode: .default, options: [.defaultToSpeaker, .allowBluetooth]) + try audioSession.setActive(true, options: .notifyOthersOnDeactivation) } catch { print("Error configuring audio session: \(error)") }