Skip to content

Commit

Permalink
Merge pull request #151 from bridie-hifi/2021-06-30-release
Browse files Browse the repository at this point in the history
Weekly-ish merge into Release branch
  • Loading branch information
hd23408 authored Jun 30, 2021
2 parents 8670151 + a3bedb5 commit 4c9df73
Show file tree
Hide file tree
Showing 12 changed files with 993 additions and 10,580 deletions.
9,522 changes: 539 additions & 8,983 deletions package-lock.json

Large diffs are not rendered by default.

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": "1.2.1",
"version": "1.3.0",
"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 @@ -37,6 +37,7 @@
"homepage": "https://highfidelity.com/",
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/pako": "^1.0.1",
"@types/puppeteer": "^5.4.3",
"aws-sdk": "^2.831.0",
"clean-webpack-plugin": "^3.0.0",
Expand Down
49 changes: 37 additions & 12 deletions src/classes/HiFiMixerSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { RaviUtils } from "../libravi/RaviUtils";
import { RaviSession, RaviSessionStates, WebRTCSessionParams, CustomSTUNandTURNConfig } from "../libravi/RaviSession";
import { RaviSignalingConnection, RaviSignalingStates } from "../libravi/RaviSignalingConnection";
import { HiFiAxisUtilities, ourHiFiAxisConfiguration } from "./HiFiAxisConfiguration";
const pako = require('pako');
import { Diagnostics } from "../diagnostics/diagnostics";
import pako from 'pako'

const INIT_TIMEOUT_MS = 5000;
const PERSONAL_VOLUME_ADJUST_TIMEOUT_MS = 5000;
Expand Down Expand Up @@ -135,8 +136,8 @@ export class HiFiMixerSession {
* Since the server doesn't always send the "Provided User ID" in these peer updates, we have to keep track of the (presumably stable) key in `jsonData.peers`
* associated with that "Provided User ID" in order to forward that "Provided User ID" to the Subscription handler and thus to the Library user.
*
* And since we are caching that one value, we are also caching the full state for all kwnon peers.
* This allows to optimize the received stream of changed data for a given peer from the server to just the necessary bits
* And since we are caching that one value, we are also caching the full state for all known peers.
* This allows us to optimize the received stream of changed data for a given peer from the server to just the necessary bits
* and reconstruct the complete information with the knowledge of the cached state of thata peer.
* One caveat, the position and orienationQuat fields cached for a peer are expressed in the 'MixerSpace', not transformed yet in the 'ClientUserSpace'.
*
Expand All @@ -155,6 +156,11 @@ export class HiFiMixerSession {

private onMuteChanged: OnMuteChangedCallback;

/**
* Only valid for users covered by a user data subscription. Remains constant at disconnect until the next connect.
*/
public concurrency:number = 0;

/**
* The WebRTC Stats Observer callback
*/
Expand Down Expand Up @@ -190,6 +196,9 @@ export class HiFiMixerSession {
*/
mixerInfo: any;

private _raviDiagnostics: Diagnostics;
private _hifiDiagnostics: Diagnostics;

/**
*
* @param __namedParameters
Expand Down Expand Up @@ -223,6 +232,11 @@ export class HiFiMixerSession {
this.onConnectionStateChanged = onConnectionStateChanged;

this._resetMixerInfo();
this._raviDiagnostics = new Diagnostics({label: 'ravi', session: this, ravi: this._raviSession});
this._hifiDiagnostics = new Diagnostics({label: 'app', session: this, ravi: this._raviSession,
// The first is the standard way to tell, but browser have bugs in which they don't fire.
// The second is enough for all known browser bugs, except for Safari desktop closing a visible tab.
fireOn: ['visibilitychange', 'pagehide', 'beforeunload']});
}

/**
Expand Down Expand Up @@ -252,7 +266,7 @@ export class HiFiMixerSession {
let initTimeout = setTimeout(async () => {
let errMsg = `Couldn't connect to mixer: Call to \`init\` timed out!`
try {
await this.disconnectFromHiFiMixer();
await this._disconnectFromHiFiMixer();
} catch (errorClosing) {
errMsg += `\nAdditionally, there was an error trying to close the failed connection. Error:\n${errorClosing}`;
}
Expand All @@ -272,6 +286,8 @@ export class HiFiMixerSession {
this.mixerInfo["build_type"] = parsedResponse.build_type;
this.mixerInfo["build_version"] = parsedResponse.build_version;
this.mixerInfo["visit_id_hash"] = parsedResponse.visit_id_hash;
this._raviDiagnostics.prime(this.mixerInfo.visit_id_hash);
this._hifiDiagnostics.prime(this.mixerInfo.visit_id_hash);
resolve({
success: true,
audionetInitResponse: parsedResponse
Expand Down Expand Up @@ -319,7 +335,7 @@ export class HiFiMixerSession {
}

// TODO: remove the entry from the peer state cache

this.concurrency -= allDeletedUserData.length;
if (this.onUsersDisconnected && allDeletedUserData.length > 0) {
this.onUsersDisconnected(allDeletedUserData);
}
Expand All @@ -334,14 +350,15 @@ export class HiFiMixerSession {

// See {@link this._mixerPeerKeyToStateCacheDict}.
let userDataCache: ReceivedHiFiAudioAPIData;
// If it is a knwon peer, we should have an entry for it in the cache dict
// If it is a known peer, we should have an entry for it in the cache dict
if (this._mixerPeerKeyToStateCacheDict[peerKeys[itr]]) {
userDataCache = this._mixerPeerKeyToStateCacheDict[peerKeys[itr]] as ReceivedHiFiAudioAPIData;
}
// if not let's create it.
else {
userDataCache = new ReceivedHiFiAudioAPIData();
this._mixerPeerKeyToStateCacheDict[peerKeys[itr]] = userDataCache;
this.concurrency += 1;
}

// This is a new empty data that will collect the changes received from the server.
Expand Down Expand Up @@ -510,7 +527,7 @@ export class HiFiMixerSession {
if (!this.webRTCAddress) {
let errMsg = `Couldn't connect: \`this.webRTCAddress\` is falsey!`;
try {
await this.disconnectFromHiFiMixer();
await this._disconnectFromHiFiMixer();
} catch (errorClosing) {
errMsg += `\nAdditionally, there was an error trying to close the failed connection. Error:\n${errorClosing}`;
}
Expand All @@ -534,7 +551,7 @@ export class HiFiMixerSession {
} catch (errorOpeningSignalingConnection) {
let errMsg = `Couldn't open signaling connection to \`${this.webRTCAddress.slice(0, this.webRTCAddress.indexOf("token="))}<token redacted>\`! Error:\n${errorOpeningSignalingConnection}`;
try {
await this.disconnectFromHiFiMixer();
await this._disconnectFromHiFiMixer();
} catch (errorClosing) {
errMsg += `\nAdditionally, there was an error trying to close the failed connection. Error:\n${errorClosing}`;
}
Expand All @@ -550,7 +567,7 @@ export class HiFiMixerSession {
errMsg = `High Fidelity server is at capacity; service is unavailable.`;
}
try {
await this.disconnectFromHiFiMixer();
await this._disconnectFromHiFiMixer();
} catch (errorClosing) {
errMsg += `\nAdditionally, there was an error trying to close the connection. Error:\n${errorClosing}`;
}
Expand All @@ -564,7 +581,7 @@ export class HiFiMixerSession {
} catch (initError) {
let errMsg = `\`audionet.init\` command failed! Error:\n${initError.error}`;
try {
await this.disconnectFromHiFiMixer();
await this._disconnectFromHiFiMixer();
} catch (errorClosing) {
errMsg += `\nAdditionally, there was an error trying to close the failed connection. Error:\n${errorClosing}`;
}
Expand All @@ -574,6 +591,7 @@ export class HiFiMixerSession {

this._raviSignalingConnection.removeStateChangeHandler(tempUnavailableStateHandler);

this.concurrency = 0;
this._raviSession.getCommandController().addBinaryHandler((data: any) => { this.handleRAVISessionBinaryData(data) }, true);

return Promise.resolve(audionetInitResponse);
Expand All @@ -584,6 +602,11 @@ export class HiFiMixerSession {
* @returns A Promise that _always_ Resolves with a "success" status string.
*/
async disconnectFromHiFiMixer(): Promise<string> {
this._raviDiagnostics.noteExplicitApplicationClose();
this._hifiDiagnostics.noteExplicitApplicationClose();
return this._disconnectFromHiFiMixer();
}
async _disconnectFromHiFiMixer(): Promise<string> {
async function close(thingToClose: (RaviSignalingConnection | RaviSession), nameOfThingToClose: string, closedState: string) {
if (thingToClose) {
let state = thingToClose.getState();
Expand Down Expand Up @@ -841,6 +864,7 @@ export class HiFiMixerSession {
if (this.onConnectionStateChanged) {
this.onConnectionStateChanged(this._currentHiFiConnectionState);
}
this._hifiDiagnostics.fire();
}
}

Expand All @@ -861,7 +885,7 @@ export class HiFiMixerSession {
case RaviSignalingStates.UNAVAILABLE:
this._setCurrentHiFiConnectionState(HiFiConnectionStates.Unavailable);
try {
await this.disconnectFromHiFiMixer();
await this._disconnectFromHiFiMixer();
} catch (errorClosing) {
HiFiLogger.log(`Error encountered while trying to close the connection. Error:\n${errorClosing}`);
}
Expand All @@ -875,6 +899,7 @@ export class HiFiMixerSession {
*/
async onRAVISessionStateChanged(event: any): Promise<void> {
HiFiLogger.log(`New RAVI session state: \`${event.state}\``);
this._raviDiagnostics.fire();
switch (event.state) {
case RaviSessionStates.CONNECTED:
this._mixerPeerKeyToStateCacheDict = {};
Expand All @@ -886,7 +911,7 @@ export class HiFiMixerSession {
}
this._setCurrentHiFiConnectionState(HiFiConnectionStates.Disconnected);
try {
await this.disconnectFromHiFiMixer();
await this._disconnectFromHiFiMixer();
} catch (errorClosing) {
HiFiLogger.log(`Error encountered while trying to close the connection. Error:\n${errorClosing}`);
}
Expand Down
Loading

0 comments on commit 4c9df73

Please sign in to comment.