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

Hubs Cloud - Temporary fix for Safari audio issues #4442

Merged
merged 2 commits into from
Jul 26, 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
6 changes: 2 additions & 4 deletions src/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import "aframe-slice9-component";
import "./utils/threejs-positional-audio-updatematrixworld";
import "./utils/threejs-world-update";
import patchThreeAllocations from "./utils/threejs-allocation-patches";
import { detectOS, detect } from "detect-browser";
import { isSafari } from "./utils/detect-safari";
import {
getReticulumFetchUrl,
getReticulumMeta,
Expand Down Expand Up @@ -687,11 +687,9 @@ document.addEventListener("DOMContentLoaded", async () => {
return;
}

const detectedOS = detectOS(navigator.userAgent);
const browser = detect();
// HACK - it seems if we don't initialize the mic track up-front, voices can drop out on iOS
// safari when initializing it later.
if (["iOS", "Mac OS"].includes(detectedOS) && ["safari", "ios"].includes(browser.name)) {
if (isSafari()) {
try {
await navigator.mediaDevices.getUserMedia({ audio: true });
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions src/storage/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import merge from "deepmerge";
import Cookies from "js-cookie";
import jwtDecode from "jwt-decode";
import { qsGet } from "../utils/qs_truthy.js";
import { isSafari } from "../utils/detect-safari";

const LOCAL_STORE_KEY = "___hubs_store";
const STORE_STATE_CACHE_KEY = Symbol();
Expand Down Expand Up @@ -239,6 +240,12 @@ export default class Store extends EventTarget {
preferences: {}
});

// Temporary fix for distorted audio in Safari.
// See https://github.com/mozilla/hubs/issues/4411
if (isSafari()) {
this.update({ preferences: { audioOutputMode: "audio" } });
}

this._shouldResetAvatarOnInit = false;

const oauthFlowCredentials = Cookies.getJSON(OAUTH_FLOW_CREDENTIALS_KEY);
Expand Down
6 changes: 5 additions & 1 deletion src/systems/audio-settings-system.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isSafari } from "../utils/detect-safari";

function updateMediaAudioSettings(mediaVideo, settings) {
mediaVideo.el.setAttribute("media-video", {
distanceModel: settings.mediaDistanceModel,
Expand Down Expand Up @@ -43,7 +45,9 @@ export class AudioSettingsSystem {

this.sceneEl.addEventListener("reset_scene", this.onSceneReset);

if (window.APP.store.state.preferences.audioOutputMode === "audio") {
// Do not force panner audio in Safari as a temporary fix for distorted audio.
// See https://github.com/mozilla/hubs/issues/4411
if (!isSafari() && window.APP.store.state.preferences.audioOutputMode === "audio") {
//hack to always reset to "panner"
window.APP.store.update({
preferences: { audioOutputMode: "panner" }
Expand Down
6 changes: 6 additions & 0 deletions src/utils/detect-safari.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { detect } from "detect-browser";

export function isSafari() {
const browser = detect();
return ["iOS", "Mac OS"].includes(browser.os) && ["safari", "ios"].includes(browser.name)
}