UNPKG

@jellyfin/sdk

Version:
44 lines (41 loc) 1.93 kB
import { SubtitleDeliveryMethod } from '../generated-client/models/subtitle-delivery-method.js'; /** * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * Generates a list of subtitle profiles * @param {HTMLVideoElement} videoElement - HTML video element to test again * @param {DeviceProfileGeneratorOptions} options - Options to pass to the subtitle generator * @returns List of subtitle profiles */ const getBrowserSubtitleProfiles = (videoElement, options) => { const subtitleProfiles = []; if (videoElement.textTracks !== null) { subtitleProfiles.push({ Format: 'vtt', Method: SubtitleDeliveryMethod.External }); } if (options === null || options === void 0 ? void 0 : options.ssaExternal) { subtitleProfiles.push({ Format: 'ssa', Method: SubtitleDeliveryMethod.External }, { Format: 'ass', Method: SubtitleDeliveryMethod.External }); } else { subtitleProfiles.push({ Format: 'ssa', Method: SubtitleDeliveryMethod.Encode }, { Format: 'ass', Method: SubtitleDeliveryMethod.Encode }); } return subtitleProfiles; }; /** * Generates a device profile based on a few options and the current browser capabilites * @exports * @param {DeviceProfileGeneratorOptions} options - Options to pass to the different profiles generators * @param {HTMLVideoElement} videoElement - Optionnal HTML video element to use, else it'll create one * @returns A detected device profile */ const getBrowserDeviceProfile = (options, videoElement) => { const deviceProfile = {}; if (!videoElement) { videoElement = document.createElement('video'); } deviceProfile.SubtitleProfiles = getBrowserSubtitleProfiles(videoElement, options); return deviceProfile; }; export { getBrowserDeviceProfile };