capacitor-microphone 0.1.14 → 0.1.15

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,49 +319,65 @@ 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
- call.resolve(new JSObject().put("status", "restarting"));
324
-
325
- // 2. Obtener el lenguaje (del call actual o del parámetro)
326
- final String lang;
327
- if (currentCall != null && currentCall != call) {
328
- lang = currentCall.getString("lang", "es-MX");
322
+ // 1. Obtener lenguaje actual o del parámetro
323
+ String currentLang = "es-MX";
324
+ if (currentCall != null) {
325
+ currentLang = currentCall.getString("lang", "es-MX");
329
326
  } else {
330
- lang = call.getString("lang", "es-MX");
327
+ currentLang = call.getString("lang", "es-MX");
331
328
  }
332
329
 
333
- // 3. Detener completamente usando tu método existente
334
- if (isListening) {
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();
347
- }
330
+ // 2. Guardar para usar después
331
+ final String lang = currentLang;
348
332
 
349
- // 4. Esperar y comenzar de nuevo con tu método startListening
350
- getActivity().runOnUiThread(() -> {
351
- getActivity().getWindow().getDecorView().postDelayed(() -> {
352
- // Crear NUEVO call para la nueva sesión
353
- PluginCall newCall = new PluginCall(
354
- this,
355
- "restart_session_" + System.currentTimeMillis(),
356
- "capacitor-microphone",
357
- "startListening",
358
- new JSObject().put("lang", lang)
359
- );
360
-
361
- // Iniciar nueva sesión usando tu método ya probado
362
- startListening(newCall);
363
- }, 600); // 600ms es suficiente
364
- });
333
+ // 3. Enviar respuesta INMEDIATA
334
+ call.resolve(new JSObject().put("success", true));
335
+
336
+ // 4. En el background, hacer el restart REAL
337
+ new Thread(() -> {
338
+ try {
339
+ // 4.1 Detener completamente
340
+ if (isListening) {
341
+ getActivity().runOnUiThread(() -> {
342
+ isListening = false;
343
+ isDestroyed = true;
344
+
345
+ if (delayedStartRunnable != null) {
346
+ getActivity()
347
+ .getWindow()
348
+ .getDecorView()
349
+ .removeCallbacks(delayedStartRunnable);
350
+ delayedStartRunnable = null;
351
+ }
352
+
353
+ if (speechRecognizer != null) {
354
+ speechRecognizer.cancel();
355
+ speechRecognizer.destroy();
356
+ speechRecognizer = null;
357
+ }
358
+
359
+ currentCall = null;
360
+ speechIntent = null;
361
+ });
362
+
363
+ // 4.2 Esperar 500ms
364
+ Thread.sleep(500);
365
+ }
366
+
367
+ // 4.3 Reiniciar
368
+ getActivity().runOnUiThread(() -> {
369
+ isListening = true;
370
+ isDestroyed = false;
371
+
372
+ // Usar el call ORIGINAL pero solo para startListeningInternal
373
+ // No hay problema porque ya fue resuelto
374
+ startListeningInternal(call, lang);
375
+ });
376
+
377
+ } catch (Exception e) {
378
+ // Log error si es necesario
379
+ }
380
+ }).start();
365
381
  }
366
382
 
367
383
  private void destroyEverything() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-microphone",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "plugin to use the microphone",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",