lib/WiFi.js
function(next) {
      function finishJoining(err) {
        targetService.removeListener('PropertyChanged', onChange);
        if (typeof(passphraseSender) == 'function') {
          self.connman.Agent.removeListener('RequestInput', passphraseSender);
          passphraseSender = null
        }
        next(err);
      }
      function onChange(type, value) {
        if (type !== 'State') return;
        debug('service State: ', value);
        switch (value) {
          // when wifi ready and online
          case STATES.READY:
          case STATES.ONLINE:
            clearTimeout(timeout);
            finishJoining()
            break;
          case STATES.DISCONNECT:
          case STATES.FAILURE:
            clearTimeout(timeout);
            var err = new Error('Joining network failed (wrong password?)');
            finishJoining(err);
            // ToDo include error... (sometimes there is a Error property change, with a value like 'invalid-key')
            break;
        }
      }
      timeout = setTimeout(function(){
        var err = new Error('Joining network failed (Timeout)');
        finishJoining(err);
      }, _timeoutJoin);
      targetService.on('PropertyChanged', onChange);
    }
function(next) {
      function finishJoining(err) {
        targetService.removeListener('PropertyChanged', onChange);
        if (typeof(passphraseSender) == 'function') {
          self.connman.Agent.removeListener('RequestInput', passphraseSender);
          passphraseSender = null
        }
        next(err);
      }
      function onChange(type, value) {
        if (type !== 'State') return;
        debug('service State: ', value);
        switch (value) {
          // when wifi ready and online
          case STATES.READY:
          case STATES.ONLINE:
            clearTimeout(timeout);
            finishJoining()
            break;
          case STATES.DISCONNECT:
          case STATES.FAILURE:
            clearTimeout(timeout);
            var err = new Error('Joining network failed (wrong password?)');
            finishJoining(err);
            // ToDo include error... (sometimes there is a Error property change, with a value like 'invalid-key')
            break;
        }
      }
      timeout = setTimeout(function(){
        var err = new Error('Joining network failed (Timeout)');
        finishJoining(err);
      }, _timeoutJoin);
      targetService.on('PropertyChanged', onChange);
    }
function ( next ) { function finishJoining ( err ) { targetService . removeListener ( 'PropertyChanged' , onChange ) ; if ( typeof ( passphraseSender ) == 'function' ) { self . connman . Agent . removeListener ( 'RequestInput' , passphraseSender ) ; passphraseSender = null } next ( err ) ; } function onChange ( type , value ) { if ( type !== 'State' ) return ; debug ( 'service State: ' , value ) ; switch ( value ) { // when wifi ready and online case STATES . READY : case STATES . ONLINE : clearTimeout ( timeout ) ; finishJoining ( ) break ; case STATES . DISCONNECT : case STATES . FAILURE : clearTimeout ( timeout ) ; var err = new Error ( 'Joining network failed (wrong password?)' ) ; finishJoining ( err ) ; // ToDo include error... (sometimes there is a Error property change, with a value like 'invalid-key') break ; } } timeout = setTimeout ( function ( ) { var err = new Error ( 'Joining network failed (Timeout)' ) ; finishJoining ( err ) ; } , _timeoutJoin ) ; targetService . on ( 'PropertyChanged' , onChange ) ; }
listen to state
listen to state