Skip to content

Commit

Permalink
Fixed cannot resolve module errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gcalica committed Apr 1, 2019
1 parent 8a9ca35 commit b15e1d0
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 353 deletions.
4 changes: 2 additions & 2 deletions app/containers/Bulb/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// // import Yeelight from '../Yeelight';
// const Yeelight = require('../Yeelight/index');
//
// export default class Bulb {
// constructor(info) {
Expand All @@ -8,7 +8,7 @@
// this[i] = info[i];
// }
//
// // this.yeelight = new Yeelight();
// this.yeelight = new Yeelight();
// }
//
// togglePower(callback) {
Expand Down
17 changes: 12 additions & 5 deletions app/containers/HomePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import React from 'react';
import { Button } from 'semantic-ui-react';
import Bulbs from '../../../server/index';
import Yeelight from '../Yeelight/index';

/* eslint-disable react/prefer-stateless-function */
Expand All @@ -22,13 +23,19 @@ export default class HomePage extends React.Component {
refreshing: false,
bulbs: [],
};

this.yeelight = new Yeelight();
for (let i = 0; i < Bulbs.length; i++) {
this.state.bulbs.push(Bulbs[i]);
}
this.yeelight = Yeelight.getInstance();
this.handleClick = this.handleClick.bind(this);
this.toggleBulb = this.toggleBulb.bind(this);
}

toggleBulb = () => this.yeelight.togglePower();
toggleBulbPower() {
for (let bulb = 0; bulb < this.state.bulbs.length; bulb++) {
this.state.bulbs[bulb].togglePower();
}
}

handleClick = () => this.discoverBulbs();

Expand Down Expand Up @@ -58,8 +65,8 @@ export default class HomePage extends React.Component {
render() {
return (
<div>
<Button basic content="Connect" onClick={this.handleClick} />
{/* <Button content="Toggle" onClick={this.toggleBulb()} /> */}
{/* <Button basic content="Connect" onClick={this.handleClick} /> */}
<Button content="Toggle" onClick={this.toggleBulbPower()} />
</div>
);
}
Expand Down
275 changes: 49 additions & 226 deletions app/containers/Yeelight/index.js
Original file line number Diff line number Diff line change
@@ -1,228 +1,51 @@
/* eslint-disable no-console */
// import Bulb from '../Bulb';
// const dgram = require('dgram');
// /* eslint-disable no-console */
// const net = require('net');
// import port from '../../../server/port';
// const WebSocket = require('isomorphic-ws');
// function b64Encode(str) {
// return Buffer.from(str).toString('base64');
// }

// function b64Decode(encodedStr) {
// return Buffer.from(encodedStr, 'base64').toString();
// }
//
export default class Yeelight {
// config = {
// multicastHost: '239.255.255.250',
// multicastPort: 1982,
// };
//
// discoverBulbs(callback) {
// const bulbs = [];
//
// const intKeys = [
// 'bright',
// 'color_mode',
// 'ct',
// 'fw_ver',
// 'hue',
// 'rgb',
// 'sat',
// ];
//
// const message = Buffer.from(
// 'M-SEARCH * HTTP/1.1\r\n' +
// 'HOST: 239.255.255.250:1982\r\n' +
// 'MAN: "ssdp:discover"\r\n' +
// 'ST: wifi_bulb\r\n',
// );
//
// const pingTimeout = setTimeout(() => {
// client.close();
// callback(null);
// });
//
// const client = dgram.createSocket('udp4');
// client.on('message', (msg, rinfo) => {
// console.log(`Client got: ${msg} from ${rinfo.address}:${rinfo.port}`);
// client.close();
// clearTimeout(pingTimeout);
//
// const newBulbInfo = {};
//
// const splitMsg = msg.toString().split('\r\n');
// const slicedMsg = splitMsg.slice(1, msg.length - 1);
//
// // Message to object
// slicedMsg.forEach(line => {
// const key = line.substr(0, line.indexOf(':')).trim();
// const value = line.substr(line.indexOf(':') + 1).trim();
//
// if (intKeys.includes(key)) {
// newBulbInfo[key] = parseInt(value, 10);
// } else if (key === 'name') {
// newBulbInfo[key] = b64Decode(value);
// } else if (key === 'support') {
// newBulbInfo[key] = value.split(' ');
// } else {
// newBulbInfo[key] = value;
// }
//
// // Put additional ip and port info
// if (key === 'Location') {
// const bulbUrl = value.replace('yeelight://', '');
// const [bulbIp, bulbPort] = bulbUrl.split(':');
// newBulbInfo.ip = bulbIp.trim();
// newBulbInfo.port = parseInt(bulbPort.trim(), 10);
// }
// });
//
// bulbs.push(new Bulb(newBulbInfo));
// callback(bulbs);
// });
//
// client.send(
// message,
// 0,
// message.length,
// this.config.multicastPort,
// this.config.multicastHost,
// err => {
// if (err) {
// client.close();
// clearTimeout(pingTimeout);
// callback(null);
// }
// },
// );
// const socketProtocol =
// window.location.protocol === 'https:' ? 'wss:' : 'ws:';
// const socketPort = window.location.port !== '' ? port : '';
// let echoSocketUrl;
// if (socketPort !== '') {
// echoSocketUrl = `${socketProtocol}//${
// window.location.hostname
// }:${socketPort}/`;
// } else {
// echoSocketUrl = `${socketProtocol}//${window.location.hostname}`;
// }
// console.log(echoSocketUrl);
// const client = new WebSocket(echoSocketUrl);
// const pingTimeout = setTimeout(() => {
// client.close();
// callback(null);
// }, 10000 + 5000);
//
// client.onopen = () => {
// console.log('Websocket Client Connection Opened');
// client.send(message, Object.create({}), null);
// };
//
// client.onmessage = msg => {
// console.log('Message received');
// console.log(msg);
// client.close();
// clearTimeout(pingTimeout);
//
// const newBulbInfo = {};
//
// const splitMsg = msg.toString().split('\r\n');
// const newMessage = splitMsg.slice(1, msg.length - 1);
//
// // Message to object
// newMessage.forEach(line => {
// const key = line.substr(0, line.indexOf(':')).trim();
// const value = line.substr(line.indexOf(':') + 1).trim();
//
// if (intKeys.includes(key)) {
// newBulbInfo[key] = parseInt(value, 10);
// } else if (key === 'name') {
// newBulbInfo[key] = b64Decode(value);
// } else if (key === 'support') {
// newBulbInfo[key] = value.split(' ');
// } else {
// newBulbInfo[key] = value;
// }
//
// // Put additional ip and port info
// if (key === 'Location') {
// const bulbUrl = value.replace('yeelight://', '');
// const [bulbIp, bulbPort] = bulbUrl.split(':');
// newBulbInfo.ip = bulbIp.trim();
// newBulbInfo.port = parseInt(bulbPort.trim(), 10);
// }
// });
//
// console.log(newBulbInfo);
// bulbs.push(new Bulb(newBulbInfo));
// callback(bulbs);
// };
//
// client.onclose = () => {
// console.log('WebSocket Client Connection Closed');
// clearTimeout(pingTimeout);
// };
// const discoveryTimeout = setTimeout(() => {
// socket.close(3000, 'closing');
// callback(null);
// }, 10000);
// }
//
// sendCommand(ip, port, command, callback) {
// // Callback returns success:boolean
// const socketProtocol =
// window.location.protocol === 'https:' ? 'wss:' : 'ws:';
// const socketPort = window.location.port !== '' ? port : '';
// let echoSocketUrl;
// if (socketPort !== '') {
// echoSocketUrl = `${socketProtocol}//${
// window.location.hostname
// }:${socketPort}/`;
// } else {
// echoSocketUrl = `${socketProtocol}//${window.location.hostname}`;
// }
//
// const client = new WebSocket(echoSocketUrl);
// client.send(`${JSON.stringify(command)}\r\n`, Object.create({}), null);
// callback(false);
// const client = net.createConnection(port, ip, () => {
// client.write(`${JSON.stringify(command)}\r\n`);
// });
// client.setTimeout(3000, () => {
// client.destroy();
// callback(false);
// });
//
// client.on('data', data => {
// client.destroy();
//
// const response = JSON.parse(data.toString());
//
// if (response.result !== undefined) {
// const success = response.result[0] === 'ok';
// callback(success);
// } else if (response.error !== undefined) {
// callback(false);
// }
// });
//
// client.on('error', error => {
// client.destroy();
// console.log(error);
// callback(false);
// });
// }
//
// togglePower(ip, port, msgId, callback) {
// // Callback returns success:boolean
//
// const command = {
// id: msgId,
// method: 'toggle',
// params: [],
// };
//
// this.sendCommand(ip, port, command, callback);
// }
}
// export default class Yeelight {
// constructor(data) {
// this.data = data;
// }
//
// sendCommand(ip, port, command, callback) {
// // Callback returns success:boolean
// const client = net.createConnection(port, ip, () => {
// client.write(`${JSON.stringify(command)}\r\n`);
// });
//
// client.setTimeout(3000, () => {
// client.destroy();
// callback(false);
// });
//
// client.on('data', data => {
// client.destroy();
//
// const response = JSON.parse(data.toString());
//
// if (response.result !== undefined) {
// const success = response.result[0] === 'ok';
// callback(success);
// } else if (response.error !== undefined) {
// callback(false);
// }
// });
//
// client.on('error', error => {
// client.destroy();
// console.log(error);
// callback(false);
// });
// }
//
// togglePower(ip, port, msgId, callback) {
// // Callback returns success:boolean
//
// const command = {
// id: msgId,
// method: 'toggle',
// params: [],
// };
//
// this.sendCommand(ip, port, command, callback);
// }
// }
9 changes: 8 additions & 1 deletion internals/webpack/webpack.base.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const webpack = require('webpack');
process.noDeprecation = true;

module.exports = options => ({
node: {
fs: 'empty',
child_process: 'empty',
tls: 'empty',
dgram: 'empty',
module: 'empty',
},
mode: options.mode,
entry: options.entry,
output: Object.assign(
Expand Down Expand Up @@ -125,7 +132,7 @@ module.exports = options => ({
]),
resolve: {
modules: ['node_modules', 'app'],
extensions: ['.js', '.jsx', '.react.js'],
extensions: ['.js', '.jsx', '.react.js', '.json'],
mainFields: ['browser', 'jsnext:main', 'main'],
},
devtool: options.devtool,
Expand Down
Loading

0 comments on commit b15e1d0

Please sign in to comment.