Skip to content
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

10/14 Weekly merge into release #191

Merged
merged 13 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hifi-spatial-audio",
"version": "2.1.0",
"version": "2.1.1",
"description": "The High Fidelity Audio Client Library allows developers to integrate High Fidelity's spatial audio technology into their projects.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -57,6 +57,7 @@
"dependencies": {
"esm": "^3.2.25",
"pako": "^2.0.3",
"uuid": "^8.3.2",
"wrtc": "^0.4.7",
"ws": "^7.4.2"
},
Expand Down
4 changes: 2 additions & 2 deletions src/classes/HiFiMixerSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ export class HiFiMixerSession {
this._hifiDiagnostics.prime(this.mixerInfo.visit_id_hash);
this._copyAudioTracksFromRavi();
} else {
this._hifiDiagnostics.fire();
this._hifiDiagnostics.fire(state.toString());
}
}

Expand Down Expand Up @@ -1070,7 +1070,7 @@ export class HiFiMixerSession {
onRAVISessionStateChanged = (async function(event:any) : Promise<void> {
HiFiLogger.log(`New RAVI session state: \`${event.state}\``);
let message = undefined;
this._raviDiagnostics.fire();
this._raviDiagnostics.fire(event.state.toString());
switch (event.state) {
case RaviSessionStates.CONNECTED:
HiFiLogger.log(`RaviSession connected; waiting for results of audionet.init`);
Expand Down
26 changes: 20 additions & 6 deletions src/diagnostics/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HiFiMixerSession } from "../classes/HiFiMixerSession";
import { RaviSession, STATS_WATCHER_FILTER } from "../libravi/RaviSession";
import { apiVersion } from "../index";


const isBrowser = typeof window !== 'undefined';
const noop = (_:any):any => undefined;
Expand All @@ -17,6 +19,8 @@ if (!isBrowser) {
}
}

const MAX_DIAGNOSTICS_STORAGE_LENGTH = 5000;

const nonOperative = "non-operative";

STATS_WATCHER_FILTER.set('remote-inbound-rtp',
Expand Down Expand Up @@ -72,7 +76,7 @@ export class Diagnostics {
Object.assign(this, {url, label, session, ravi, fireOn});
this.checkPersisted();
this.reset();
this.fireListener = () => this.fire();
this.fireListener = (event:any) => this.fire(event.type);
this.onlineListener = () => this.checkPersisted();
}
/**
Expand All @@ -89,9 +93,9 @@ export class Diagnostics {
/**
* Call this when we get into a state that we want to know more about, e.g., when leaving the thing that caused us to prime().
*/
async fire() {
async fire(eventName:string) {
if (!this.isPrimed()) return;
const reportString = this.toString();
const reportString = this.toString(eventName);
this.reset();
// When we fire on closing tab or browser, we sometimes don't have enough time to report, or
// sometimes have enough time to report, but not enough to check the response.
Expand Down Expand Up @@ -137,7 +141,7 @@ export class Diagnostics {
/**
* Answer a single (long) log line to report.
*/
toString() {
toString(eventName:string) {
return `${new Date().toISOString()} ${this.identifier} ` +
this.s('logReason', 'sessionEND') +
this.connectionStats('browserStats') +
Expand All @@ -152,6 +156,8 @@ export class Diagnostics {
this.visibilityInfo() +
this.connectionInfo() +
this.s('PERSISTENCE', directSendLabel) +
this.s('VERSION', apiVersion) +
this.s('EVENT', eventName) +
(useDebugPrefixes ? '\n' : '') +
` [${xNavigator.userAgent}]`;
}
Expand Down Expand Up @@ -237,7 +243,8 @@ export class Diagnostics {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: reportString
}).then((response:Response) => response.ok);
}).then((response:Response) => response.ok)
.catch((err) => { console.log(`Could not send diagnostics report for ${this.label} to ${this.url}: ${err}`); return false; });
}
/**
* Add reportString to the set of data being saved for later reporting.
Expand All @@ -248,7 +255,14 @@ export class Diagnostics {
// there is a bug, or if the application site limits the connect-src (or default-src)
// in its Content-Security-Policy header without allowing this.url.
// If it is more than a line, we are accumulating stuff and really ought to phone home through the mixer when connected.
if (existing) existing += "\n";
if (existing) {
if (existing.length > MAX_DIAGNOSTICS_STORAGE_LENGTH) {
// If it is many lines, we may be in a web context where we cannot send diagnostics lines, and are better off discarding them to conserve web storage
console.log(`Diagnostics for ${this.label} truncated`);
existing = "";
}
existing += "\n";
}
// The reportString is generated as through it will be sent directly. Here we replace that label with a reason why we're persisting.
reportString = reportString.replace(directSendLabel, reason);
xStorage.setItem(this.label, existing + reportString);
Expand Down
18 changes: 5 additions & 13 deletions tests/testUtilities/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { default: SignedJWT } = require('jose/jwt/sign');
const { default: UnsecuredJWT } = require('jose/jwt/unsecured');
const crypto = require('crypto');
const { default: SignedJWT } = require('jose/jwt/sign'),
{ v4 } = require('uuid'),
{ default: UnsecuredJWT } = require('jose/jwt/unsecured'),
crypto = require('crypto');

export let tokenTypes: any = {};

Expand Down Expand Up @@ -111,16 +112,7 @@ export async function generateJWT(tokenType: { [property: string]: any }, spaceI
}

export function generateUUID() {
let i = 0;
let generatedUUID = "";
let baseString = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';

while (i++ < 38) {
let c = baseString[i - 1], r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
generatedUUID += (c == '-' || c == '4') ? c : v.toString(16)
}

return generatedUUID;
return v4();
}

export function sleep(ms: number) {
Expand Down