louis49 / androidtv-remote

MIT License
68 stars 23 forks source link

ERR_UNHANDLED_ERROR #4

Closed Aymkdn closed 2 years ago

Aymkdn commented 2 years ago

Salut Louis,

J'ai installé hier androidtv-remote. J'ai réussi le pairing, par contre quand j'envoie une commande je reçois cette erreur (pour info j'ai essayé de redémarrer ma TV):

code: 'ERR_UNHANDLED_ERROR',
  context: {
    error: RemoteError {
      value: true,
      message: RemoteMessage {
        remoteKeyInject: RemoteKeyInject { keyCode: 91, direction: 3 }
      }
    }
  }

J'utilise le même exemple que toi (au passage dans le readme et example,js tu marques RemoteKeyCode.MUTE alors que ça devrait être RemoteKeyCode.KEYCODE_MUTE):

androidRemote.on('ready', async function (){
      androidRemote.sendKey(RemoteKeyCode.KEYCODE_MUTE, RemoteDirection.SHORT)
  }.bind(this))

En debug ça donne :

Start Remote Connect
192.168.0.47 Remote secureConnect
192.168.0.47 Receive : {"remoteConfigure":{"code1":639}}
192.168.0.47 Bytes : 5,10,3,8,255,4
Create Remote {"remoteConfigure":{"code1":622,"deviceInfo":{"unknown1":1,"unknown2":"1","packageName":"androitv-remote","appVersion":"1.0.0"}}}
DEBUG payload =>  {
  remoteConfigure: {
    code1: 622,
    deviceInfo: {
      model: undefined,
      vendor: undefined,
      unknown1: 1,
      unknown2: '1',
      packageName: 'androitv-remote',
      appVersion: '1.0.0'
    }
  }
}
DEBUG message =>  RemoteMessage {
  remoteConfigure: {
    code1: 622,
    deviceInfo: {
      model: undefined,
      vendor: undefined,
      unknown1: 1,
      unknown2: '1',
      packageName: 'androitv-remote',
      appVersion: '1.0.0'
    }
  }
}
DEBUG array of bytes =>  <Buffer 24 0a 22 08 ee 04 12 1d 18 01 22 01 31 2a 0f 61 6e 64 72 6f 69 74 76 2d 72 65 6d 6f 74 65 32 05 31 2e 30 2e 30>
Sending {"remoteConfigure":{"code1":622,"deviceInfo":{"unknown1":1,"unknown2":"1","packageName":"androitv-remote","appVersion":"1.0.0"}}}
Create Remote {"remoteKeyInject":{"keyCode":91,"direction":3}}
DEBUG payload =>  { remoteKeyInject: { keyCode: 91, direction: 3 } }
DEBUG message =>  RemoteMessage { remoteKeyInject: { keyCode: 91, direction: 3 } }
DEBUG array of bytes =>  <Buffer 06 52 04 08 5b 10 03>
Sending {"remoteKeyInject":{"keyCode":"KEYCODE_MUTE","direction":"SHORT"}}
192.168.0.47 Receive : {"remoteError":{"value":true,"message":{"remoteKeyInject":{"keyCode":"KEYCODE_MUTE","direction":"SHORT"}}}}
192.168.0.47 Bytes : 12,26,10,8,2,18,6,82,4,8,91,16,3

J'ai vu que tu as fait une màj aujourd'hui (v1.0.6) donc j'ai mis à jour et j'ai utilisé le fichier example.js mais maintenant j'obtiens:

Start Remote Connect
Error: error:0680009B:asn1 encoding routines::too long
    at node:internal/tls/secure-context:65:13
    at Array.forEach (<anonymous>)
    at setCerts (node:internal/tls/secure-context:63:3)
    at configSecureContext (node:internal/tls/secure-context:152:5)
    at Object.createSecureContext (node:_tls_common:116:3)
    at Object.connect (node:_tls_wrap:1621:48)
    at D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:48:37
    at new Promise (<anonymous>)
    at D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:39:14
    at Generator.next (<anonymous>) {
  opensslErrorStack: [
    'error:0488000D:PEM routines::ASN1 lib',
    'error:0688010A:asn1 encoding routines::nested asn1 error',
    'error:06800066:asn1 encoding routines::bad object header'
  ],
  library: 'asn1 encoding routines',
  reason: 'too long',
  code: 'ERR_OSSL_ASN1_TOO_LONG'
}
D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:148
      _this2.client.destroy();
                    ^

TypeError: Cannot read properties of undefined (reading 'destroy')
    at D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:148:21
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:22:103)
    at _next (D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:24:194)
    at D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:24:364
    at new Promise (<anonymous>)
    at D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:24:97
    at RemoteManager.stop (D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\remote\RemoteManager.js:149:7)
    at AndroidRemote.stop (D:\experiments\android_pop\js\node_modules\androidtv-remote\dist\index.js:102:24)
    at file:///D:/experiments/android_pop/js/example.js:106:15

Une idée du problème ?

Je continue à bidouiller pour essayer de comprendre ce qu'il se passe…

Merci

Aymkdn commented 2 years ago

Concernant la v1.0.6 j'ai réussi à "faire fonctionner" mais j'obtiens la même erreur que précédemment :

code: 'ERR_UNHANDLED_ERROR',
  context: {
    error: RemoteError {
      value: true,
      message: RemoteMessage {
        remoteKeyInject: RemoteKeyInject { keyCode: 91, direction: 3 }
      }
    }
  }
Aymkdn commented 2 years ago

À noter qu'avec Assistant Cloud j'ai aussi une erreur (en bytes) qui est : [26,9,8,2,18,5,18,3,8,238,4]

Et je ne comprends pas d'où ça vient :-(

Aymkdn commented 2 years ago

Après avoir installé FreeTelec puis avoir constaté que ça marchait avec l'appli, tout s'est débloqué pour une raison inconnue…

Maintenant je n'ai plus d'erreur sur ton programme ni avec Assistant Cloud… Par contre androidtv-remote ne semble pas exécuter la commande (j'ai essayé avec du volume up/down, avec mute, avec du RemoteDirection.SHORT et du RemoteDirection.START_LONG/RemoteDirection.END_LONG:

Start Remote Connect
192.168.0.47 Remote secureConnect
192.168.0.47 Receive in Bytes : 5,10,3,8,255,4
192.168.0.47 Receive : {"remoteConfigure":{"code1":639}}
Create Remote {"remoteConfigure":{"code1":622,"deviceInfo":{"unknown1":1,"unknown2":"1","packageName":"androitv-remote","appVersion":"1.0.0"}}}
Sending in Bytes 36,10,34,8,238,4,18,29,24,1,34,1,49,42,15,97,110,100,114,111,105,116,118,45,114,101,109,111,116,101,50,5,49,46,48,46,48
Sending {"remoteConfigure":{"code1":622,"deviceInfo":{"unknown1":1,"unknown2":"1","packageName":"androitv-remote","appVersion":"1.0.0"}}}
Create Remote {"remoteKeyInject":{"keyCode":91,"direction":3}}
Sending in Bytes 6,82,4,8,91,16,3
Sending {"remoteKeyInject":{"keyCode":"KEYCODE_MUTE","direction":"SHORT"}}
192.168.0.47 Receive in Bytes : 2,18,0
192.168.0.47 Receive : {"remoteSetActive":{}}
Create Remote {"remoteSetActive":{"active":622}}
Sending in Bytes 5,18,3,8,238,4
Sending {"remoteSetActive":{"active":622}}
192.168.0.47 Receive in Bytes : 5,194,2,2,8,1
192.168.0.47 Receive : {"remoteStart":{"started":true}}
Powered : true
192.168.0.47 Receive in Bytes : 18,146,3,15,8,9,16,10,26,7,84,80,77,49,55,49,69,32,1
192.168.0.47 Receive : {"remoteSetVolumeLevel":{"unknown1":9,"unknown2":10,"playerModel":"TPM171E","unknown4":1}}
Volume : 0/0 | Muted : false
192.168.0.47 Receive in Bytes : 25,162,1,22,10,20,98,18,111,114,103,46,100,114,111,105,100,116,118,46,112,108,97,121,116,118
192.168.0.47 Receive : {"remoteImeKeyInject":{"appInfo":{"appPackage":"org.droidtv.playtv"}}}
Current App : org.droidtv.playtv
192.168.0.47 Receive in Bytes : 9,66,7,8,1,16,207,242,176,2
Sending in Bytes 4,74,2,8,1
192.168.0.47 Receive in Bytes : 9,66,7,8,2,16,239,153,177,2
Sending in Bytes 4,74,2,8,2

La commande est envoyée trop tôt, du coup je rajoute un délai:

androidRemote.on('ready', async function (){
      // délai nécessaire sinon la commande est envoyée trop tôt
      await new Promise(resolve => setTimeout(resolve, 2000));
      androidRemote.sendKey(RemoteKeyCode.KEYCODE_MUTE, RemoteDirection.SHORT)
  }.bind(this))

En faisant ça, le MUTE est bien activé sur la TV !

louis49 commented 2 years ago

Oui j’avais remarqué qu’on pouvait rencontrer des erreurs si on envoyait tout de suite des commandes juste après le ready : mettre 2s d’attente est un bon workaround

louis49 commented 2 years ago

Je vais corriger l’exemple qui effectivement contenait une erreur

louis49 commented 2 years ago

Corrigé dans la V1.0.7

piyush2greedy commented 2 years ago

@Aymkdn What is the use case u r working on.

Aymkdn commented 2 years ago

It's for controlling a French set-top box with Google and Alexa, and also to build a documentation https://github.com/Aymkdn/assistant-freebox-cloud/wiki/Google-TV-(aka-Android-TV)-Remote-Control-(v2)

Ganime422 commented 2 years ago

@Aymkdn have you managed to get keyboards keys to work? such as KEYCODE_A, KEYCODE_F etc. ?

Aymkdn commented 2 years ago

@Ganime422 I didn't try as only TV controls interest me.