Skip to content

Commit

Permalink
Merge pull request #175 from bridie-hifi/2021-08-26-release
Browse files Browse the repository at this point in the history
Weekly-ish merge into Release branch
  • Loading branch information
howard-stearns authored Aug 26, 2021
2 parents 0e21081 + b2773a7 commit 5777b61
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 45 deletions.
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hifi-spatial-audio",
"version": "1.4.1",
"version": "1.5.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
38 changes: 23 additions & 15 deletions src/classes/HiFiCommunicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,8 @@ export interface ConnectionRetryAndTimeoutConfig {
* connection is disconnected. When this is set to true, we will attempt
* to reconnect if any disconnect from any cause occurs.
* By default, reconnections are not automatically attempted.
* NOTE: The retrying that happens when this is set to `true` does not currently take into account
* the reason WHY a connection was disconnected. This means that if this is
* set to true, a connection that is disconnected via a purposeful server-side
* action (e.g. a "kick") will be automatically reconnected. (However, connections
* that are explicitly closed from the client side via the `disconnectFromHiFiAudioAPIServer()`
* method will stay closed.)
* The client will not attempt to reconnect when the client is 'kicked'
* or the space is forcibly shut down.
*/
autoRetryOnDisconnect?: boolean;
/**
Expand Down Expand Up @@ -178,7 +174,12 @@ export interface HiFiConnectionAttemptResult {
* is made. It is primarily used for debugging and includes information about the server build version and
* other details. This will not be set if there is an error when connecting to the server.
*/
audionetInitResponse?: any
audionetInitResponse?: any,
/**
* `disableReconnect` will be present and 'true' on a failed connection attempt or disconnect if reconnects should not
* be performed. This typically happens during a kick operation.
*/
disableReconnect?: boolean;
}

/**
Expand Down Expand Up @@ -458,6 +459,9 @@ export class HiFiCommunicator {
signalingHostURLSafe = signalingHostURL ? signalingHostURL : HiFiConstants.DEFAULT_PROD_HIGH_FIDELITY_ENDPOINT;
}

// if reconnections are enabled, attempt them if necessary.
this._mixerSession._disableReconnect = false;

signalingPort = signalingPort ? signalingPort : HiFiConstants.DEFAULT_PROD_HIGH_FIDELITY_PORT;
let webRTCSignalingAddress = `wss://${signalingHostURLSafe}:${signalingPort}/?token=`;
this._mixerSession.webRTCAddress = `${webRTCSignalingAddress}${hifiAuthJWT}`;
Expand Down Expand Up @@ -513,7 +517,7 @@ export class HiFiCommunicator {
// gets handled by the _manageConnection callback handler. (Note that calls to our _connectToHiFiMixer()
// method get handled entirely by callback-initiated retry code, so we should never get here unless
// a callback asked us to do it.)
this._mixerSession.connectToHiFiMixer({ webRTCSessionParams: this._webRTCSessionParams, customSTUNandTURNConfig: this._customSTUNandTURNConfig, timeout: timeoutPerConnectionAttempt });
this._mixerSession.connectToHiFiMixer({ webRTCSessionParams: this._webRTCSessionParams, customSTUNandTURNConfig: this._customSTUNandTURNConfig, timeout: timeoutPerConnectionAttempt, initData: this._currentHiFiAudioAPIData });
}

/**
Expand Down Expand Up @@ -621,14 +625,15 @@ export class HiFiCommunicator {
// OK, we've dealt with the situation where there's already a retry cycle going.
// Now see if we need to start one.
let retriesTimeoutMs = 0;

if (this._currentHiFiConnectionState === HiFiConnectionStates.Connecting &&
this._connectionRetryAndTimeoutConfig.autoRetryInitialConnection) {
this._connectionRetryAndTimeoutConfig.autoRetryInitialConnection &&
!message.disableReconnect) {
// The user has started a connection attempt. It failed, and they want to retry.
retriesTimeoutMs = 1000 * this._connectionRetryAndTimeoutConfig.maxSecondsToSpendRetryingInitialConnection;

} else if (this._currentHiFiConnectionState === HiFiConnectionStates.Reconnecting &&
this._connectionRetryAndTimeoutConfig.autoRetryOnDisconnect) {
this._connectionRetryAndTimeoutConfig.autoRetryOnDisconnect &&
!message.disableReconnect) {
// The user had previously been trying to reconnect. It failed, and they want to keep retrying.
// (Note - we're not even supposed to be here; this situation should have been
// caught by the "there's already a timer in play" logic above.
Expand All @@ -637,7 +642,8 @@ export class HiFiCommunicator {
retriesTimeoutMs = 1000 * this._connectionRetryAndTimeoutConfig.maxSecondsToSpendRetryingOnDisconnect;

} else if (this._currentHiFiConnectionState === HiFiConnectionStates.Connected &&
this._connectionRetryAndTimeoutConfig.autoRetryOnDisconnect) {
this._connectionRetryAndTimeoutConfig.autoRetryOnDisconnect &&
!message.disableReconnect) {
// The user had previously been connected. They got disconnected, and they want to retry
retriesTimeoutMs = 1000 * this._connectionRetryAndTimeoutConfig.maxSecondsToSpendRetryingOnDisconnect;

Expand Down Expand Up @@ -960,7 +966,7 @@ export class HiFiCommunicator {
* @param position - The new position of the user.
* @param orientationQuat - The new orientationQuat of the user.
* @param orientationEuler - The new orientationEuler of the user.
* @param volumeThreshold - The new volumeThreshold of the user.
* @param volumeThreshold - The new volumeThreshold of the user. Setting this to null will use the space default volume threshold.
* @param hiFiGain - This value affects how loud User A will sound to User B at a given distance in 3D space.
* This value also affects the distance at which User A can be heard in 3D space.
* Higher values for User A means that User A will sound louder to other users around User A, and it also means that User A will be audible from a greater distance.
Expand Down Expand Up @@ -997,7 +1003,8 @@ export class HiFiCommunicator {
this._currentHiFiAudioAPIData.orientationQuat = eulerToQuaternion(checkedEuler, ourHiFiAxisConfiguration.eulerOrder);
}

if (typeof (volumeThreshold) === "number") {
if (typeof (volumeThreshold) === "number" ||
volumeThreshold === null) {
this._currentHiFiAudioAPIData.volumeThreshold = volumeThreshold;
}
if (typeof (hiFiGain) === "number") {
Expand Down Expand Up @@ -1052,7 +1059,8 @@ export class HiFiCommunicator {
this._lastTransmittedHiFiAudioAPIData.orientationQuat.z = dataJustTransmitted.orientationQuat.z ?? this._lastTransmittedHiFiAudioAPIData.orientationQuat.z;
}

if (typeof (dataJustTransmitted.volumeThreshold) === "number") {
if (typeof (dataJustTransmitted.volumeThreshold) === "number" ||
dataJustTransmitted.volumeThreshold === null) {
this._lastTransmittedHiFiAudioAPIData["volumeThreshold"] = dataJustTransmitted.volumeThreshold;
}

Expand Down
Loading

0 comments on commit 5777b61

Please sign in to comment.