use window.mixpanel, remove eventEmitter

pull/512/head
Ryan Tharp 6 years ago
parent c921d3e3b3
commit 51eaa90823

@ -230,8 +230,7 @@
window.feeds = []; window.feeds = [];
window.lokiMessageAPI = new window.LokiMessageAPI(ourKey); window.lokiMessageAPI = new window.LokiMessageAPI(ourKey);
window.lokiPublicChatAPI = new window.LokiPublicChatAPI(ourKey); window.lokiPublicChatAPI = new window.LokiPublicChatAPI(ourKey);
// set up mixpanel // are there limits on tracking, is this unneeded?
window.mixpanel = window.mixpanel || new window.LokiMixpanelAPI(); // incase account manager already set it up
// window.mixpanel.track("Desktop boot"); // window.mixpanel.track("Desktop boot");
window.lokiP2pAPI = new window.LokiP2pAPI(ourKey); window.lokiP2pAPI = new window.LokiP2pAPI(ourKey);
window.lokiP2pAPI.on('pingContact', pubKey => { window.lokiP2pAPI.on('pingContact', pubKey => {

@ -4,9 +4,6 @@
const _ = require('lodash'); const _ = require('lodash');
const { rpc } = require('./loki_rpc'); const { rpc } = require('./loki_rpc');
const LokiMixpanelAPI = require('./loki_mixpanel.js');
const Mixpanel = new LokiMixpanelAPI();
const DEFAULT_CONNECTIONS = 3; const DEFAULT_CONNECTIONS = 3;
const MAX_ACCEPTABLE_FAILURES = 1; const MAX_ACCEPTABLE_FAILURES = 1;
@ -181,7 +178,7 @@ class LokiMessageAPI {
try { try {
// eslint-disable-next-line more/no-then // eslint-disable-next-line more/no-then
success = await firstTrue(promises); success = await firstTrue(promises);
Mixpanel.track('Sent Message Using Swarm API'); window.mixpanel.track('Sent Message Using Swarm API');
} catch (e) { } catch (e) {
if (e instanceof textsecure.WrongDifficultyError) { if (e instanceof textsecure.WrongDifficultyError) {
// Force nonce recalculation // Force nonce recalculation
@ -195,7 +192,7 @@ class LokiMessageAPI {
throw e; throw e;
} }
if (!success) { if (!success) {
Mixpanel.track('Failed to Send Message Using Swarm API'); window.mixpanel.track('Failed to Send Message Using Swarm API');
throw new window.textsecure.EmptySwarmError( throw new window.textsecure.EmptySwarmError(
pubKey, pubKey,
'Ran out of swarm nodes to query' 'Ran out of swarm nodes to query'
@ -260,7 +257,7 @@ class LokiMessageAPI {
} catch (e) { } catch (e) {
log.warn('Loki send message:', e); log.warn('Loki send message:', e);
if (e instanceof textsecure.WrongSwarmError) { if (e instanceof textsecure.WrongSwarmError) {
Mixpanel.track('Migrated Snode'); window.mixpanel.track('Migrated Snode');
const { newSwarm } = e; const { newSwarm } = e;
await lokiSnodeAPI.updateSwarmNodes(params.pubKey, newSwarm); await lokiSnodeAPI.updateSwarmNodes(params.pubKey, newSwarm);
this.sendingData[params.timestamp].swarm = newSwarm; this.sendingData[params.timestamp].swarm = newSwarm;

@ -1,12 +1,8 @@
/* eslint-disable class-methods-use-this */
const EventEmitter = require('events'); const EventEmitter = require('events');
const Mixpanel = require('mixpanel'); const Mixpanel = require('mixpanel');
// require('setimmediate');
class LokiMixpanelAPI extends EventEmitter { class LokiMixpanelAPI {
constructor() { constructor() {
super();
this.mixpanel = Mixpanel.init('736cd9a854a157591153efacd1164e9a'); this.mixpanel = Mixpanel.init('736cd9a854a157591153efacd1164e9a');
} }
track(label) { track(label) {

@ -3,9 +3,6 @@ clearTimeout, MessageController */
const EventEmitter = require('events'); const EventEmitter = require('events');
const nodeFetch = require('node-fetch'); const nodeFetch = require('node-fetch');
const { URL, URLSearchParams } = require('url'); const { URL, URLSearchParams } = require('url');
const LokiMixpanelAPI = require('./loki_mixpanel.js');
const Mixpanel = new LokiMixpanelAPI();
// Can't be less than 1200 if we have unauth'd requests // Can't be less than 1200 if we have unauth'd requests
const PUBLICCHAT_MSG_POLL_EVERY = 1.5 * 1000; // 1.5s const PUBLICCHAT_MSG_POLL_EVERY = 1.5 * 1000; // 1.5s
@ -666,12 +663,12 @@ class LokiPublicChannelAPI {
objBody: payload, objBody: payload,
}); });
if (!res.err && res.response) { if (!res.err && res.response) {
Mixpanel.track('Public Message Sent'); window.mixpanel.track('Public Message Sent');
return res.response.data.id; return res.response.data.id;
} }
// there's no retry on desktop // there's no retry on desktop
// this is supposed to be after retries // this is supposed to be after retries
Mixpanel.track('Failed to Send Public Message'); window.mixpanel.track('Failed to Send Public Message');
return false; return false;
} }
} }

@ -6,9 +6,6 @@ const dns = require('dns');
const process = require('process'); const process = require('process');
const { rpc } = require('./loki_rpc'); const { rpc } = require('./loki_rpc');
const natUpnp = require('nat-upnp'); const natUpnp = require('nat-upnp');
const LokiMixpanelAPI = require('./loki_mixpanel.js');
const Mixpanel = new LokiMixpanelAPI();
const resolve4 = url => const resolve4 = url =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
@ -121,7 +118,7 @@ class LokiSnodeAPI {
port: snode.storage_port, port: snode.storage_port,
})); }));
} catch (e) { } catch (e) {
Mixpanel.track('Seed Node Failed'); window.mixpanel.track('Seed Node Failed');
if (seedNodes.length === 0) { if (seedNodes.length === 0) {
throw new window.textsecure.SeedNodeError( throw new window.textsecure.SeedNodeError(
'Failed to contact seed node' 'Failed to contact seed node'
@ -137,7 +134,7 @@ class LokiSnodeAPI {
const filteredNodes = swarmNodes.filter( const filteredNodes = swarmNodes.filter(
node => node.address !== nodeUrl && node.ip !== nodeUrl node => node.address !== nodeUrl && node.ip !== nodeUrl
); );
Mixpanel.track('Unreachable Snode'); window.mixpanel.track('Unreachable Snode');
await conversation.updateSwarmNodes(filteredNodes); await conversation.updateSwarmNodes(filteredNodes);
} }

Loading…
Cancel
Save