react-native-voice-bot-sdk 0.0.0-stage → 0.1.1
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/CHANGELOG.md +57 -0
- package/LICENSE +21 -0
- package/README.md +438 -2
- package/android/build.gradle +15 -0
- package/android/src/main/AndroidManifest.xml +16 -0
- package/android/src/main/java/expo/modules/voicebot/VoiceBotAudioModule.kt +416 -0
- package/android/src/main/java/expo/modules/voicebot/VoiceBotMicService.kt +107 -0
- package/app.plugin.js +1 -0
- package/build/NativeAudio.d.ts +24 -0
- package/build/NativeAudio.js +1 -0
- package/build/VoiceBotClient.d.ts +231 -0
- package/build/VoiceBotClient.js +1 -0
- package/build/audio/noiseGate.d.ts +83 -0
- package/build/audio/noiseGate.js +1 -0
- package/build/base64.d.ts +6 -0
- package/build/base64.js +1 -0
- package/build/expo-router.d.ts +16 -0
- package/build/expo-router.js +1 -0
- package/build/index.d.ts +20 -0
- package/build/index.js +1 -0
- package/build/logger.d.ts +35 -0
- package/build/logger.js +1 -0
- package/build/navigation/callbackNavigation.d.ts +28 -0
- package/build/navigation/callbackNavigation.js +1 -0
- package/build/navigation/reactNavigation.d.ts +33 -0
- package/build/navigation/reactNavigation.js +1 -0
- package/build/navigation/state.d.ts +20 -0
- package/build/navigation/state.js +1 -0
- package/build/navigation/types.d.ts +27 -0
- package/build/navigation/types.js +1 -0
- package/build/protocol.d.ts +108 -0
- package/build/protocol.js +1 -0
- package/build/react/VoiceBotProvider.d.ts +52 -0
- package/build/react/VoiceBotProvider.js +1 -0
- package/build/react/VoiceBotWidget.d.ts +29 -0
- package/build/react/VoiceBotWidget.js +1 -0
- package/build/react/useVoiceBot.d.ts +17 -0
- package/build/react/useVoiceBot.js +1 -0
- package/docs/INTEGRATION.md +189 -0
- package/docs/PROTOCOL.md +271 -0
- package/expo-module.config.json +9 -0
- package/ios/VoiceBotAudio.podspec +25 -0
- package/ios/VoiceBotAudioModule.swift +219 -0
- package/package.json +76 -4
- package/plugin/withVoiceBot.js +137 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expo config plugin for react-native-voice-bot-sdk.
|
|
3
|
+
*
|
|
4
|
+
* app.json:
|
|
5
|
+
* "plugins": [["react-native-voice-bot-sdk", {
|
|
6
|
+
* "microphonePermission": "Allow $(PRODUCT_NAME) to use the microphone for the voice assistant",
|
|
7
|
+
* "allowCleartextTraffic": true, // only if your server URL is ws:// (not wss://)
|
|
8
|
+
* "trustedCertificates": ["./certs/test-server.pem"] // Android dev builds: trust a self-signed wss:// server
|
|
9
|
+
* }]]
|
|
10
|
+
*
|
|
11
|
+
* trustedCertificates: PEM or DER certificate files (paths relative to the project root). They are
|
|
12
|
+
* added to an Android network security config as <debug-overrides>, so only debuggable (dev)
|
|
13
|
+
* builds trust them. Release builds keep the normal system trust. Set
|
|
14
|
+
* "trustCertificatesInRelease": true only if you really ship a self-signed server.
|
|
15
|
+
*/
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const { AndroidConfig, withAndroidManifest, withDangerousMod, withInfoPlist } = require('expo/config-plugins');
|
|
19
|
+
|
|
20
|
+
const DEFAULT_MIC = 'Allow $(PRODUCT_NAME) to use the microphone for the voice assistant';
|
|
21
|
+
const XML_NAME = 'voicebot_network_security_config';
|
|
22
|
+
|
|
23
|
+
function rawName(file, i) {
|
|
24
|
+
// Android resource names: lowercase letters, digits and underscores, starting with a letter.
|
|
25
|
+
const base = path.basename(file).replace(/\.[^.]+$/, '').toLowerCase().replace(/[^a-z0-9_]/g, '_');
|
|
26
|
+
return `voicebot_cert_${i}_${base}`.replace(/_+/g, '_');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function networkSecurityXml({ certNames, allowCleartextTraffic, inRelease }) {
|
|
30
|
+
const certs = certNames.map((n) => ` <certificates src="@raw/${n}" />`).join('\n');
|
|
31
|
+
const cleartext = allowCleartextTraffic ? 'true' : 'false';
|
|
32
|
+
const lines = [
|
|
33
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
34
|
+
'<!-- Generated by react-native-voice-bot-sdk (trustedCertificates). Do not edit. -->',
|
|
35
|
+
'<network-security-config>',
|
|
36
|
+
` <base-config cleartextTrafficPermitted="${cleartext}">`,
|
|
37
|
+
' <trust-anchors>',
|
|
38
|
+
' <certificates src="system" />',
|
|
39
|
+
];
|
|
40
|
+
if (inRelease) lines.push(certs);
|
|
41
|
+
lines.push(' </trust-anchors>', ' </base-config>');
|
|
42
|
+
if (!inRelease) {
|
|
43
|
+
lines.push(
|
|
44
|
+
' <!-- Only debuggable (dev) builds trust these extra certificates. -->',
|
|
45
|
+
' <debug-overrides>',
|
|
46
|
+
' <trust-anchors>',
|
|
47
|
+
certs,
|
|
48
|
+
' </trust-anchors>',
|
|
49
|
+
' </debug-overrides>'
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
lines.push('</network-security-config>', '');
|
|
53
|
+
return lines.join('\n');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function withTrustedCertificates(config, { trustedCertificates, allowCleartextTraffic, inRelease }) {
|
|
57
|
+
const certNames = trustedCertificates.map((f, i) => rawName(f, i));
|
|
58
|
+
|
|
59
|
+
config = withDangerousMod(config, [
|
|
60
|
+
'android',
|
|
61
|
+
async (cfg) => {
|
|
62
|
+
const projectRoot = cfg.modRequest.projectRoot;
|
|
63
|
+
const res = path.join(cfg.modRequest.platformProjectRoot, 'app', 'src', 'main', 'res');
|
|
64
|
+
fs.mkdirSync(path.join(res, 'raw'), { recursive: true });
|
|
65
|
+
fs.mkdirSync(path.join(res, 'xml'), { recursive: true });
|
|
66
|
+
trustedCertificates.forEach((file, i) => {
|
|
67
|
+
const src = path.resolve(projectRoot, file);
|
|
68
|
+
if (!fs.existsSync(src)) {
|
|
69
|
+
throw new Error(`react-native-voice-bot-sdk: trustedCertificates file not found: ${file} (${src})`);
|
|
70
|
+
}
|
|
71
|
+
const isPem = fs.readFileSync(src).includes('-----BEGIN CERTIFICATE-----');
|
|
72
|
+
fs.copyFileSync(src, path.join(res, 'raw', certNames[i] + (isPem ? '.pem' : '.der')));
|
|
73
|
+
});
|
|
74
|
+
fs.writeFileSync(
|
|
75
|
+
path.join(res, 'xml', `${XML_NAME}.xml`),
|
|
76
|
+
networkSecurityXml({ certNames, allowCleartextTraffic, inRelease })
|
|
77
|
+
);
|
|
78
|
+
return cfg;
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
config = withAndroidManifest(config, (cfg) => {
|
|
83
|
+
const app = AndroidConfig.Manifest.getMainApplicationOrThrow(cfg.modResults);
|
|
84
|
+
const existing = app.$['android:networkSecurityConfig'];
|
|
85
|
+
if (existing && existing !== `@xml/${XML_NAME}`) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`react-native-voice-bot-sdk: the app already sets android:networkSecurityConfig (${existing}). ` +
|
|
88
|
+
'Add the certificates to that file yourself instead of using trustedCertificates.'
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
app.$['android:networkSecurityConfig'] = `@xml/${XML_NAME}`;
|
|
92
|
+
return cfg;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return config;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function withVoiceBot(config, props = {}) {
|
|
99
|
+
const {
|
|
100
|
+
microphonePermission = DEFAULT_MIC,
|
|
101
|
+
allowCleartextTraffic = false,
|
|
102
|
+
trustedCertificates = [],
|
|
103
|
+
trustCertificatesInRelease = false,
|
|
104
|
+
} = props || {};
|
|
105
|
+
|
|
106
|
+
config = AndroidConfig.Permissions.withPermissions(config, [
|
|
107
|
+
'android.permission.RECORD_AUDIO',
|
|
108
|
+
'android.permission.MODIFY_AUDIO_SETTINGS',
|
|
109
|
+
'android.permission.INTERNET',
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
if (allowCleartextTraffic) {
|
|
113
|
+
config = withAndroidManifest(config, (cfg) => {
|
|
114
|
+
const app = AndroidConfig.Manifest.getMainApplicationOrThrow(cfg.modResults);
|
|
115
|
+
app.$['android:usesCleartextTraffic'] = 'true';
|
|
116
|
+
return cfg;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (Array.isArray(trustedCertificates) && trustedCertificates.length) {
|
|
121
|
+
// A network security config replaces usesCleartextTraffic, so it carries that setting too.
|
|
122
|
+
config = withTrustedCertificates(config, {
|
|
123
|
+
trustedCertificates,
|
|
124
|
+
allowCleartextTraffic,
|
|
125
|
+
inRelease: !!trustCertificatesInRelease,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
config = withInfoPlist(config, (cfg) => {
|
|
130
|
+
cfg.modResults.NSMicrophoneUsageDescription = cfg.modResults.NSMicrophoneUsageDescription || microphonePermission;
|
|
131
|
+
return cfg;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return config;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
module.exports = withVoiceBot;
|