plasticrake / tplink-smarthome-api

TP-Link Smarthome WiFi API
MIT License
1.02k stars 141 forks source link

Angular integration #79

Closed BlueCC8 closed 4 years ago

BlueCC8 commented 4 years ago

Hello everybody, I tried to use this api in an angular app and I get two errors right from the start by running ng serve.

Errors encountered:

ERROR in ./node_modules/tplink-smarthome-api/lib/client.js Module not found: Error: Can't resolve 'dgram' and ERROR in ./node_modules/tplink-smarthome-api/lib/client.js Module not found: Error: Can't resolve 'net'

Tested Code:

import { Component } from '@angular/core';
const { Client } = require('tplink-smarthome-api');
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  constructor() {
    const client = new Client();
    // Look for devices, log to console, and turn them on
    client.startDiscovery().on('device-new', device => {
      device.getSysInfo().then(console.log);
      device.setPowerState(true);
    });
  }
}

I am using an Angular project generated with ng new.

Is there a way to fix this? Thank you in adavance for any help!

plasticrake commented 4 years ago

This is a node module to be run on the node runtime, not in the browser