componentDidMount() {
    AppState.addEventListener('change', this.handleAppStateChange);

    BleManager.start({showAlert: false});

    this.handlerDiscover = bleManagerEmitter.addListener('BleManagerDiscoverPeripheral', this.handleDiscoverPeripheral );
    this.handlerStop = bleManagerEmitter.addListener('BleManagerStopScan', this.handleStopScan );
    this.handlerDisconnect = bleManagerEmitter.addListener('BleManagerDisconnectPeripheral', this.handleDisconnectedPeripheral );
    this.handlerUpdate = bleManagerEmitter.addListener('BleManagerDidUpdateValueForCharacteristic', this.handleUpdateValueForCharacteristic );



    if (Platform.OS === 'android' && Platform.Version >= 23) {
        PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
            if (result) {
              console.log("Permission is OK");
            } else {
              PermissionsAndroid.requestPermission(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
                if (result) {
                  console.log("User accept");
                } else {
                  console.log("User refuse");
                }
              });
            }
      });
    }

  }
/**
 * Notifies the feature jwt that the action {@link APP_WILL_MOUNT} is being
 * dispatched within a specific redux {@code store}.
 *
 * @param {Store} store - The redux store in which the specified {@code action}
 * is being dispatched.
 * @param {Dispatch} next - The redux dispatch function to dispatch the
 * specified {@code action} to the specified {@code store}.
 * @param {Action} action - The redux action {@code APP_WILL_MOUNT} which is
 * being dispatched in the specified {@code store}.
 * @private
 * @returns {*} The value returned by {@code next(action)}.
 */
function _appWillMount({ dispatch, getState }, next, action) {
    const result = next(action);

    const emitter = new NativeEventEmitter(Invite);
    const context = {
        dispatch,
        getState
    };

    dispatch({
        type: _SET_EMITTER_SUBSCRIPTIONS,
        emitterSubscriptions: [
            emitter.addListener(
                'org.jitsi.meet:features/invite#invite',
                _onInvite,
                context),
            emitter.addListener(
                'org.jitsi.meet:features/invite#performQuery',
                _onPerformQuery,
                context)
        ]
    });

    return result;
}
Exemple #3
0
    .then((music) => {
      MediaModel.init(music);

      this.listeners.push(this.eventEmitter.addListener('onPlayItemChanged', (payload) => {
        payload && AppStore.updateNowPlaying(MediaModel.getItem(payload));
      }));
      this.listeners.push(this.eventEmitter.addListener('onPlaybackStateChanged', (payload) => {
        AppStore.checkPause(payload);
      }));

      AppStore.isReady = true;
      this.forceUpdate();
    })
async function watchHeadingAsync(callback: HeadingCallback) {
  // Check if there is already a compass event watch.
  if (headingEventSub) {
    _removeHeadingWatcher(headingId);
  }

  headingEventSub = LocationEventEmitter.addListener(
    'Exponent.headingChanged',
    ({ watchId, heading }) => {
      const callback = watchCallbacks[watchId];
      if (callback) {
        callback(heading);
      } else {
        ExponentLocation.removeWatchAsync(watchId);
      }
    }
  );

  headingId = _getNextWatchId();
  watchCallbacks[headingId] = callback;
  await ExponentLocation.watchDeviceHeading(headingId);
  return {
    remove() {
      _removeHeadingWatcher(headingId);
    },
  };
}
 ({ watchId, heading }) => {
   if (heading.accuracy > 1 || tries > 5) {
     resolve(heading);
     LocationEventEmitter.removeSubscription(headingSub);
   } else {
     tries += 1;
   }
 }
// Removes the compass listener and sub from JS and Native
function _removeHeadingWatcher(watchId) {
  if (!watchCallbacks[watchId]) {
    return;
  }
  delete watchCallbacks[watchId];
  ExponentLocation.removeWatchAsync(watchId);
  LocationEventEmitter.removeSubscription(headingEventSub);
  headingEventSub = null;
}
 // TODO: We can optimize by only using time observer on native if (this._onPlaybackStatusUpdate).
 _subscribeToNativeStatusUpdateEvents() {
   if (this._loaded) {
     this._subscriptions.push(
       this._eventEmitter.addListener(
         'didUpdatePlaybackStatus',
         this._internalStatusUpdateCallback
       )
     );
   }
 }
Exemple #8
0
 remove: function remove() {
   if (!removed) {
     ExponentLocation.removeWatchAsync(watchId);
     delete watchCallbacks[watchId];
     if (Object.keys(watchCallbacks).length === 0) {
       LocationEventEmitter.removeSubscription(deviceEventSubscription);
       deviceEventSubscription = null;
     }
     removed = true;
   }
 }
 addEventListener: function(
   type: string,
   handler: Function
 ) {
   _statusBarSizeHandlers[handler] = StatusBarEmitter.addListener(
     DEVICE_STATUS_BAR_HEIGHT_EVENTS[type],
     (statusBarSizeData) => {
       handler(statusBarSizeData.height);
     }
   );
 },
const addEventListener = (event, handler) => {
  const mappedEvent = eventMap[event];
  if (mappedEvent) {
    let listener;
    if (event === 'adFailedToLoad') {
      listener = eventEmitter.addListener(mappedEvent, error => handler(createErrorFromErrorData(error)));
    } else {
      listener = eventEmitter.addListener(mappedEvent, handler);
    }
    _subscriptions.set(handler, listener);
    return {
      remove: () => removeEventListener(event, handler),
    };
  } else {
    // eslint-disable-next-line no-console
    console.warn(`Trying to subscribe to unknown event: "${event}"`);
    return {
      remove: () => {},
    };
  }
};
function _removeWatcher(watchId) {
  // Do nothing if we have already removed the subscription
  if (!watchCallbacks[watchId]) {
    return;
  }

  ExponentLocation.removeWatchAsync(watchId);
  delete watchCallbacks[watchId];
  if (Object.keys(watchCallbacks).length === 0) {
    LocationEventEmitter.removeSubscription(deviceEventSubscription);
    deviceEventSubscription = null;
  }
}
Exemple #12
0
  return regeneratorRuntime.async(function watchPositionAsync$(_context2) {
    while (1) {
      switch (_context2.prev = _context2.next) {
        case 0:
          ExponentLocation = _reactNative.NativeModules.ExponentLocation;


          if (!deviceEventSubscription) {
            deviceEventSubscription = LocationEventEmitter.addListener('Exponent.locationChanged', function (_ref) {
              var watchId = _ref.watchId,
                  location = _ref.location;

              var callback = watchCallbacks[watchId];
              if (callback) {
                callback(location);
              } else {
                ExponentLocation.removeWatchAsync(watchId);
              }
            });
          }

          watchId = nextWatchId++;

          watchCallbacks[watchId] = callback;
          _context2.next = 6;
          return regeneratorRuntime.awrap(ExponentLocation.watchPositionImplAsync(watchId, options));

        case 6:
          removed = false;
          return _context2.abrupt('return', {
            remove: function remove() {
              if (!removed) {
                ExponentLocation.removeWatchAsync(watchId);
                delete watchCallbacks[watchId];
                if (Object.keys(watchCallbacks).length === 0) {
                  LocationEventEmitter.removeSubscription(deviceEventSubscription);
                  deviceEventSubscription = null;
                }
                removed = true;
              }
            }
          });

        case 8:
        case 'end':
          return _context2.stop();
      }
    }
  }, null, this);
function _maybeInitializeEmitterSubscription() {
  if (!deviceEventSubscription) {
    deviceEventSubscription = LocationEventEmitter.addListener(
      'Exponent.locationChanged',
      ({ watchId, location }) => {
        const callback = watchCallbacks[watchId];
        if (callback) {
          callback(location);
        } else {
          ExponentLocation.removeWatchAsync(watchId);
        }
      }
    );
  }
}
export function watchStepCount(callback) {
    if (_listenerCount === 0) {
        NativeModules.ExponentPedometer.watchStepCount();
    }
    _listenerCount++;
    const listener = PedometerEventEmitter.addListener('Exponent.pedometerUpdate', callback);
    return {
        remove() {
            listener.remove();
            _listenerCount--;
            if (_listenerCount === 0) {
                NativeModules.ExponentPedometer.stopWatchingStepCount();
            }
        },
    };
}
  return new Promise(async (resolve, reject) => {
    try {
      // If there is already a compass active (would be a watch)
      if (headingEventSub) {
        let tries = 0;
        const headingSub = LocationEventEmitter.addListener(
          'Exponent.headingChanged',
          ({ watchId, heading }) => {
            if (heading.accuracy > 1 || tries > 5) {
              resolve(heading);
              LocationEventEmitter.removeSubscription(headingSub);
            } else {
              tries += 1;
            }
          }
        );
      } else {
        let done = false;
        let subscription;
        let tries = 0;
        subscription = await watchHeadingAsync(heading => {
          if (!done) {
            if (heading.accuracy > 1 || tries > 5) {
              subscription.remove();
              resolve(heading);
              done = true;
            } else {
              tries += 1;
            }
          } else {
            subscription.remove();
          }
        });

        if (done) {
          subscription.remove();
        }
      }
    } catch (e) {
      reject(e);
    }
  });
Exemple #16
0
      +onExit: (error: any, metadata: Object) => void,
      +onEvent: ?(event: string, metadata: Object) => void,
    |},
  ) {
    if (typeof configuration.onSuccess !== 'function') {
      throw new Error('Must provide an onSuccess callback');
    }
    if (typeof configuration.onExit !== 'function') {
      throw new Error('Must provide an onExit callback');
    }
    if (configuration.webhook && configuration.webhook.length > 0 && !configuration.webhook.startsWith('http')) {
      throw new Error('webhook parameter must be a valid HTTP(S) URL');
    }

    RNLinkkit._create(configuration);
    var emitter = new NativeEventEmitter(RNLinkkit);

    emitter.addListener("onSuccess", payload => {
      configuration.onSuccess(payload.publicToken, payload.metadata);
    });

    emitter.addListener("onExit", payload => {
      configuration.onExit(payload.error, payload.metadata);
    });

    if (configuration.onEvent) {
      emitter.addListener("onEvent", payload => {
        configuration.onEvent(payload.event, payload.metadata);
      });
    }
    return this;
 addListener: function(event, callback) {
   if (this.events.indexOf(event) < 0) {
     throw "RNBackgroundFetch: Unknown event '" + event + '"';
   }
   return EventEmitter.addListener(event, callback);
 },
/**
 * @providesModule StatusBarSizeIOS
 * @flow
 */
'use strict';

const { NativeEventEmitter, NativeModules } = require('react-native');
const { RNStatusBarSize } = NativeModules;
const StatusBarEmitter = new NativeEventEmitter(RNStatusBarSize);

var DEVICE_STATUS_BAR_HEIGHT_EVENTS = {
  willChange: 'statusBarSizeWillChange',
  didChange: 'statusBarSizeDidChange',
  change: 'statusBarSizeDidChange'
};

var _statusBarSizeHandlers = {};
var noop = function() {};

/**
 * `StatusBarSizeIOS` can tell you what the current height of the status bar
 * is, so that you can adjust your layout accordingly when a phone call
 * notification comes up, for example.
 *
 * ### Basic Usage
 *
 * To see the current height, you can check `StatusBarSizeIOS.currentHeight`, which
 * will be kept up-to-date. However, `currentHeight` will be null at launch
 * while `StatusBarSizeIOS` retrieves it over the bridge.
 *
 * ```
Exemple #19
0
function removeSpeakingListener(eventName) {
  SpeechEventEmitter.removeAllListeners(eventName);
}
Exemple #20
0
function setSpeakingListener(eventName, callback) {
  if (SpeechEventEmitter.listeners(eventName).length > 0) {
    SpeechEventEmitter.removeAllListeners(eventName);
  }
  SpeechEventEmitter.addListener(eventName, callback);
}
 componentDidMount() {
     this.mounted = true;
     this.eventEmitter = new NativeEventEmitter(NativeModules.RNReactNativeDocViewer);
     this.eventEmitter.addListener('DoneButtonEvent', () => this.setStatusBarColor());
 }
 componentWillUnmount() {
     this.mounted = false;
     this.eventEmitter.removeListener();
 }
Exemple #23
0
	async componentDidMount() {
		AppState.addEventListener("change", this.handleAppStateChange);

		await BleManager.start({
			showAlert: false
		});

		var boards = await StateBuilder.getBoards();

		if (boards) {
			this.setState({
				boardData: boards,
			});
		}

		this.handlerDiscover = bleManagerEmitter.addListener("BleManagerDiscoverPeripheral", this.handleDiscoverPeripheral);
		this.handlerStop = bleManagerEmitter.addListener("BleManagerStopScan", this.handleStopScan);
		this.handlerDisconnect = bleManagerEmitter.addListener("BleManagerDisconnectPeripheral", this.handleDisconnectedPeripheral);
		this.handlerNewData = bleManagerEmitter.addListener("BleManagerDidUpdateValueForCharacteristic", this.handleNewData);

		// this is a hack for android permissions. Not required for IOS.
		if (Platform.OS === "android" && Platform.Version >= 23) {
			PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
				if (result) {
					console.log("BoardManager: Permission is OK");
				} else {
					PermissionsAndroid.requestPermission(PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION).then((result) => {
						if (result) {
							console.log("BoardManager: User accept");
						} else {
							console.log("BoardManager: User refuse");
						}
					});
				}
			});

			PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION).then((result) => {
				if (result) {
					console.log("BoardManager: Permission is OK");
				} else {
					PermissionsAndroid.requestPermission(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION).then((result) => {
						if (result) {
							console.log("BoardManager: User accept");
						} else {
							console.log("BoardManager: User refuse");
						}
					});
				}
			});
		}

		// if there is a default BleDevice saved, scan and attempt to load that board.
		var config = await FileSystemConfig.getDefaultPeripheral();
		if (config) {
			this.setState({
				boardName: config.name,
			});

			await this.startScan(true);
		}
		this.readPhoneLocationLoop();
	}
 _removeListener(evt) {
   return FirestackStorageEvt.removeListener(evt);
 }
const removeEventListener = (type) => {
  SplashEventEmitter.removeAllListeners(type);
}
 _addListener(evt, cb) {
   return FirestackStorageEvt.addListener(evt, cb);
 }
 addDownloadListener: (callback: Callback): EmitterSubscription => eventEmitter.addListener('download', callback),
  componentDidMount() {
    // Initialization, configuration and adding of beacon regions
    init('MY_KONTAKTIO_API_KEY')
      .then(() => configure({
        dropEmptyRanges: true,    // don't trigger beacon events in case beacon array is empty
        invalidationAge: 5000,   // time to forget lost beacon
        // connectNearbyBeacons: false,   // true not working yet
      }))
      .then(() => this._requestAlwaysAuthorization())
      // .then(() => requestWhenInUseAuthorization())
      .then(() => console.log('Successfully initialized beacon ranging, monitoring and scanning'))
      .catch(error => console.log('error', error));

    // Monitoring events
    this.startMonitoringSubscription = kontaktEmitter.addListener(
      'didStartMonitoringForRegion',
      ({ region }) => {
        console.log('didStartMonitoringForRegion', region);
      }
    );
    this.monitoringFailSubscription = kontaktEmitter.addListener(
      'monitoringDidFailForRegion',
      ({ region, error }) => (
        console.log('monitoringDidFailForRegion', region , error)
      )
    );
    this.regionEnterSubscription = kontaktEmitter.addListener(
      'didEnterRegion',
      ({ region }) => {
        console.log('didEnterRegion', region);

        this.setState({
          monitoredRegionsCloseBy: this.state.monitoredRegionsCloseBy.concat(region)
        });
      }
    );
    this.regionExitSubscription = kontaktEmitter.addListener(
      'didExitRegion',
      ({ region: exitRegion }) => {
        console.log('didExitRegion', exitRegion);

        const { monitoredRegionsCloseBy } = this.state;
        const index = monitoredRegionsCloseBy.findIndex(region =>
          this._isIdenticalRegion(exitRegion, region)
        );
        this.setState({
          monitoredRegionsCloseBy: monitoredRegionsCloseBy.reduce((result, val, ind) => {
            // don't add disappeared region to array
            if (ind === index) return result;
            // add all other regions to array
            else {
              result.push(val);
              return result;
            }
          }, [])
        });
      }
    );

    // Ranging event
    this.regionRangeSubscription = kontaktEmitter.addListener(
      'didRangeBeacons',
      ({ beacons: rangedBeacons, region }) => {
        console.log('didRangeBeacons', rangedBeacons, region);
        this.setState({ rangedBeacons });
      }
    );
    this.regionRangeFailSubscription = kontaktEmitter.addListener(
      'rangingDidFailForRegion',
      ({ region, error }) => (
        console.log('rangingDidFailForRegion', region , error)
      )
    );

    // Authorization event
    this.authorizationSubscription = kontaktEmitter.addListener(
      'authorizationStatusDidChange',
      ({ status }) => {
        console.log('authorizationStatusDidChange', status);
        this.setState({ authorizationStatus: status });
      }
    );

    // Discovery event
    this.discoverSubscription = kontaktEmitter.addListener(
      'didDiscoverDevices',
      ({ beacons: discoveredBeacons }) => {
        console.log('didDiscoverDevices', discoveredBeacons);
        this.setState({ discoveredBeacons });
      }
    );
    this.discoverFailSubscription = kontaktEmitter.addListener(
      'discoveryDidFail',
      ({ error }) => (
        console.log('discoveryDidFail', error)
      )
    );
  }
                        continue;
                    }
                    const result = await wrapCb(child);
                    // Boolean true indicates we should stop iterating now.
                    // Flag for termination but continue iterating to release remaining snapshots.
                    if (result === true) {
                        terminated = true;
                    }
                }
            }));
    }

}

const eventListenersById = {};
const databaseEmitter = new NativeEventEmitter(NativeFirebaseBridgeDatabase);
databaseEmitter.addListener('databaseOn', data => {
    const { id, snapshot, error } = data;
    if (eventListenersById[id]) {
        const { listener, cancelCallback } = eventListenersById[id];
        if (!error) {
            listener(snapshot);
        } else {
            if (cancelCallback) {
                cancelCallback(new Error(error));
            }
        }
    }
});

export class Query {
const addEventListener = (type, handler) => {
  SplashEventEmitter.addListener(type, handler);
};