1'use strict';
2
3const event = require('events');
4
5function setIfConfig(options) {
6    if (!options) {
7        throw new Error('params is invalid');
8    }
9    __native.WIFI.set_ifconfig(options);
10}
11
12function getIfConfig() {
13    var config = __native.WIFI.get_ifconfig();
14    if (!config) {
15        throw 'get ifconfig failed';
16    }
17    return config;
18}
19
20function connect(options) {
21    if(!options) {
22        throw new Error("invalid params");
23    }
24    __native.WIFI.connect(options, function(state) {
25        if (state == 1) {
26            console.log('wifi connected success')
27            event.emit('connect');
28        }
29    });
30}
31
32function disconnect() {
33    return __native.WIFI.disconnect();
34}
35
36function getState() {
37    var state;
38    state =  __native.WIFI.getState();
39    return state;
40}
41
42module.exports = {
43    setIfConfig,
44    getIfConfig,
45    connect,
46    disconnect,
47    getState
48}