jacobrosenthal / react-native-ble

Central role BLE for react native noble api surface
MIT License
169 stars 45 forks source link

Illegal invocation #12

Open Grandiz opened 8 years ago

Grandiz commented 8 years ago

if i call noble.on('stateChange', console.log); i will get an error

Illegal invocation Noble.EventEmitter.emit events.js @77:0

here is full code. could anyone help?


import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
    TouchableHighlight,
    DeviceEventEmitter
} from 'react-native';
import Orientation from 'react-native-orientation';

import { Accelerometer } from 'NativeModules';
var noble = require('react-native-ble');

Accelerometer.setAccelerometerUpdateInterval(5);
class arduinoCar extends Component {

    handlePressIn(){
        Accelerometer.startAccelerometerUpdates();
    }

    handlePressOut(){
        Accelerometer.stopAccelerometerUpdates();
    }

    componentWillMount(){
        noble.on('stateChange', console.log);
        //noble.on('discover', console.log);

    }

    componentDidMount(){
        Orientation.lockToLandscape();
        DeviceEventEmitter.addListener('AccelerationData', function (data) {
            console.log('acceleration data ', data.acceleration);
        });
    }

  render() {
    return (
      <View style={styles.container}>
          <TouchableHighlight underlayColor='#A74040'
                                style={styles.button}
                              onPressIn={this.handlePressIn}
                              onPressOut={this.handlePressOut}>
            <Text style={styles.buttonText}>Start</Text>
          </TouchableHighlight>
      </View>
    );
  }
}
AppRegistry.registerComponent('arduinoCar', () => arduinoCar);
Shakarang commented 8 years ago

It's norman, you should give a handler. What you can do is noble.on('stateChange', function(state) { // Your code here });

DavoCg commented 8 years ago

but console.log is a handler !