@wemap/positioning 2.3.0 → 2.3.1
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/package.json +1 -1
- package/src/PositioningHandler.js +36 -19
- package/src/PositioningHandler.spec.js +218 -0
- package/src/index.js +2 -1
- package/src/providers/ProviderOptions.js +7 -1
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@ import ProviderOptions from './providers/ProviderOptions';
|
|
|
6
6
|
import InclinationProvider from './providers/others/InclinationProvider';
|
|
7
7
|
import Logger from '@wemap/logger';
|
|
8
8
|
import ArCoreAbsoluteProvider from './providers/pose/ArCoreAbsoluteProvider';
|
|
9
|
+
import ArCoreProvider from './providers/pose/ArCoreProvider';
|
|
10
|
+
import GnssWifiProvider from './providers/position/GnssWifiProvider';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* @private
|
|
@@ -32,9 +34,9 @@ class PositioningHandler {
|
|
|
32
34
|
*/
|
|
33
35
|
start(eventsType, onEvent, onError, options) {
|
|
34
36
|
|
|
35
|
-
this.options = Object.assign(ProviderOptions, options);
|
|
37
|
+
this.options = Object.assign({}, ProviderOptions, options);
|
|
36
38
|
|
|
37
|
-
const providerClass =
|
|
39
|
+
const providerClass = PositioningHandler.findProvider(eventsType, this.options);
|
|
38
40
|
|
|
39
41
|
if (!providerClass) {
|
|
40
42
|
throw new Error('No provider found');
|
|
@@ -50,36 +52,51 @@ class PositioningHandler {
|
|
|
50
52
|
/**
|
|
51
53
|
* @private
|
|
52
54
|
*/
|
|
53
|
-
findProvider(eventsType,
|
|
55
|
+
static findProvider(eventsType, _options) {
|
|
56
|
+
|
|
57
|
+
const options = Object.assign({}, ProviderOptions, _options);
|
|
58
|
+
const canUse = (provider, others = []) => {
|
|
59
|
+
return !options.ignoreProviders.includes(provider)
|
|
60
|
+
&& !others.some(elem => options.ignoreProviders.includes(elem))
|
|
61
|
+
&& provider.checkAvailabilityErrors().length === 0;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (eventsType.length === 1
|
|
65
|
+
&& eventsType.includes(EventType.Inclination)
|
|
66
|
+
&& InclinationProvider.checkAvailabilityErrors().length === 0) {
|
|
67
|
+
return InclinationProvider;
|
|
68
|
+
}
|
|
54
69
|
|
|
55
70
|
const wantPoseProvider = [EventType.AbsolutePosition, EventType.AbsoluteAttitude]
|
|
56
|
-
.every(elem => eventsType.includes(elem));
|
|
71
|
+
.every(elem => eventsType.includes(elem)) && eventsType.length === 2;
|
|
57
72
|
|
|
58
73
|
if (wantPoseProvider) {
|
|
59
74
|
|
|
60
|
-
const arCoreAvailable = ArCoreAbsoluteProvider.checkAvailabilityErrors().length === 0;
|
|
61
|
-
|
|
62
|
-
if ((options.ignoreProviders.includes(PdrProvider)
|
|
63
|
-
&& options.ignoreProviders.includes(ArCoreAbsoluteProvider))
|
|
64
|
-
|| (!options.ignoreProviders.includes(ArCoreAbsoluteProvider)
|
|
65
|
-
&& !arCoreAvailable)) {
|
|
66
|
-
return PoseProvider;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
75
|
if (options.waitInputPosition) {
|
|
70
|
-
if (
|
|
76
|
+
if (canUse(ArCoreAbsoluteProvider, [ArCoreProvider])) {
|
|
71
77
|
return ArCoreAbsoluteProvider;
|
|
72
78
|
}
|
|
73
|
-
if (
|
|
79
|
+
if (canUse(PdrProvider)) {
|
|
74
80
|
return PdrProvider;
|
|
75
81
|
}
|
|
82
|
+
return null;
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
if (canUse(GnssWifiPdrProvider, [PdrProvider])) {
|
|
86
|
+
return GnssWifiPdrProvider;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (canUse(PoseProvider)) {
|
|
91
|
+
return PoseProvider;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (options.optionalEvents.includes(EventType.AbsoluteAttitude)
|
|
95
|
+
&& canUse(GnssWifiProvider)) {
|
|
96
|
+
return GnssWifiProvider;
|
|
97
|
+
}
|
|
82
98
|
}
|
|
99
|
+
|
|
83
100
|
return null;
|
|
84
101
|
}
|
|
85
102
|
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
import 'jsdom-global/register';
|
|
3
|
+
|
|
4
|
+
import PositioningHandler from './PositioningHandler';
|
|
5
|
+
import EventType from './events/EventType';
|
|
6
|
+
import InclinationProvider from './providers/others/InclinationProvider';
|
|
7
|
+
import GnssWifiPdrProvider from './providers/pose/GnssWifiPdrProvider';
|
|
8
|
+
import PoseProvider from './providers/pose/PoseProvider';
|
|
9
|
+
import PdrProvider from './providers/pose/pdr/PdrProvider';
|
|
10
|
+
import ArCoreAbsoluteProvider from './providers/pose/ArCoreAbsoluteProvider';
|
|
11
|
+
import GnssWifiProvider from './providers/position/GnssWifiProvider';
|
|
12
|
+
import ArCoreProvider from './providers/pose/ArCoreProvider';
|
|
13
|
+
|
|
14
|
+
const expect = chai.expect;
|
|
15
|
+
|
|
16
|
+
function fakeUserAgent(userAgent) {
|
|
17
|
+
navigator.__defineGetter__('userAgent', () => userAgent);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function fakeNativeInterface(arcore = true) {
|
|
21
|
+
// We have to clear the cache here
|
|
22
|
+
ArCoreProvider._nativeProvider = null;
|
|
23
|
+
|
|
24
|
+
global.WemapProvidersAndroid = {getArCoreProvider: () => {
|
|
25
|
+
return { checkAvailability: () => arcore };
|
|
26
|
+
}};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function fakeGeolocation() {
|
|
30
|
+
navigator.__defineGetter__('geolocation', () => {
|
|
31
|
+
return {watchPosition: () => {}};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function config(userAgent, nativeInterface = false, arcore = false) {
|
|
36
|
+
if (userAgent) {
|
|
37
|
+
fakeUserAgent(userAgent);
|
|
38
|
+
}
|
|
39
|
+
if (nativeInterface) {
|
|
40
|
+
fakeNativeInterface(arcore);
|
|
41
|
+
} else {
|
|
42
|
+
delete global.WemapProvidersAndroid;
|
|
43
|
+
}
|
|
44
|
+
fakeGeolocation();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const CHROME_ANDROID_USER_AGENT = 'Mozilla/5.0 (Linux; Android 9; SM-G960F Build/PPR1.180610.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.157 Mobile Safari/537.36';
|
|
48
|
+
|
|
49
|
+
const CHROME_DESKTOP_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36';
|
|
50
|
+
|
|
51
|
+
describe('PositioningHandler#findProvider', () => {
|
|
52
|
+
|
|
53
|
+
it('Inclination Desktop', () => {
|
|
54
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
55
|
+
const provider = PositioningHandler.findProvider([EventType.Inclination]);
|
|
56
|
+
expect(provider).to.be.null;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('Inclination Mobile', () => {
|
|
60
|
+
config(CHROME_ANDROID_USER_AGENT);
|
|
61
|
+
const provider = PositioningHandler.findProvider([EventType.Inclination]);
|
|
62
|
+
expect(provider).to.be.equals(InclinationProvider);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('Pose Desktop', () => {
|
|
66
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
67
|
+
const provider = PositioningHandler.findProvider([EventType.AbsolutePosition, EventType.AbsoluteAttitude]);
|
|
68
|
+
expect(provider).to.be.null;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('Pose without PDR Desktop', () => {
|
|
72
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
73
|
+
const provider = PositioningHandler.findProvider(
|
|
74
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
75
|
+
{ ignoreProviders: [PdrProvider] }
|
|
76
|
+
);
|
|
77
|
+
expect(provider).to.be.null;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('Pose without ArCore Desktop', () => {
|
|
81
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
82
|
+
const provider = PositioningHandler.findProvider(
|
|
83
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
84
|
+
{ ignoreProviders: [ArCoreProvider] }
|
|
85
|
+
);
|
|
86
|
+
expect(provider).to.be.null;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('Pose with optional attitude Desktop', () => {
|
|
90
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
91
|
+
const provider = PositioningHandler.findProvider([EventType.AbsolutePosition, EventType.AbsoluteAttitude]);
|
|
92
|
+
expect(provider).to.be.null;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('Pose with optional attitude without PDR Desktop', () => {
|
|
96
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
97
|
+
const provider = PositioningHandler.findProvider(
|
|
98
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
99
|
+
{
|
|
100
|
+
ignoreProviders: [PdrProvider],
|
|
101
|
+
optionalEvents: [EventType.AbsoluteAttitude]
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
expect(provider).to.be.equals(GnssWifiProvider);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('Pose with optional attitude without ArCore Desktop', () => {
|
|
108
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
109
|
+
const provider = PositioningHandler.findProvider(
|
|
110
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
111
|
+
{
|
|
112
|
+
ignoreProviders: [ArCoreProvider],
|
|
113
|
+
optionalEvents: [EventType.AbsoluteAttitude]
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
expect(provider).to.be.equals(GnssWifiProvider);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('Pose with optional attitude without PDR and ArCore Desktop', () => {
|
|
120
|
+
config(CHROME_DESKTOP_USER_AGENT);
|
|
121
|
+
const provider = PositioningHandler.findProvider(
|
|
122
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
123
|
+
{
|
|
124
|
+
ignoreProviders: [PdrProvider, ArCoreProvider],
|
|
125
|
+
optionalEvents: [EventType.AbsoluteAttitude]
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
expect(provider).to.be.equals(GnssWifiProvider);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('Pose Mobile Web', () => {
|
|
132
|
+
config(CHROME_ANDROID_USER_AGENT);
|
|
133
|
+
const provider = PositioningHandler.findProvider([EventType.AbsolutePosition, EventType.AbsoluteAttitude]);
|
|
134
|
+
expect(provider).to.be.equals(GnssWifiPdrProvider);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('Pose without PDR Mobile Web', () => {
|
|
138
|
+
config(CHROME_ANDROID_USER_AGENT);
|
|
139
|
+
const provider = PositioningHandler.findProvider(
|
|
140
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
141
|
+
{ ignoreProviders: [PdrProvider] }
|
|
142
|
+
);
|
|
143
|
+
expect(provider).to.be.equals(PoseProvider);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('Pose without ArCore Mobile Web', () => {
|
|
147
|
+
config(CHROME_ANDROID_USER_AGENT);
|
|
148
|
+
const provider = PositioningHandler.findProvider(
|
|
149
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
150
|
+
{ ignoreProviders: [ArCoreProvider] }
|
|
151
|
+
);
|
|
152
|
+
expect(provider).to.be.equals(GnssWifiPdrProvider);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('Pose without PDR and ArCore Mobile Web', () => {
|
|
156
|
+
config(CHROME_ANDROID_USER_AGENT);
|
|
157
|
+
const provider = PositioningHandler.findProvider(
|
|
158
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
159
|
+
{ ignoreProviders: [PdrProvider, ArCoreProvider] }
|
|
160
|
+
);
|
|
161
|
+
expect(provider).to.be.equals(PoseProvider);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('Pose with waitInputPosition Mobile Web', () => {
|
|
165
|
+
config(CHROME_ANDROID_USER_AGENT);
|
|
166
|
+
const provider = PositioningHandler.findProvider(
|
|
167
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
168
|
+
{ waitInputPosition: true }
|
|
169
|
+
);
|
|
170
|
+
expect(provider).to.be.equals(PdrProvider);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('Pose with waitInputPosition Mobile Native with ArCore', () => {
|
|
174
|
+
config(CHROME_ANDROID_USER_AGENT, true, true);
|
|
175
|
+
const provider = PositioningHandler.findProvider(
|
|
176
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
177
|
+
{ waitInputPosition: true }
|
|
178
|
+
);
|
|
179
|
+
expect(provider).to.be.equals(ArCoreAbsoluteProvider);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('Pose with waitInputPosition Mobile Native without ArCore', () => {
|
|
183
|
+
config(CHROME_ANDROID_USER_AGENT, true, false);
|
|
184
|
+
const provider = PositioningHandler.findProvider(
|
|
185
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
186
|
+
{
|
|
187
|
+
waitInputPosition: true,
|
|
188
|
+
ignoreProviders: [ArCoreProvider]
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
expect(provider).to.be.equals(PdrProvider);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('Pose with waitInputPosition without PDR Mobile Web', () => {
|
|
195
|
+
config(CHROME_ANDROID_USER_AGENT, false);
|
|
196
|
+
const provider = PositioningHandler.findProvider(
|
|
197
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
198
|
+
{
|
|
199
|
+
waitInputPosition: true,
|
|
200
|
+
ignoreProviders: [PdrProvider]
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
expect(provider).to.be.null;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('Pose with waitInputPosition without ArCore Mobile Native', () => {
|
|
207
|
+
config(CHROME_ANDROID_USER_AGENT, true, true);
|
|
208
|
+
const provider = PositioningHandler.findProvider(
|
|
209
|
+
[EventType.AbsolutePosition, EventType.AbsoluteAttitude],
|
|
210
|
+
{
|
|
211
|
+
waitInputPosition: true,
|
|
212
|
+
ignoreProviders: [ArCoreProvider]
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
expect(provider).to.be.equals(PdrProvider);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
});
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import InclinationProvider from './providers/computed/InclinationProvider';
|
|
2
2
|
import PositioningHandler from './PositioningHandler';
|
|
3
|
+
import EventType from './events/EventType';
|
|
3
4
|
|
|
4
5
|
export {
|
|
5
|
-
InclinationProvider, PositioningHandler
|
|
6
|
+
InclinationProvider, PositioningHandler, EventType
|
|
6
7
|
};
|
|
@@ -22,7 +22,13 @@ const ProviderOptions = {
|
|
|
22
22
|
* Providers listed here will not be used by PositioningHandler
|
|
23
23
|
* List of {@link Provider}
|
|
24
24
|
*/
|
|
25
|
-
ignoreProviders: []
|
|
25
|
+
ignoreProviders: [],
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Define the list of EventType that are optionals
|
|
29
|
+
* List of {@link EventType}
|
|
30
|
+
*/
|
|
31
|
+
optionalEvents: []
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
export default ProviderOptions;
|