From fec4e19c1d3816693a38bd1f24f000643115d0aa Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Thu, 1 Sep 2022 07:01:02 -0600 Subject: [PATCH] Selectively force long polling for ios only --- web/lib/firebase/init.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/web/lib/firebase/init.ts b/web/lib/firebase/init.ts index b9c96a9b..44bc3a2a 100644 --- a/web/lib/firebase/init.ts +++ b/web/lib/firebase/init.ts @@ -10,9 +10,28 @@ import { connectFunctionsEmulator, getFunctions } from 'firebase/functions' // Initialize Firebase export const app = getApps().length ? getApp() : initializeApp(FIREBASE_CONFIG) -export const db = initializeFirestore(app, { - experimentalForceLongPolling: true, -}) +function iOS() { + if (typeof navigator === 'undefined') { + // we're on the server, do whatever + return false + } + return ( + [ + 'iPad Simulator', + 'iPhone Simulator', + 'iPod Simulator', + 'iPad', + 'iPhone', + 'iPod', + ].includes(navigator.platform) || + // iPad on iOS 13 detection + (navigator.userAgent.includes('Mac') && 'ontouchend' in document) + ) +} +// Necessary for ios, see: https://github.com/firebase/firebase-js-sdk/issues/6118 +const opts = iOS() ? { experimentalForceLongPolling: true } : {} +export const db = initializeFirestore(app, opts) + export const functions = getFunctions() export const storage = getStorage()