capacitor-microphone 0.1.12 → 0.1.13

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.
@@ -319,42 +319,43 @@ private void startListeningInternal(PluginCall call, String lang) {
319
319
 
320
320
  @PluginMethod
321
321
  public void restartListening(PluginCall call) {
322
- // 1. Resolver INMEDIATAMENTE el call de restart
323
- // Esto evita problemas de que el call quede pendiente
324
- call.resolve(new JSObject().put("status", "restarting"));
325
-
326
- // 2. Guardar el lenguaje
327
- final String lang;
328
- if (currentCall != null) {
329
- lang = currentCall.getString("lang", "es-MX");
330
- } else {
331
- lang = call.getString("lang", "es-MX");
332
- }
322
+ // Resolver inmediatamente
323
+ call.resolve();
333
324
 
334
- // 3. Detener la escucha actual si está activa
335
- if (isListening) {
336
- // Usar forceStop() para limpiar sin tocar currentCall
337
- forceStop();
338
- }
325
+ // Guardar parámetros
326
+ final String lang = call.getString("lang", "es-MX");
339
327
 
340
- // 4. Pequeño delay y comenzar de nuevo
328
+ // Usar un enfoque diferente: llamar a los métodos internos directamente
341
329
  getActivity().runOnUiThread(() -> {
330
+ // 1. Detener manualmente
331
+ if (isListening) {
332
+ isListening = false;
333
+ isDestroyed = true;
334
+
335
+ if (delayedStartRunnable != null) {
336
+ getActivity()
337
+ .getWindow()
338
+ .getDecorView()
339
+ .removeCallbacks(delayedStartRunnable);
340
+ delayedStartRunnable = null;
341
+ }
342
+
343
+ if (speechRecognizer != null) {
344
+ speechRecognizer.cancel();
345
+ speechRecognizer.destroy();
346
+ speechRecognizer = null;
347
+ }
348
+ }
349
+
350
+ // 2. Esperar y reiniciar
342
351
  getActivity().getWindow().getDecorView().postDelayed(() -> {
343
- // Resetear flags
352
+ // Resetear
344
353
  isListening = true;
345
354
  isDestroyed = false;
346
355
 
347
- // Crear NUEVO PluginCall para el inicio
348
- PluginCall newCall = new PluginCall(
349
- "restart_" + System.currentTimeMillis(),
350
- "capacitor-microphone",
351
- "startListening",
352
- new JSObject().put("lang", lang)
353
- );
354
-
355
- // Iniciar nueva sesión
356
- startListening(newCall);
357
- }, 500); // Delay suficiente para limpieza
356
+ // Iniciar directamente sin crear PluginCall
357
+ startListeningInternal(call, lang);
358
+ }, 500);
358
359
  });
359
360
  }
360
361
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-microphone",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "plugin to use the microphone",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",