@wemap/positioning 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/.eslintrc.json +4 -2
  2. package/debug/absolute-attitude.html +16 -0
  3. package/debug/arcore.html +16 -0
  4. package/debug/gnss-wifi-pdr.html +16 -0
  5. package/debug/gnss-wifi.html +16 -0
  6. package/debug/imu.html +16 -0
  7. package/debug/inclination.html +16 -0
  8. package/debug/pdr.html +16 -0
  9. package/debug/pose.html +16 -0
  10. package/debug/positioning.html +16 -0
  11. package/debug/relative-attitude.html +16 -0
  12. package/package.json +7 -4
  13. package/src/PositioningHandler.js +96 -34
  14. package/src/components/AbsoluteAttitudeComponent.jsx +104 -0
  15. package/src/components/ArCoreComponent.jsx +74 -0
  16. package/src/components/GnssWifiComponent.jsx +58 -0
  17. package/src/components/GnssWifiPdrComponent.jsx +94 -0
  18. package/src/components/ImuComponent.jsx +100 -0
  19. package/src/components/InclinationComponent.jsx +53 -0
  20. package/src/components/MapComponent.jsx +226 -0
  21. package/src/components/PdrComponent.jsx +97 -0
  22. package/src/components/PoseComponent.jsx +81 -0
  23. package/src/components/PositioningComponent.jsx +26 -0
  24. package/src/components/PositioningInclinationComponent.jsx +76 -0
  25. package/src/components/PositioningPoseComponent.jsx +120 -0
  26. package/src/components/RelativeAttitudeComponent.jsx +82 -0
  27. package/src/components/StartStopComponent.jsx +50 -0
  28. package/src/components/Utils.js +92 -0
  29. package/src/components/index.js +32 -0
  30. package/src/errors/AskImuOnDesktopError.js +9 -0
  31. package/src/errors/GeolocationApiMissingError.js +9 -0
  32. package/src/errors/GeolocationPermissionDeniedError.js +9 -0
  33. package/src/errors/GeolocationPositionUnavailableError.js +9 -0
  34. package/src/errors/IpResolveServerError.js +9 -0
  35. package/src/errors/MissingAccelerometerError.js +11 -0
  36. package/src/errors/MissingArCoreError.js +9 -0
  37. package/src/errors/MissingGyroscopeError.js +11 -0
  38. package/src/errors/MissingMagnetometerError.js +9 -0
  39. package/src/errors/MissingNativeInterfaceError.js +9 -0
  40. package/src/errors/MissingSensorError.js +14 -0
  41. package/src/events/EventType.js +20 -0
  42. package/src/events/ProviderError.js +52 -0
  43. package/src/events/ProviderEvent.js +35 -0
  44. package/src/index.js +2 -2
  45. package/src/providers/Constants.js +5 -0
  46. package/src/providers/FakeAbsolutePositionProvider.js +56 -0
  47. package/src/providers/Provider.js +230 -0
  48. package/src/providers/ProviderOptions.js +28 -0
  49. package/{src.old → src}/providers/ProvidersLogger.js +2 -2
  50. package/src/providers/attitude/AbsoluteAttitudeProvider.js +207 -0
  51. package/src/providers/attitude/RelativeAttitudeProvider.js +129 -0
  52. package/src/providers/others/ImuProvider.js +186 -0
  53. package/src/providers/others/InclinationProvider.js +107 -0
  54. package/{src.old/providers/LocationSource.js → src/providers/others/MapMatchingProvider.js} +5 -148
  55. package/src/providers/pose/ArCoreProvider.js +127 -0
  56. package/src/providers/pose/GnssWifiPdrProvider.js +233 -0
  57. package/src/providers/pose/PoseProvider.js +90 -0
  58. package/{src.old/providers/PdrLocationSource.js → src/providers/pose/pdr/PdrProvider.js} +145 -113
  59. package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/Smoother.js +1 -1
  60. package/src/providers/position/GnssWifiProvider.js +129 -0
  61. package/src/providers/position/IpProvider.js +75 -0
  62. package/webpack/webpack.common.js +1 -1
  63. package/webpack/webpack.dev.js +1 -1
  64. package/debug/index.html +0 -15
  65. package/debug/index.old.html +0 -37
  66. package/scripts/release-github.js +0 -216
  67. package/src/providers/FakeLocationSource.js +0 -36
  68. package/src.old/Constants.js +0 -11
  69. package/src.old/NavigationHandler.js +0 -244
  70. package/src.old/Pose.js +0 -8
  71. package/src.old/attitude/AttitudeHandler.js +0 -342
  72. package/src.old/components/AbsoluteAttitude.jsx +0 -136
  73. package/src.old/components/Imu.jsx +0 -89
  74. package/src.old/components/LocationSource.jsx +0 -434
  75. package/src.old/components/Logger.jsx +0 -113
  76. package/src.old/components/NavigationDebugApp.jsx +0 -106
  77. package/src.old/components/Others.jsx +0 -121
  78. package/src.old/components/RelativeAttitude.jsx +0 -104
  79. package/src.old/components/Utils.js +0 -35
  80. package/src.old/components/index.js +0 -13
  81. package/src.old/index.js +0 -7
  82. package/src.old/providers/FixedLocationImuLocationSource.js +0 -66
  83. package/src.old/providers/GnssLocationSource.js +0 -118
  84. package/src.old/providers/GnssPdrLocationSource.js +0 -182
  85. package/src.old/providers/IPLocationSource.js +0 -96
  86. package/src.old/sensors/SensorsCompatibility.js +0 -486
  87. package/src.old/sensors/SensorsCompatibility.spec.js +0 -270
  88. package/src.old/sensors/SensorsLogger.js +0 -94
  89. package/src.old/sensors/SensorsLoggerUtils.js +0 -35
  90. /package/{src.old → src/providers}/attitude/EkfAttitude.js +0 -0
  91. /package/{src.old → src/providers}/attitude/EkfAttitude.spec.js +0 -0
  92. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/HeadingUnlocker.js +0 -0
  93. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/HeadingUnlocker.spec.js +0 -0
  94. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/Smoother.spec.js +0 -0
  95. /package/{src.old/providers/pdr → src/providers/pose/pdr/helpers}/ThugDetector.js +0 -0
  96. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetection.js +0 -0
  97. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionLadetto.js +0 -0
  98. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionMinMaxPeaks.js +0 -0
  99. /package/{src.old/providers → src/providers/pose/pdr}/steps/StepDetectionMinMaxPeaks2.js +0 -0
@@ -0,0 +1,76 @@
1
+ import React from 'react';
2
+ import isEmpty from 'lodash.isempty';
3
+ import PropTypes from 'prop-types';
4
+
5
+ import EventType from '../events/EventType';
6
+ import Utils from './Utils';
7
+ import PositioningHandler from '../PositioningHandler';
8
+ import StartStopComponent from './StartStopComponent';
9
+
10
+ class PositioningInclinationComponent extends React.Component {
11
+
12
+ static propTypes = { positioningHandler: PropTypes.instanceOf(PositioningHandler).isRequired };
13
+
14
+ constructor(props, context) {
15
+ super(props, context);
16
+ this.state = {
17
+ inclination: null,
18
+ errored: false
19
+ };
20
+ }
21
+
22
+
23
+ start() {
24
+ this.id = this.props.positioningHandler.start(
25
+ [EventType.Inclination],
26
+ this.onEvents,
27
+ this.onErrors
28
+ );
29
+ }
30
+
31
+
32
+ stop() {
33
+ this.props.positioningHandler.stop(this.id);
34
+ this.setState({
35
+ inclination: null,
36
+ errored: false
37
+ });
38
+ }
39
+
40
+ onEvents = (events) => {
41
+ const newState = {};
42
+ events.forEach(event => {
43
+ if (event.dataType === EventType.Inclination) {
44
+ newState.inclination = event.data;
45
+ }
46
+ });
47
+ if (!isEmpty(newState)) {
48
+ this.setState(newState);
49
+ }
50
+ };
51
+
52
+ onErrors = events => {
53
+ const newState = { errored: true };
54
+ events.forEach(event => {
55
+ if (event.dataType === EventType.Inclination) {
56
+ newState.inclination = event.error;
57
+ }
58
+ });
59
+ this.setState(newState);
60
+ }
61
+
62
+ render() {
63
+ return (
64
+ <div>
65
+ <StartStopComponent
66
+ onStart={() => this.start()}
67
+ onStop={() => this.stop()}
68
+ errored={this.state.errored} />
69
+
70
+ <p>{Utils.renderInclination(this.state.inclination)}</p>
71
+ </div>
72
+ );
73
+ }
74
+ }
75
+
76
+ export default PositioningInclinationComponent;
@@ -0,0 +1,120 @@
1
+ import React from 'react';
2
+ import isEmpty from 'lodash.isempty';
3
+ import PropTypes from 'prop-types';
4
+
5
+ import EventType from '../events/EventType';
6
+ import Utils from './Utils';
7
+ import PositioningHandler from '../PositioningHandler';
8
+ import StartStopComponent from './StartStopComponent';
9
+ import {
10
+ WGS84UserPosition, Itinerary
11
+ } from '@wemap/geo';
12
+ import MapComponent from './MapComponent';
13
+
14
+ const INITIAL_LOCATION = new WGS84UserPosition(43.6091955, 3.8841255);
15
+ const INITIAL_HEADING = 191.9;
16
+ const ITINERARY = Itinerary.fromPoints([
17
+ [INITIAL_LOCATION.lat, INITIAL_LOCATION.lng],
18
+ [43.6091883, 3.8841242],
19
+ [43.6091709, 3.8842382],
20
+ [43.6091288, 3.884226],
21
+ [43.6091461, 3.884112]
22
+ ], false);
23
+
24
+ class PositioningPoseComponent extends React.Component {
25
+
26
+ static propTypes = { positioningHandler: PropTypes.instanceOf(PositioningHandler).isRequired };
27
+
28
+ constructor(props, context) {
29
+ super(props, context);
30
+ this.state = {
31
+ position: null,
32
+ attitude: null,
33
+ errored: false
34
+ };
35
+ }
36
+
37
+
38
+ start() {
39
+ this.id = this.props.positioningHandler.start(
40
+ [EventType.AbsolutePosition, EventType.AbsoluteAttitude],
41
+ this.onEvents,
42
+ this.onErrors,
43
+ {
44
+ waitInputPosition: true,
45
+ useMapMatching: true
46
+ }
47
+ );
48
+
49
+ setTimeout(() => {
50
+ this.props.positioningHandler.setPosition(this.id, INITIAL_LOCATION);
51
+ this.props.positioningHandler.setHeading(this.id, INITIAL_HEADING);
52
+ this.props.positioningHandler.setItinerary(this.id, ITINERARY);
53
+ }, 3000);
54
+ }
55
+
56
+
57
+ stop() {
58
+ this.props.positioningHandler.stop(this.id);
59
+ this.setState({
60
+ position: null,
61
+ attitude: null,
62
+ errored: false
63
+ });
64
+ }
65
+
66
+ onEvents = (events) => {
67
+ const newState = {};
68
+ events.forEach(event => {
69
+ if (event.dataType === EventType.AbsolutePosition) {
70
+ newState.position = event.data;
71
+ } else if (event.dataType === EventType.AbsoluteAttitude) {
72
+ newState.attitude = event.data;
73
+ }
74
+ });
75
+ if (!isEmpty(newState)) {
76
+ this.setState(newState);
77
+ }
78
+
79
+ if (this.map) {
80
+ this.map.parseEvents(events);
81
+ }
82
+ };
83
+
84
+ onErrors = events => {
85
+ const newState = { errored: true };
86
+ events.forEach(event => {
87
+ if (event.dataType === EventType.AbsolutePosition) {
88
+ newState.position = event.error;
89
+ } else if (event.dataType === EventType.AbsoluteAttitude) {
90
+ newState.attitude = event.error;
91
+ }
92
+ });
93
+ this.setState(newState);
94
+ }
95
+
96
+ render() {
97
+ const attitudeRender = Utils.renderAttitude(this.state.attitude);
98
+ const positionRender = Utils.renderPosition(this.state.position);
99
+
100
+ return (
101
+ <div>
102
+ <StartStopComponent
103
+ onStart={() => this.start()}
104
+ onStop={() => this.stop()}
105
+ errored={this.state.errored} />
106
+
107
+ <h3>Position</h3>
108
+ {positionRender}
109
+ <h3>Attitude</h3>
110
+ {attitudeRender}
111
+ <h3>Map</h3>
112
+ <MapComponent
113
+ ref={map => (this.map = map)}
114
+ network={ITINERARY} />
115
+ </div>
116
+ );
117
+ }
118
+ }
119
+
120
+ export default PositioningPoseComponent;
@@ -0,0 +1,82 @@
1
+ import React from 'react';
2
+
3
+ import RelativeAttitudeProvider from '../providers/attitude/RelativeAttitudeProvider';
4
+ import Utils from './Utils';
5
+ import EventType from '../events/EventType';
6
+
7
+ class RelativeAttitudeComponent extends React.Component {
8
+
9
+ constructor(props, context) {
10
+ super(props, context);
11
+
12
+ this.state = {
13
+ attitude: null,
14
+ deviceorientation: null
15
+ };
16
+
17
+ this.relativeAttitudeProvider = new RelativeAttitudeProvider(this.onEvent, this.onError);
18
+ }
19
+
20
+ componentDidMount() {
21
+ this.relativeAttitudeProvider.start();
22
+ window.addEventListener('deviceorientation', this.onDeviceOrientationEventListener, true);
23
+ }
24
+
25
+ componentWillUnmount() {
26
+ this.relativeAttitudeProvider.stop();
27
+ window.removeEventListener('deviceorientation', this.onDeviceOrientationEventListener, true);
28
+ }
29
+
30
+ onEvent = events => {
31
+ events.forEach(event => {
32
+ if (event.dataType === EventType.RelativeAttitude) {
33
+ this.setState({ attitude: event.data });
34
+ }
35
+ });
36
+ };
37
+
38
+ onError = events => {
39
+ events.forEach(event => {
40
+ if (event.dataType === EventType.RelativeAttitude) {
41
+ this.setState({ attitude: event.error });
42
+ }
43
+ });
44
+ }
45
+
46
+ onDeviceOrientationEventListener = (e) => this.setState({ deviceorientation: e });
47
+
48
+ setOffset(offset) {
49
+ this.relativeAttitudeProvider.setOffset(offset);
50
+ }
51
+
52
+ render() {
53
+
54
+ let rawRender = <span>Not available</span>;
55
+
56
+ if (this.state.deviceorientation) {
57
+ const alpha = this.state.deviceorientation.alpha;
58
+ const beta = this.state.deviceorientation.beta;
59
+ const gamma = this.state.deviceorientation.gamma;
60
+
61
+ if (alpha && beta && gamma) {
62
+ rawRender = <p>alpha: {alpha.toFixed(2)}, <br />
63
+ beta: {beta.toFixed(2)}, <br />
64
+ gamma: {gamma.toFixed(2)}</p>;
65
+ }
66
+ }
67
+
68
+ const browserRender = Utils.renderAttitude(this.state.attitude);
69
+
70
+ return (
71
+ <div>
72
+ <h3>Raw:</h3>
73
+ {rawRender}
74
+ <h3>From browser:</h3>
75
+ {browserRender}
76
+ </div>
77
+ );
78
+ }
79
+ }
80
+
81
+ export default RelativeAttitudeComponent;
82
+
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ class StartStopComponent extends React.Component {
5
+
6
+ static propTypes = {
7
+ onStart: PropTypes.func.isRequired,
8
+ onStop: PropTypes.func.isRequired,
9
+ errored: PropTypes.bool.isRequired
10
+ };
11
+
12
+ constructor(props, context) {
13
+ super(props, context);
14
+ this.state = { started: false };
15
+ }
16
+
17
+ start() {
18
+ this.setState({started: true});
19
+ this.props.onStart();
20
+ }
21
+
22
+ componentWillUnmount() {
23
+ stop();
24
+ }
25
+
26
+ stop() {
27
+ this.setState({started: false});
28
+ this.props.onStop();
29
+ }
30
+
31
+
32
+ render() {
33
+ return (
34
+ <div>
35
+ <button onClick={() => this.start()}
36
+ disabled={(this.state.started && !this.props.errored)}>
37
+ Start
38
+ </button>
39
+ <button onClick={() => this.stop()}
40
+ disabled={!(this.state.started && !this.props.errored)}>
41
+ Stop
42
+ </button>
43
+ </div>
44
+
45
+ );
46
+ }
47
+
48
+ }
49
+
50
+ export default StartStopComponent;
@@ -0,0 +1,92 @@
1
+ import React from 'react'; // eslint-disable-line no-unused-vars
2
+ import { rad2deg } from '@wemap/maths';
3
+
4
+ const NOT_AVAILABLE_STR = 'Not available';
5
+
6
+ class Utils {
7
+
8
+ static renderAttitude(attitude) {
9
+
10
+ if (!attitude) {
11
+ return <p>Waiting</p>;
12
+ }
13
+
14
+ if (attitude instanceof Error) {
15
+ return Utils.renderError(attitude);
16
+ }
17
+
18
+ const quaternion = attitude.quaternion;
19
+
20
+ const w = quaternion[0].toFixed(3);
21
+ const x = quaternion[1].toFixed(3);
22
+ const y = quaternion[2].toFixed(3);
23
+ const z = quaternion[3].toFixed(3);
24
+
25
+ const euler = attitude.eulerAnglesDegrees;
26
+ const yaw = euler[0].toFixed(2);
27
+ const pitch = euler[1].toFixed(2);
28
+ const roll = euler[2].toFixed(2);
29
+ const heading = attitude.headingDegrees.toFixed(2);
30
+
31
+ return <p>Quaternion: [{w}, {x}, {y}, {z}]<br />
32
+ Eulers: [{yaw}, {pitch}, {roll}]<br />
33
+ Heading: {heading}</p>;
34
+ }
35
+
36
+ static renderPosition(position) {
37
+
38
+ if (!position) {
39
+ return <p>Waiting</p>;
40
+ }
41
+ if (position instanceof Error) {
42
+ return Utils.renderError(position);
43
+ }
44
+ return (
45
+ <p>
46
+ Latitude: {position.lat.toFixed(7)}<br />
47
+ Longitude: {position.lng.toFixed(7)}<br />
48
+ Altitude: {position.alt ? position.alt.toFixed(2) : NOT_AVAILABLE_STR}<br />
49
+ Bearing: {position.bearing ? position.bearing.toFixed(2) : NOT_AVAILABLE_STR}<br />
50
+ Accuracy: {position.accuracy ? position.accuracy.toFixed(2) : NOT_AVAILABLE_STR}<br />
51
+ Time: {position.time ? position.time.toFixed(2) : NOT_AVAILABLE_STR}<br />
52
+ Provider: {position.provider ? position.provider : NOT_AVAILABLE_STR}
53
+ </p>
54
+ );
55
+
56
+ }
57
+
58
+ static renderRelativePosition(position) {
59
+
60
+ if (!position) {
61
+ return <p>Waiting</p>;
62
+ }
63
+ if (position instanceof Error) {
64
+ return Utils.renderError(position);
65
+ }
66
+ return (
67
+ <p>
68
+ x: {position[0].toFixed(2)}<br />
69
+ y: {position[1].toFixed(2)}<br />
70
+ z: {position[2].toFixed(2)}
71
+ </p>
72
+ );
73
+
74
+ }
75
+
76
+ static renderInclination(inclination) {
77
+ if (inclination === null) {
78
+ return 'Waiting';
79
+ }
80
+ if (inclination instanceof Error) {
81
+ return Utils.renderError(inclination);
82
+ }
83
+ return rad2deg(inclination).toFixed(2);
84
+ }
85
+
86
+ static renderError(error) {
87
+ return (<span><strong>[{error.constructor.name}]</strong> {error.message}</span>);
88
+ }
89
+
90
+ }
91
+
92
+ export default Utils;
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+
4
+ import AbsoluteAttitudeComponent from './AbsoluteAttitudeComponent';
5
+ import ArCoreComponent from './ArCoreComponent';
6
+ import GnssWifiComponent from './GnssWifiComponent';
7
+ import GnssWifiPdrComponent from './GnssWifiPdrComponent';
8
+ import ImuComponent from './ImuComponent';
9
+ import InclinationComponent from './InclinationComponent';
10
+ import PdrComponent from './PdrComponent';
11
+ import PoseComponent from './PoseComponent';
12
+ import PositioningComponent from './PositioningComponent';
13
+ import RelativeAttitudeComponent from './RelativeAttitudeComponent';
14
+
15
+ const createReactElement = (component, container) => ReactDOM.render(
16
+ React.createElement(component, {}, null),
17
+ container
18
+ );
19
+
20
+ export {
21
+ AbsoluteAttitudeComponent,
22
+ ArCoreComponent,
23
+ ImuComponent,
24
+ InclinationComponent,
25
+ GnssWifiComponent,
26
+ GnssWifiPdrComponent,
27
+ PdrComponent,
28
+ PoseComponent,
29
+ PositioningComponent,
30
+ RelativeAttitudeComponent,
31
+ createReactElement
32
+ };
@@ -0,0 +1,9 @@
1
+ const DEFAULT_MESSAGE = 'It seems that you ask for IMU events on a desktop browser';
2
+
3
+ class AskImuOnDesktopError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+ }
8
+
9
+ export default AskImuOnDesktopError;
@@ -0,0 +1,9 @@
1
+ const DEFAULT_MESSAGE = 'Geolocation api is missing';
2
+
3
+ class GeolocationApiMissingError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+ }
8
+
9
+ export default GeolocationApiMissingError;
@@ -0,0 +1,9 @@
1
+ const DEFAULT_MESSAGE = 'Geolocation permission denied';
2
+
3
+ class GeolocationPermissionDeniedError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+ }
8
+
9
+ export default GeolocationPermissionDeniedError;
@@ -0,0 +1,9 @@
1
+ const DEFAULT_MESSAGE = 'Geolocation position unavailable';
2
+
3
+ class GeolocationPositionUnavailableError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+ }
8
+
9
+ export default GeolocationPositionUnavailableError;
@@ -0,0 +1,9 @@
1
+ const DEFAULT_MESSAGE = 'IP Resolver failed';
2
+
3
+ class IpResolveServerError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+ }
8
+
9
+ export default IpResolveServerError;
@@ -0,0 +1,11 @@
1
+ const DEFAULT_MESSAGE = 'Impossible to retrieve Acceleration data';
2
+
3
+ import MissingSensorError from './MissingSensorError';
4
+
5
+ class MissingAccelerometerError extends MissingSensorError {
6
+ constructor(message) {
7
+ super(message || DEFAULT_MESSAGE);
8
+ }
9
+ }
10
+
11
+ export default MissingAccelerometerError;
@@ -0,0 +1,9 @@
1
+ const DEFAULT_MESSAGE = 'ARCore is missing';
2
+
3
+ class MissingArCoreError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+ }
8
+
9
+ export default MissingArCoreError;
@@ -0,0 +1,11 @@
1
+ const DEFAULT_MESSAGE = 'Impossible to retrieve Angular Rate data';
2
+
3
+ import MissingSensorError from './MissingSensorError';
4
+
5
+ class MissingGyroscopeError extends MissingSensorError {
6
+ constructor(message) {
7
+ super(message || DEFAULT_MESSAGE);
8
+ }
9
+ }
10
+
11
+ export default MissingGyroscopeError;
@@ -0,0 +1,9 @@
1
+ import MissingSensorError from './MissingSensorError';
2
+
3
+ class MissingMagnetometerError extends MissingSensorError {
4
+ constructor(message) {
5
+ super(message);
6
+ }
7
+ }
8
+
9
+ export default MissingMagnetometerError;
@@ -0,0 +1,9 @@
1
+ const DEFAULT_MESSAGE = 'Native interface is missing';
2
+
3
+ class MissingNativeInterfaceError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+ }
8
+
9
+ export default MissingNativeInterfaceError;
@@ -0,0 +1,14 @@
1
+ const DEFAULT_MESSAGE = 'Impossible to retrieve events, a sensor is missing';
2
+
3
+ class MissingSensorError extends Error {
4
+ constructor(message) {
5
+ super(message || DEFAULT_MESSAGE);
6
+ }
7
+
8
+ from(fromMessage) {
9
+ this.message += ' from ' + fromMessage;
10
+ return this;
11
+ }
12
+ }
13
+
14
+ export default MissingSensorError;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Event data types handled by {@link ProviderEvent}
3
+ */
4
+ export default {
5
+ Unknown: 'UNKNOWN',
6
+ MagneticField: 'MAGNETIC_FIELD',
7
+ AngularRate: 'ANGULAR_RATE',
8
+ Acceleration: 'ACCELERATION',
9
+ Inclination: 'INCLINATION',
10
+ RelativeAttitude: 'RELATIVE_ATTITUDE',
11
+ AbsoluteAttitude: 'ABSOLUTE_ATTITUDE',
12
+ RelativePosition: 'RELATIVE_POSITION',
13
+ AbsolutePosition: 'ABSOLUTE_POSITION',
14
+ Pressure: 'PRESSURE',
15
+ BluetoothSignals: 'BLUETOOTH_SIGNALS',
16
+ WifiSignals: 'WIFI_SIGNALS',
17
+ ScanId: 'SCAN_ID',
18
+ Itinerary: 'ITINERARY',
19
+ Network: 'NETWORK'
20
+ };
@@ -0,0 +1,52 @@
1
+ import EventType from './EventType';
2
+ import ProviderEvent from './ProviderEvent';
3
+
4
+ /**
5
+ * A provider error is an error event which is triggered by device sensors
6
+ * in case of problem
7
+ */
8
+ class ProviderError extends ProviderEvent {
9
+
10
+ error = null;
11
+
12
+ /**
13
+ * Create a Provider Error with the minimum information
14
+ * @param {String} providerName the provider name
15
+ * @param {EventType} dataType the type of event
16
+ * @param {Error} error the event error
17
+ */
18
+ constructor(providerName, dataType, error) {
19
+ super(providerName, dataType, null);
20
+ this.error = error;
21
+ }
22
+
23
+ clone() {
24
+ const evt = new ProviderError(this.providerName, this.dataType, this.error);
25
+ evt.timestamp = this.timestamp;
26
+ evt.isFromNative = this.isFromNative;
27
+ return evt;
28
+ }
29
+
30
+ /**
31
+ * Remove the same error in array
32
+ * @param {ProviderError[]} errorsArray
33
+ */
34
+ static removeArrayDuplicates(errorsArray) {
35
+ return errorsArray.reduce((acc, current) => {
36
+ const found = acc.find(item => typeof item.error === typeof current.error && item.dataType === current.dataType);
37
+ return !found ? acc.concat([current]) : acc;
38
+ }, []);
39
+ }
40
+
41
+ static modifyArrayDataType(errorsArray, newDataType) {
42
+ const output = [];
43
+ errorsArray.forEach(error => {
44
+ const newError = error.clone();
45
+ newError.dataType = newDataType;
46
+ output.push(newError);
47
+ });
48
+ return ProviderError.removeArrayDuplicates(output);
49
+ }
50
+ }
51
+
52
+ export default ProviderError;
@@ -0,0 +1,35 @@
1
+ import EventType from './EventType';
2
+
3
+ /**
4
+ * A provider event is an event which can be triggered by device sensors
5
+ * or can be computed from raw providers.
6
+ */
7
+ class ProviderEvent {
8
+
9
+ timestamp = -1;
10
+ dataType = EventType.Unknown;
11
+ providerName = '';
12
+ isFromNative = false;
13
+ data = null;
14
+
15
+ /**
16
+ * Create a Provider Event with the minimum information
17
+ * @param {String} providerName the provider name
18
+ * @param {EventType} dataType the type of event
19
+ * @param {Object} data the event data
20
+ */
21
+ constructor(providerName, dataType, data) {
22
+ this.providerName = providerName;
23
+ this.dataType = dataType;
24
+ this.data = data;
25
+ }
26
+
27
+ clone() {
28
+ const evt = new ProviderEvent(this.providerName, this.dataType, this.data);
29
+ evt.timestamp = this.timestamp;
30
+ evt.isFromNative = this.isFromNative;
31
+ return evt;
32
+ }
33
+ }
34
+
35
+ export default ProviderEvent;