Replace recsys beacon with regular network call (#1090)

Ticket: 1080
Reason: unreliable; often blocked.
Additional: add auth-token, per suggestion in FYP PR.
This commit is contained in:
infinite-persistence 2022-03-14 07:27:09 -07:00 committed by GitHub
parent 69a9245324
commit 63f19b278d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,9 @@ import { selectUser } from 'redux/selectors/user';
import { makeSelectRecommendedRecsysIdForClaimId } from 'redux/selectors/search';
import { v4 as Uuidv4 } from 'uuid';
import { parseURI } from 'util/lbryURI';
import { getAuthToken } from 'util/saved-passwords';
import * as SETTINGS from 'constants/settings';
import { X_LBRY_AUTH_TOKEN } from 'constants/token';
import { makeSelectClaimForUri } from 'redux/selectors/claims';
import { selectPlayingUri, selectPrimaryUri } from 'redux/selectors/content';
import { selectClientSetting, selectDaemonSettings } from 'redux/selectors/settings';
@ -136,14 +138,21 @@ const recsys = {
if (recsys.entries[claimId] && shareTelemetry) {
const data = JSON.stringify(recsys.entries[claimId]);
try {
navigator.sendBeacon(recsysEndpoint, data);
if (!isTentative) {
delete recsys.entries[claimId];
}
} catch (error) {
console.log('no beacon for you', error);
}
return fetch(recsysEndpoint, {
method: 'POST',
headers: {
[X_LBRY_AUTH_TOKEN]: getAuthToken(),
'Content-Type': 'application/json',
},
body: data,
}).catch((err) => {
console.log('RECSYS: failed to send entry', err);
});
}
recsys.log('sendRecsysEntry', claimId);
},