"use strict";

exports.__esModule = true;
exports.default = exports.useMediaSession = void 0;

var _react = require("react");

// modified from https://github.com/nico-martin/yt-audio MIT License
const useMediaSession = ({
  element,
  mediaMetadata,
  controls
}) => {
  (0, _react.useEffect)(() => {
    if (!('mediaSession' in navigator)) {
      console.error('no mediaSession support');
      return;
    }

    if (!element || !controls || !mediaMetadata || !mediaMetadata.src) {
      // console.log({element, controls, mediaMetadata});
      // console.error('no element or src');
      return;
    }

    navigator.mediaSession.metadata = new window.MediaMetadata({ ...mediaMetadata,
      artwork: [{
        src: mediaMetadata.artwork,
        sizes: '192x192',
        type: 'image/jpeg'
      }]
    });
    Object.keys(controls).forEach(e => navigator.mediaSession.setActionHandler(e, controls[e]));
  }, [element, controls, mediaMetadata]);
};

exports.useMediaSession = useMediaSession;
var _default = useMediaSession;
exports.default = _default;