nathankellenicki / node-poweredup

A Javascript module to interface with LEGO Powered Up components.
https://nathankellenicki.github.io/node-poweredup/
MIT License
478 stars 59 forks source link

Can't connect in ts application #88

Closed DashyGamaki closed 4 years ago

DashyGamaki commented 4 years ago

Hi,

I created a Ionic application where I try to connect to a hub. I implemented the plugin in ts instead of js, however it gets stuck on "Scanning for Hubs" and the promise never resolve.

import { Component, OnInit } from '@angular/core';
import { PoweredUP } from 'node_modules/node-poweredup/dist/node/poweredup-browser';

@Component({
  selector: 'app-poweredup',
  templateUrl: './poweredup.component.html',
  styleUrls: ['./poweredup.component.scss'],
})
export class PoweredupComponent implements OnInit {
  constructor(public poweredUP: PoweredUP) {}

  ngOnInit() {
    this.poweredUP.on('discover', async (hub) => {
      // Wait to discover a Hub
      console.log(`Discovered ${hub.name}!`);
      await hub.connect(); // Connect to the Hub
      console.log('Connected');
    });
  }

  scan() {
    this.poweredUP.scan().then();
    console.log('Scanning for Hubs...');
  }
}

I searched in the async _discoveryEventHandler(server) function of poweredup-bowser.js to see where the scanning stop, and i found out that the event handler never goes through this line :

if (isLPF2Hub) {
     hubType = await this._determineLPF2HubType(device);
}

The eventHandler seems to be stuck here and I can't find a solution. Any idea?

nathankellenicki commented 4 years ago

What hardware are you using to test this under?

Can you run it by setting localStorage DEBUG=* and pasting console output?

nathankellenicki commented 4 years ago

Closed due to inactivity.