-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add IP change listener to getVerifiedLocationToken() #193
base: master
Are you sure you want to change the base?
Changes from all commits
54af232
59c8040
743fc94
2433b44
bb2d127
e39b30b
77b940a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,27 @@ let lastToken: RadarTrackVerifiedResponse | null = null; | |
let lastTokenNow: number = 0; | ||
let expectedCountryCode: string | null = null; | ||
let expectedStateCode: string | null = null; | ||
let lastIp: string | null = null; | ||
|
||
class VerifyAPI { | ||
static async checkIpChanges() { | ||
const { ip }: any = await Http.request({ | ||
method: 'GET', | ||
path: 'ping', | ||
}); | ||
|
||
const ipChanged = ip !== lastIp; | ||
if (ipChanged) { | ||
Logger.info(`IP changed from ${lastIp} to ${ip}`); | ||
|
||
lastToken = null; | ||
} | ||
|
||
lastIp = ip; | ||
|
||
return ipChanged; | ||
} | ||
|
||
static async trackVerified(params: RadarTrackVerifiedParams, encrypted: Boolean = false) { | ||
const options = Config.get(); | ||
|
||
|
@@ -104,6 +123,11 @@ class VerifyAPI { | |
} | ||
} | ||
|
||
if (params.ipChanges && trackRes?.user?.ip) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also picks up IP changes in trackVerified() responses |
||
lastIp = trackRes?.user?.ip; | ||
Logger.info(`Setting ip to ${lastIp}`); | ||
} | ||
|
||
lastToken = trackRes; | ||
lastTokenNow = performance.now(); | ||
|
||
|
@@ -115,15 +139,19 @@ class VerifyAPI { | |
} | ||
|
||
static async startTrackingVerified(params: RadarStartTrackingVerifiedParams) { | ||
let { interval } = params; | ||
if (!interval) { | ||
interval = 60; | ||
Logger.info(`interval not provided, using 60 seconds`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adds default interval of 60 seconds, avoids bug if interval undefined |
||
} | ||
|
||
const doTrackVerified = async () => { | ||
let trackRes; | ||
try { | ||
trackRes = await this.trackVerified(params); | ||
} catch (err: any) { | ||
Logger.error(`trackVerified error: ${err.message}`); | ||
} | ||
|
||
const { interval } = params; | ||
|
||
let expiresIn = 0; | ||
let minInterval = interval; | ||
|
@@ -164,6 +192,10 @@ class VerifyAPI { | |
static async getVerifiedLocationToken(params: RadarTrackVerifiedParams) { | ||
const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000; | ||
|
||
if (params.ipChanges) { | ||
await this.checkIpChanges(); | ||
} | ||
|
||
if (lastToken && lastToken.passed) { | ||
if (lastTokenElapsed < (lastToken.expiresIn || 0)) { | ||
return lastToken; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ class RadarMap extends maplibregl.Map { | |
radarMapOptions, | ||
{ style }, | ||
); | ||
Logger.debug('map initailized with options', mapOptions); | ||
Logger.debug('map initialized with options', mapOptions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo |
||
|
||
(mapOptions as maplibregl.MapOptions).transformRequest = (url, resourceType) => { | ||
// this handles when a style is switched | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default '4.4.8'; | ||
export default '4.4.10-beta.1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove old ping call