Skip to content

Commit

Permalink
Use a UUID for session ID (rather than a random float)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrauninger committed Oct 9, 2018
1 parent 662e258 commit f426ec4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
20 changes: 8 additions & 12 deletions src/store/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ import { ActionType } from 'typesafe-actions';
import { TelemetryActionType } from './InternalTypes';
import * as telemetryActions from './TelemetryActions';

// const TelemetryEndpoint = 'http://localhost:3001/';
const TelemetryEndpoint = 'https://gpvz3vnswb.execute-api.us-west-2.amazonaws.com/Stage/SaveSurveyResult';
const TelemetryEndpoint = 'http://localhost:3001/';
// const TelemetryEndpoint = 'https://gpvz3vnswb.execute-api.us-west-2.amazonaws.com/Stage/SaveSurveyResult';

// Courtesy of 'broofa's answer in https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
/*function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}*/

function uniqueId(): string {
// TODO: This is almost certainly not a good way to generate IDs.
return Math.random().toString();
function uuidv4() {
return (`${1e7}${-1e3}${-4e3}${-8e3}${-1e11}`).replace(/[018]/g, c => {
const i = parseInt(c, undefined);
return (i ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> i / 4).toString(16)
});
}

export class TelemetrySession {
private sessionId: string;

constructor() {
this.sessionId = uniqueId();
this.sessionId = uuidv4();
}

public recordStart() {
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"named-imports-order": "any"
}
],
"object-literal-sort-keys": false
"object-literal-sort-keys": false,
"no-bitwise": false
}
}

0 comments on commit f426ec4

Please sign in to comment.