import type { HlsConfig } from 'hls.js'

import { readToken } from 'helpers/token'

import { isMobileDevice } from 'config/userAgent'

export const streamConfig: Partial<HlsConfig> = {
  liveSyncDuration: 30,
  maxBufferLength: 30,
  xhrSetup: (xhr, urlString) => {
    const url = new URL(urlString)
    url.searchParams.set('access_token', readToken() || '')
    xhr.open('GET', url.toString())
  },
}

export const REWIND_SECONDS = isMobileDevice ? 10 : 5

export const HOUR_IN_MILLISECONDS = 60 * 60 * 1000
