@wemap/positioning 2.0.0 → 2.1.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.
- package/.eslintrc.json +4 -2
- package/debug/absolute-attitude.html +16 -0
- package/debug/gnss-wifi-pdr.html +16 -0
- package/debug/gnss-wifi.html +16 -0
- package/debug/imu.html +16 -0
- package/debug/inclination.html +16 -0
- package/debug/pdr.html +16 -0
- package/debug/pose.html +16 -0
- package/debug/positioning.html +16 -0
- package/debug/relative-attitude.html +16 -0
- package/package.json +6 -4
- package/src/PositioningHandler.js +96 -34
- package/src/components/AbsoluteAttitudeComponent.jsx +104 -0
- package/src/components/GnssWifiComponent.jsx +46 -0
- package/src/components/GnssWifiPdrComponent.jsx +85 -0
- package/src/components/ImuComponent.jsx +100 -0
- package/src/components/InclinationComponent.jsx +53 -0
- package/src/components/PdrComponent.jsx +88 -0
- package/src/components/PoseComponent.jsx +74 -0
- package/src/components/PositioningComponent.jsx +26 -0
- package/src/components/PositioningInclinationComponent.jsx +76 -0
- package/src/components/PositioningPoseComponent.jsx +111 -0
- package/src/components/RelativeAttitudeComponent.jsx +82 -0
- package/src/components/StartStopComponent.jsx +50 -0
- package/src/components/Utils.js +74 -0
- package/src/components/index.js +30 -0
- package/src/errors/AskImuOnDesktopError.js +9 -0
- package/src/errors/GeolocationApiMissingError.js +9 -0
- package/src/errors/GeolocationPermissionDeniedError.js +9 -0
- package/src/errors/GeolocationPositionUnavailableError.js +9 -0
- package/src/errors/IpResolveServerError.js +9 -0
- package/src/errors/MissingAccelerometerError.js +11 -0
- package/src/errors/MissingGyroscopeError.js +11 -0
- package/src/errors/MissingMagnetometerError.js +9 -0
- package/src/errors/MissingSensorError.js +14 -0
- package/src/events/EventType.js +20 -0
- package/src/events/ProviderError.js +52 -0
- package/src/events/ProviderEvent.js +35 -0
- package/src/index.js +2 -2
- package/src/providers/Constants.js +5 -0
- package/src/providers/FakeAbsolutePositionProvider.js +56 -0
- package/src/providers/Provider.js +218 -0
- package/src/providers/ProviderOptions.js +28 -0
- package/src/providers/ProvidersLogger.js +77 -0
- package/src/providers/attitude/AbsoluteAttitudeProvider.js +207 -0
- package/src/providers/attitude/EkfAttitude.js +238 -0
- package/src/providers/attitude/EkfAttitude.spec.js +116 -0
- package/src/providers/attitude/RelativeAttitudeProvider.js +129 -0
- package/src/providers/others/ImuProvider.js +186 -0
- package/src/providers/others/InclinationProvider.js +107 -0
- package/src/providers/others/MapMatchingProvider.js +147 -0
- package/src/providers/pose/GnssWifiPdrProvider.js +233 -0
- package/src/providers/pose/PoseProvider.js +90 -0
- package/src/providers/pose/pdr/PdrProvider.js +352 -0
- package/src/providers/pose/pdr/helpers/HeadingUnlocker.js +41 -0
- package/src/providers/pose/pdr/helpers/HeadingUnlocker.spec.js +26 -0
- package/src/providers/pose/pdr/helpers/Smoother.js +90 -0
- package/src/providers/pose/pdr/helpers/Smoother.spec.js +424 -0
- package/src/providers/pose/pdr/helpers/ThugDetector.js +37 -0
- package/src/providers/pose/pdr/steps/StepDetection.js +7 -0
- package/src/providers/pose/pdr/steps/StepDetectionLadetto.js +67 -0
- package/src/providers/pose/pdr/steps/StepDetectionMinMaxPeaks.js +80 -0
- package/src/providers/pose/pdr/steps/StepDetectionMinMaxPeaks2.js +108 -0
- package/src/providers/position/GnssWifiProvider.js +129 -0
- package/src/providers/position/IpProvider.js +75 -0
- package/src.old/providers/GnssPdrLocationSource.js +1 -1
- package/webpack/webpack.dev.js +1 -1
- package/debug/index.html +0 -15
- package/debug/index.old.html +0 -37
- package/scripts/release-github.js +0 -216
- package/src/providers/FakeLocationSource.js +0 -36
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
// in seconds
|
|
3
|
+
const WINDOW_TIME = 0.3;
|
|
4
|
+
|
|
5
|
+
// in seconds
|
|
6
|
+
const MIN_TIME_BETWEEN_STEPS = 0.4;
|
|
7
|
+
|
|
8
|
+
// in Hz
|
|
9
|
+
const MAX_FRENQUENCY = 4;
|
|
10
|
+
const MIN_FRENQUENCY = 1;
|
|
11
|
+
|
|
12
|
+
// in m.s-2
|
|
13
|
+
const VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD = 1.5;
|
|
14
|
+
const VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD = -1;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class StepDetectionMinMaxPeaks {
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
this.slidingWindow = [];
|
|
21
|
+
|
|
22
|
+
this.lastStepTimestamp = -MIN_TIME_BETWEEN_STEPS;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
compute(timestamp, linearAcc) {
|
|
27
|
+
|
|
28
|
+
if (this.lastStepTimestamp && this.lastStepTimestamp + MIN_TIME_BETWEEN_STEPS > timestamp) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let maxValue = Number.MIN_SAFE_INTEGER;
|
|
33
|
+
let minValue = Number.MAX_SAFE_INTEGER;
|
|
34
|
+
|
|
35
|
+
const windowTime = WINDOW_TIME;
|
|
36
|
+
this.slidingWindow.forEach(function(item, index, object) {
|
|
37
|
+
if (item.timestamp < timestamp - windowTime) {
|
|
38
|
+
object.splice(index, 1);
|
|
39
|
+
} else {
|
|
40
|
+
maxValue = Math.max(item.verticalAcc, maxValue);
|
|
41
|
+
minValue = Math.min(item.verticalAcc, minValue);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this.slidingWindow.push({
|
|
45
|
+
timestamp: timestamp,
|
|
46
|
+
verticalAcc: linearAcc[2]
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (maxValue > VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD
|
|
51
|
+
&& minValue < VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD) {
|
|
52
|
+
|
|
53
|
+
const timeInterval = this.lastStepTimestamp ? timestamp - this.lastStepTimestamp : 1;
|
|
54
|
+
this.frequency = Math.min(Math.max((1 / timeInterval), MIN_FRENQUENCY), MAX_FRENQUENCY);
|
|
55
|
+
|
|
56
|
+
this.lastStepTimestamp = timestamp;
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get lastStepSize() {
|
|
64
|
+
|
|
65
|
+
if (!this.frequency) {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const kParamA = 0.45;
|
|
70
|
+
const kParamB = 0.2;
|
|
71
|
+
return kParamA + kParamB * this.frequency;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get speed() {
|
|
75
|
+
return this.lastStepTimestamp ? this.lastStepSize * this.frequency : 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default StepDetectionMinMaxPeaks;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
|
|
2
|
+
// in seconds
|
|
3
|
+
const WINDOW_TIME = 0.3;
|
|
4
|
+
|
|
5
|
+
// in seconds
|
|
6
|
+
const MIN_TIME_BETWEEN_STEPS = 0.4;
|
|
7
|
+
|
|
8
|
+
// in Hz
|
|
9
|
+
const MAX_FRENQUENCY = 4;
|
|
10
|
+
const MIN_FRENQUENCY = 1;
|
|
11
|
+
|
|
12
|
+
// in m.s-2
|
|
13
|
+
const VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD = 0.75;
|
|
14
|
+
const VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD = -0.3;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class StepDetectionMinMaxPeaks2 {
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
this.slidingWindow = [];
|
|
21
|
+
|
|
22
|
+
this.lastStepTimestamp = -MIN_TIME_BETWEEN_STEPS;
|
|
23
|
+
this.previousVerticalAcc = 0;
|
|
24
|
+
this.influence = 0.2;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
compute(timestamp, linearAcc, angularRate) {
|
|
29
|
+
|
|
30
|
+
const verticalAcc = this.influence * (linearAcc[2] * 2) + (1 - this.influence) * this.previousVerticalAcc;
|
|
31
|
+
this.previousVerticalAcc = verticalAcc;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if (Math.sqrt(angularRate[0] ** 2 + angularRate[1] ** 2 + angularRate[2] ** 2) > 0.75) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (this.lastStepTimestamp && this.lastStepTimestamp + MIN_TIME_BETWEEN_STEPS > timestamp) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let maxValue = Number.MIN_SAFE_INTEGER;
|
|
43
|
+
let minValue = Number.MAX_SAFE_INTEGER;
|
|
44
|
+
|
|
45
|
+
this.slidingWindow.forEach(function(item, index, object) {
|
|
46
|
+
if (item.timestamp < timestamp - WINDOW_TIME) {
|
|
47
|
+
object.splice(index, 1);
|
|
48
|
+
} else {
|
|
49
|
+
maxValue = Math.max(item.verticalAcc, maxValue);
|
|
50
|
+
minValue = Math.min(item.verticalAcc, minValue);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.slidingWindow.push({
|
|
54
|
+
timestamp: timestamp,
|
|
55
|
+
verticalAcc: verticalAcc
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (maxValue > VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD
|
|
60
|
+
&& minValue < VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD) {
|
|
61
|
+
|
|
62
|
+
const timeInterval = this.lastStepTimestamp ? timestamp - this.lastStepTimestamp : 1;
|
|
63
|
+
this.frequency = Math.min(Math.max((1 / timeInterval), MIN_FRENQUENCY), MAX_FRENQUENCY);
|
|
64
|
+
|
|
65
|
+
this.lastStepTimestamp = timestamp;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get lastStepSize() {
|
|
73
|
+
|
|
74
|
+
if (!this.frequency) {
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const kParamA = 0.45;
|
|
79
|
+
const kParamB = 0.2;
|
|
80
|
+
return kParamA + kParamB * this.frequency;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get speed() {
|
|
84
|
+
return this.lastStepSize && this.frequency ? this.lastStepSize * this.frequency : 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
mean(data) {
|
|
88
|
+
let sum = 0.0, mean = 0.0;
|
|
89
|
+
|
|
90
|
+
for (let i = 0; i < data.length; ++i) {
|
|
91
|
+
sum += data[i].verticalAcc;
|
|
92
|
+
}
|
|
93
|
+
mean = sum / data.length;
|
|
94
|
+
return mean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
stddev(data) {
|
|
98
|
+
const theMean = this.mean(data);
|
|
99
|
+
let standardDeviation = 0;
|
|
100
|
+
for (let i = 0; i < data.length; ++i) {
|
|
101
|
+
standardDeviation += (data[i].verticalAcc - theMean) ** 2;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return Math.sqrt(standardDeviation / data.length);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export default StepDetectionMinMaxPeaks2;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { deg2rad } from '@wemap/maths';
|
|
2
|
+
import { WGS84UserPosition } from '@wemap/geo';
|
|
3
|
+
import { DateUtils } from '@wemap/utils';
|
|
4
|
+
|
|
5
|
+
import EventType from '../../events/EventType';
|
|
6
|
+
import GeolocationApiMissingError from '../../errors/GeolocationApiMissingError';
|
|
7
|
+
import Provider from '../Provider';
|
|
8
|
+
import GeolocationPermissionDeniedError from '../../errors/GeolocationPermissionDeniedError';
|
|
9
|
+
import GeolocationPositionUnavailableError from '../../errors/GeolocationPositionUnavailableError';
|
|
10
|
+
|
|
11
|
+
const POSITION_OPTIONS = {
|
|
12
|
+
enableHighAccuracy: true,
|
|
13
|
+
timeout: Infinity,
|
|
14
|
+
maximumAge: 0
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* GnssWifiProvider is a provider based on navigator.geolocation.
|
|
19
|
+
* This API does not allow us to know if the position returned is provided
|
|
20
|
+
* by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
|
|
21
|
+
* "GnssWifi".
|
|
22
|
+
*/
|
|
23
|
+
class GnssWifiProvider extends Provider {
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @override
|
|
27
|
+
*/
|
|
28
|
+
static get displayName() {
|
|
29
|
+
return 'GNSS / Wifi from Browser';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @override
|
|
34
|
+
*/
|
|
35
|
+
static get eventsType() {
|
|
36
|
+
return [EventType.AbsolutePosition];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @override
|
|
41
|
+
*/
|
|
42
|
+
static checkAvailabilityErrors() {
|
|
43
|
+
|
|
44
|
+
if (navigator && navigator.geolocation) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return [
|
|
49
|
+
GnssWifiProvider.createError(
|
|
50
|
+
EventType.AbsolutePosition,
|
|
51
|
+
new GeolocationApiMissingError()
|
|
52
|
+
)
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @override
|
|
58
|
+
*/
|
|
59
|
+
startInternal() {
|
|
60
|
+
|
|
61
|
+
this.geoLocationId = navigator.geolocation.watchPosition(
|
|
62
|
+
this.onNewPosition,
|
|
63
|
+
this.onPositionError,
|
|
64
|
+
POSITION_OPTIONS
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @override
|
|
71
|
+
*/
|
|
72
|
+
stopInternal() {
|
|
73
|
+
|
|
74
|
+
navigator.geolocation.clearWatch(this.geoLocationId);
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
onNewPosition = position => {
|
|
82
|
+
const { coords } = position;
|
|
83
|
+
if (!coords) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let bearing;
|
|
88
|
+
if (coords.heading) {
|
|
89
|
+
bearing = deg2rad(coords.heading);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const timestamp = DateUtils.unixTimestampToPerformanceNow(position.timestamp) / 1e3;
|
|
93
|
+
|
|
94
|
+
const location = new WGS84UserPosition(
|
|
95
|
+
coords.latitude,
|
|
96
|
+
coords.longitude,
|
|
97
|
+
coords.altitude,
|
|
98
|
+
timestamp,
|
|
99
|
+
coords.accuracy,
|
|
100
|
+
bearing,
|
|
101
|
+
GnssWifiProvider.name);
|
|
102
|
+
|
|
103
|
+
this.notify(this.createEvent(
|
|
104
|
+
EventType.AbsolutePosition, location, timestamp
|
|
105
|
+
));
|
|
106
|
+
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
onPositionError = error => {
|
|
110
|
+
|
|
111
|
+
let customError;
|
|
112
|
+
switch (error.code) {
|
|
113
|
+
case 1:
|
|
114
|
+
customError = new GeolocationPermissionDeniedError(error.message);
|
|
115
|
+
break;
|
|
116
|
+
case 2:
|
|
117
|
+
customError = new GeolocationPositionUnavailableError(error.message);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (customError) {
|
|
121
|
+
this.notifyError(this.createError(
|
|
122
|
+
EventType.AbsolutePosition,
|
|
123
|
+
customError
|
|
124
|
+
));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export default GnssWifiProvider;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { WGS84UserPosition } from '@wemap/geo';
|
|
2
|
+
|
|
3
|
+
import EventType from '../../events/EventType';
|
|
4
|
+
import Provider from '../Provider';
|
|
5
|
+
import IpResolveServerError from '../../errors/IpResolveServerError';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* GnssWifiProvider is a provider based on navigator.geolocation.
|
|
9
|
+
* This API does not allow us to know if the position returned is provided
|
|
10
|
+
* by Wifi Fingerprinting algorithms or by GNSS. That is why the name is
|
|
11
|
+
* "GnssWifi".
|
|
12
|
+
*/
|
|
13
|
+
class GnssWifiProvider extends Provider {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @override
|
|
17
|
+
*/
|
|
18
|
+
static get displayName() {
|
|
19
|
+
return 'IP from ipinfo.io';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @override
|
|
24
|
+
*/
|
|
25
|
+
static get eventsType() {
|
|
26
|
+
return [EventType.AbsolutePosition];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @override
|
|
31
|
+
*/
|
|
32
|
+
static checkAvailabilityErrors() {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @override
|
|
38
|
+
*/
|
|
39
|
+
startInternal() {
|
|
40
|
+
|
|
41
|
+
fetch('https://ipinfo.io/geo?token=24a7ca2f3b489d')
|
|
42
|
+
.then((response) => {
|
|
43
|
+
if (!response) {
|
|
44
|
+
this.notifyError(this.createError(
|
|
45
|
+
EventType.AbsolutePosition,
|
|
46
|
+
new IpResolveServerError()
|
|
47
|
+
));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const timestamp = performance.now() / 1e3;
|
|
52
|
+
|
|
53
|
+
const position = new WGS84UserPosition(
|
|
54
|
+
parseFloat(response.loc.split(',')[0]),
|
|
55
|
+
parseFloat(response.loc.split(',')[1]),
|
|
56
|
+
null,
|
|
57
|
+
timestamp
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
this.notify(this.createEvent(
|
|
61
|
+
EventType.AbsolutePosition, position, timestamp
|
|
62
|
+
));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @override
|
|
68
|
+
*/
|
|
69
|
+
stopInternal() {
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default GnssWifiProvider;
|
|
@@ -132,7 +132,7 @@ class GnssPdrLocationSource extends LocationSource {
|
|
|
132
132
|
* MapMatching
|
|
133
133
|
*/
|
|
134
134
|
|
|
135
|
-
enableMapMatching(network
|
|
135
|
+
enableMapMatching(network, maxDistance = MM_GNSS_DIST, maxAngleBearing = MM_GNSS_ANGLE) {
|
|
136
136
|
this.pdrLocationSource.enableMapMatching(network, maxDistance, maxAngleBearing);
|
|
137
137
|
super.enableMapMatching(network, maxDistance, maxAngleBearing);
|
|
138
138
|
}
|
package/webpack/webpack.dev.js
CHANGED
|
@@ -7,7 +7,7 @@ const debugFolder = path.join(__dirname, '../debug');
|
|
|
7
7
|
|
|
8
8
|
module.exports = merge(common, {
|
|
9
9
|
mode: 'development',
|
|
10
|
-
entry: { '
|
|
10
|
+
entry: { 'positioning-components': './src/components/index.js' },
|
|
11
11
|
output: {
|
|
12
12
|
publicPath: '/js/',
|
|
13
13
|
filename: '[name].js',
|
package/debug/index.html
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<title>Debug navigation</title>
|
|
7
|
-
<script src="/js/navigation-components.js"></script>
|
|
8
|
-
</head>
|
|
9
|
-
|
|
10
|
-
<body>
|
|
11
|
-
<div id="app"></div>
|
|
12
|
-
<script>createReactElement(NavigationDebugApp, document.getElementById('app'));</script>
|
|
13
|
-
</body>
|
|
14
|
-
|
|
15
|
-
</html>
|
package/debug/index.old.html
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
|
|
7
|
-
<title>Positioning</title>
|
|
8
|
-
|
|
9
|
-
<script src="/js/navigation.js"></script>
|
|
10
|
-
|
|
11
|
-
</head>
|
|
12
|
-
|
|
13
|
-
<body>
|
|
14
|
-
Hello world !
|
|
15
|
-
|
|
16
|
-
<script>
|
|
17
|
-
const navHandler = new NavigationHandler(pose => console.log(pose));
|
|
18
|
-
|
|
19
|
-
navHandler.startIfNecessary()
|
|
20
|
-
.then(() => {
|
|
21
|
-
console.log('Navigation started');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
setTimeout(() => {
|
|
25
|
-
navHandler.startIfNecessary();
|
|
26
|
-
}, 3000);
|
|
27
|
-
|
|
28
|
-
setTimeout(() => {
|
|
29
|
-
navHandler.stop()
|
|
30
|
-
.then(() => {
|
|
31
|
-
console.log('Navigation stopped');
|
|
32
|
-
});
|
|
33
|
-
}, 5000);
|
|
34
|
-
</script>
|
|
35
|
-
</body>
|
|
36
|
-
|
|
37
|
-
</html>
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
const dotenv = require('dotenv');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const git = require('simple-git/promise')('.').silent(true);
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const npm = require('npm');
|
|
6
|
-
const requestp = require('request-promise');
|
|
7
|
-
|
|
8
|
-
const config = require('../config.json');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Check GITHUB_TOKEN in .env file
|
|
12
|
-
*/
|
|
13
|
-
const result = dotenv.config();
|
|
14
|
-
if (result.error) {
|
|
15
|
-
console.error('.env does not exist. '
|
|
16
|
-
+ 'You have to create a .env file at the root directory');
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const ENV = result.parsed;
|
|
20
|
-
if (!ENV.GITHUB_TOKEN) {
|
|
21
|
-
console.error('GITHUB_TOKEN does not exist in .env file. '
|
|
22
|
-
+ 'More info here: https://github.com/settings/tokens');
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Github Url and Headers
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
const GITHUB_API_URL = 'https://api.github.com';
|
|
31
|
-
const GITHUB_UPLOAD_URL = 'https://uploads.github.com';
|
|
32
|
-
|
|
33
|
-
const HEADERS = {
|
|
34
|
-
'Authorization': 'token ' + ENV.GITHUB_TOKEN,
|
|
35
|
-
'User-Agent': 'NodeJS/Release-' + config.githubRepoName
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
function checkGithubToken() {
|
|
39
|
-
|
|
40
|
-
const uri = GITHUB_API_URL;
|
|
41
|
-
const headers = HEADERS;
|
|
42
|
-
|
|
43
|
-
return requestp({
|
|
44
|
-
method: 'GET',
|
|
45
|
-
uri,
|
|
46
|
-
headers,
|
|
47
|
-
json: true
|
|
48
|
-
}).catch(e => {
|
|
49
|
-
return Promise.reject(e.message);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function createRelease(version) {
|
|
54
|
-
|
|
55
|
-
const uri = GITHUB_API_URL + '/repos/' + config.githubRepoOwner + '/'
|
|
56
|
-
+ config.githubRepoName + '/releases';
|
|
57
|
-
const headers = Object.assign({ 'Content-Type': 'application/json' }, HEADERS);
|
|
58
|
-
const inputData = {
|
|
59
|
-
'tag_name': version,
|
|
60
|
-
'target_commitish': 'master',
|
|
61
|
-
'name': version
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return requestp({
|
|
65
|
-
method: 'POST',
|
|
66
|
-
uri,
|
|
67
|
-
headers,
|
|
68
|
-
body: inputData,
|
|
69
|
-
json: true
|
|
70
|
-
}).catch(e => {
|
|
71
|
-
return Promise.reject(e.message);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
function uploadFile(releaseId, fileName, filePath) {
|
|
77
|
-
|
|
78
|
-
const stats = fs.statSync(filePath);
|
|
79
|
-
const fileSizeInBytes = stats.size;
|
|
80
|
-
|
|
81
|
-
const uri = GITHUB_UPLOAD_URL + '/repos/' + config.githubRepoOwner + '/'
|
|
82
|
-
+ config.githubRepoName + '/releases/' + releaseId
|
|
83
|
-
+ '/assets?name=' + fileName;
|
|
84
|
-
|
|
85
|
-
const headers = Object.assign({
|
|
86
|
-
'Content-Type': 'application/javascript',
|
|
87
|
-
'Content-length': fileSizeInBytes
|
|
88
|
-
}, HEADERS);
|
|
89
|
-
|
|
90
|
-
return requestp({
|
|
91
|
-
method: 'POST',
|
|
92
|
-
uri,
|
|
93
|
-
headers,
|
|
94
|
-
body: fs.createReadStream(filePath)
|
|
95
|
-
}).catch(e => {
|
|
96
|
-
return e.message;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function revertNpmVersion() {
|
|
101
|
-
return git.reset(['--hard', 'HEAD^1'])
|
|
102
|
-
.then(() => git.tag(['-d', 'v1.1.0']))
|
|
103
|
-
.catch(err => console.error(err));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const npmLoaderPromise = new Promise((resolve, reject) => {
|
|
107
|
-
npm.load(err => {
|
|
108
|
-
if (err) {
|
|
109
|
-
reject(err);
|
|
110
|
-
} else {
|
|
111
|
-
resolve();
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
function main() {
|
|
118
|
-
|
|
119
|
-
const versionsList = ['minor', 'major', 'patch'];
|
|
120
|
-
|
|
121
|
-
let isVersionCreated = false;
|
|
122
|
-
const isPushed = false;
|
|
123
|
-
|
|
124
|
-
Promise.resolve()
|
|
125
|
-
// Check github token as soon as possible to avoid to revert a push
|
|
126
|
-
.then(checkGithubToken)
|
|
127
|
-
|
|
128
|
-
// Check if current branch name corresponds to "releaseBranch"
|
|
129
|
-
.then(async () => {
|
|
130
|
-
const res = await git.raw(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
131
|
-
if (res.trim() !== config.releaseBranch) {
|
|
132
|
-
return Promise.reject('You are not on the ' + config.releaseBranch + ' branch');
|
|
133
|
-
}
|
|
134
|
-
return Promise.resolve();
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
// Check if git repo is clean before running npm version
|
|
138
|
-
.then(async () => {
|
|
139
|
-
const res = await git.raw(['status', '--porcelain']);
|
|
140
|
-
if (res) {
|
|
141
|
-
return Promise.reject('Your git working directory not clean');
|
|
142
|
-
}
|
|
143
|
-
return Promise.resolve();
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
// Update npm version with npm version argv[2]
|
|
147
|
-
.then(async () => {
|
|
148
|
-
const args = process.argv;
|
|
149
|
-
if (args.length < 3) {
|
|
150
|
-
throw new Error('version argument is missing');
|
|
151
|
-
}
|
|
152
|
-
if (!versionsList.includes(args[2])) {
|
|
153
|
-
throw new Error('version argument is unknown, it should be: ' + versionsList.join(','));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
await npmLoaderPromise;
|
|
157
|
-
return new Promise((resolve, reject) => {
|
|
158
|
-
npm.commands.version([args[2]], err => {
|
|
159
|
-
if (err) {
|
|
160
|
-
reject(err);
|
|
161
|
-
} else {
|
|
162
|
-
isVersionCreated = true;
|
|
163
|
-
resolve();
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
// Build the project in production mode
|
|
170
|
-
.then(async () => {
|
|
171
|
-
await npmLoaderPromise;
|
|
172
|
-
return new Promise((resolve, reject) => {
|
|
173
|
-
npm.commands.run(['build'], err => {
|
|
174
|
-
if (err) {
|
|
175
|
-
reject(err);
|
|
176
|
-
} else {
|
|
177
|
-
resolve();
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
// Push release to origin
|
|
184
|
-
.then(() => git.push('origin', config.releaseBranch, ['--tags']))
|
|
185
|
-
|
|
186
|
-
// Get tag name
|
|
187
|
-
.then(async () => {
|
|
188
|
-
const res = await git.raw(['describe']);
|
|
189
|
-
// TODO this condition can be improved
|
|
190
|
-
if (!res || res[0] !== 'v') {
|
|
191
|
-
return Promise.reject('Could not find tag name');
|
|
192
|
-
}
|
|
193
|
-
return Promise.resolve(res.trim());
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
// Create the release
|
|
197
|
-
.then((tagName) => createRelease(tagName))
|
|
198
|
-
|
|
199
|
-
// Upload file
|
|
200
|
-
.then(response => {
|
|
201
|
-
const filePath = path.join(config.distFolder, config.distFileName);
|
|
202
|
-
uploadFile(response.id, config.distFileName, filePath);
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
.then(() => {
|
|
206
|
-
console.log('Release finished with success');
|
|
207
|
-
})
|
|
208
|
-
.catch(e => {
|
|
209
|
-
if (isVersionCreated && !isPushed) {
|
|
210
|
-
revertNpmVersion();
|
|
211
|
-
}
|
|
212
|
-
console.error('error', e);
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
main();
|