capacitor-microphone 0.1.12 → 0.1.14

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,52 +319,53 @@ 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
322
+ // 1. Resolver inmediatamente el call de restart
324
323
  call.resolve(new JSObject().put("status", "restarting"));
325
324
 
326
- // 2. Guardar el lenguaje
325
+ // 2. Obtener el lenguaje (del call actual o del parámetro)
327
326
  final String lang;
328
- if (currentCall != null) {
327
+ if (currentCall != null && currentCall != call) {
329
328
  lang = currentCall.getString("lang", "es-MX");
330
329
  } else {
331
330
  lang = call.getString("lang", "es-MX");
332
331
  }
333
332
 
334
- // 3. Detener la escucha actual si está activa
333
+ // 3. Detener completamente usando tu método existente
335
334
  if (isListening) {
336
- // Usar forceStop() para limpiar sin tocar currentCall
337
- forceStop();
335
+ // Crear call temporal para stopListening
336
+ PluginCall stopCall = new PluginCall(
337
+ this,
338
+ "temp_stop_" + System.currentTimeMillis(),
339
+ "capacitor-microphone",
340
+ "stopListening",
341
+ new JSObject()
342
+ );
343
+ stopListening(stopCall);
344
+ } else {
345
+ // Si no estaba escuchando, limpiar manualmente
346
+ destroyEverything();
338
347
  }
339
348
 
340
- // 4. Pequeño delay y comenzar de nuevo
349
+ // 4. Esperar y comenzar de nuevo con tu método startListening
341
350
  getActivity().runOnUiThread(() -> {
342
351
  getActivity().getWindow().getDecorView().postDelayed(() -> {
343
- // Resetear flags
344
- isListening = true;
345
- isDestroyed = false;
346
-
347
- // Crear NUEVO PluginCall para el inicio
352
+ // Crear NUEVO call para la nueva sesión
348
353
  PluginCall newCall = new PluginCall(
349
- "restart_" + System.currentTimeMillis(),
354
+ this,
355
+ "restart_session_" + System.currentTimeMillis(),
350
356
  "capacitor-microphone",
351
357
  "startListening",
352
358
  new JSObject().put("lang", lang)
353
359
  );
354
360
 
355
- // Iniciar nueva sesión
361
+ // Iniciar nueva sesión usando tu método ya probado
356
362
  startListening(newCall);
357
- }, 500); // Delay suficiente para limpieza
363
+ }, 600); // 600ms es suficiente
358
364
  });
359
365
  }
360
366
 
361
- // Método helper para detener sin problemas
362
- private void forceStop() {
363
- // Solo cambiar flags
364
- isListening = false;
365
- isDestroyed = true;
366
-
367
- // Limpiar runnables pendientes
367
+ private void destroyEverything() {
368
+ // Limpiar runnables
368
369
  if (delayedStartRunnable != null) {
369
370
  getActivity().runOnUiThread(() -> {
370
371
  getActivity()
@@ -375,29 +376,23 @@ private void startListeningInternal(PluginCall call, String lang) {
375
376
  delayedStartRunnable = null;
376
377
  }
377
378
 
378
- // Detener speech recognizer (igual que stopSpeech pero sin tocar currentCall)
379
- try {
380
- lastStopTime = System.currentTimeMillis();
381
-
382
- if (speechRecognizer != null) {
379
+ // Limpiar speech recognizer
380
+ if (speechRecognizer != null) {
381
+ try {
383
382
  speechRecognizer.cancel();
384
- speechRecognizer.setRecognitionListener(null);
385
-
386
- final SpeechRecognizer recognizerToDestroy = speechRecognizer;
387
- speechRecognizer = null;
388
-
389
- getActivity().runOnUiThread(() -> {
390
- getActivity()
391
- .getWindow()
392
- .getDecorView()
393
- .postDelayed(() -> {
394
- try {
395
- recognizerToDestroy.destroy();
396
- } catch (Exception ignored) {}
397
- }, 100);
398
- });
383
+ speechRecognizer.destroy();
384
+ } catch (Exception e) {
385
+ // Ignorar
399
386
  }
400
- } catch (Exception ignored) {}
387
+ speechRecognizer = null;
388
+ }
389
+
390
+ // Resetear estado
391
+ currentCall = null;
392
+ speechIntent = null;
393
+ isListening = false;
394
+ isDestroyed = true;
395
+ lastStopTime = System.currentTimeMillis();
401
396
  }
402
397
 
403
398
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-microphone",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "plugin to use the microphone",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",