UNPKG

cloudinary-video-player

Version:
27 lines (23 loc) 7.44 kB
/*! * Cloudinary Video Player v4.0.3 * Built on 2026-06-07T12:24:04.618Z * https://github.com/cloudinary/cloudinary-video-player */ "use strict"; /* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ (self["cloudinaryVideoPlayerChunkLoading"] = self["cloudinaryVideoPlayerChunkLoading"] || []).push([["utils_schedule_js"],{ /***/ "./utils/schedule.js" /*!***************************!*\ !*** ./utils/schedule.js ***! \***************************/ (__unused_webpack_module, __webpack_exports__, __webpack_require__) { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ getElementForSchedule: () => (/* reexport safe */ _lazy_player__WEBPACK_IMPORTED_MODULE_0__.getVideoElement),\n/* harmony export */ isWithinSchedule: () => (/* binding */ isWithinSchedule),\n/* harmony export */ parseDay: () => (/* binding */ parseDay),\n/* harmony export */ renderScheduleImage: () => (/* reexport safe */ _lazy_player__WEBPACK_IMPORTED_MODULE_0__.preparePlayerPlaceholder),\n/* harmony export */ scheduleBootstrap: () => (/* binding */ scheduleBootstrap),\n/* harmony export */ shouldUseScheduleBootstrap: () => (/* binding */ shouldUseScheduleBootstrap)\n/* harmony export */ });\n/* harmony import */ var _lazy_player__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lazy-player */ \"./utils/lazy-player.js\");\n/**\n * Schedule utilities: weekly time-range parsing and bootstrap.\n * Outside-schedule bootstrap reuses lazy placeholder DOM + deferred load helpers.\n * Uses browser local time. No videojs dependency for the bootstrap path.\n */\n\n\nconst INTERNAL_ANALYTICS_URL = 'https://analytics-api-s.cloudinary.com';\nconst sendScheduleImageAnalytics = options => {\n const allowReport = options?.sourceOptions?.allowUsageReport ?? options?.allowUsageReport;\n if (allowReport === false) return;\n try {\n const params = new URLSearchParams({\n scheduleImageRendered: 'true',\n cloudName: options?.cloudName || options?.cloudinaryConfig?.cloud_name || ''\n }).toString();\n fetch(`${INTERNAL_ANALYTICS_URL}/video_player_source?${params}`);\n } catch {\n // noop\n }\n};\nconst getCloudNameFromOptions = options => options?.cloudName || options?.cloud_name || options?.cloudinaryConfig?.cloud_name;\nconst getPublicIdFromOptions = options => options?.publicId || options?.sourceOptions?.publicId;\n\n/**\n * Returns true when schedule.weekly is configured and current time is outside the schedule.\n * @param {object} options - player options\n * @returns {boolean}\n */\nconst shouldUseScheduleBootstrap = options => {\n const schedule = options?.schedule;\n const weekly = schedule?.weekly;\n return Array.isArray(weekly) && weekly.length > 0 && !isWithinSchedule(schedule, new Date());\n};\n\n/**\n * Bootstrap path when outside schedule: render poster, return stub with loadPlayer().\n * @param {string|HTMLElement} elem - Element id or video element\n * @param {object} options - player options\n * @param {function} [ready] - Video.js ready callback (passed when full player loads)\n * @returns {object} Stub with source() and loadPlayer()\n */\nconst scheduleBootstrap = async (elem, options, ready) => {\n const videoElement = (0,_lazy_player__WEBPACK_IMPORTED_MODULE_0__.getVideoElement)(elem);\n const cloudName = getCloudNameFromOptions(options);\n const publicId = getPublicIdFromOptions(options);\n if (!cloudName || !publicId) {\n throw new Error('schedule.weekly requires cloudName and publicId when outside schedule');\n }\n const {\n buildPosterUrl\n } = await __webpack_require__.e(/*! import() */ \"cld-poster-url\").then(__webpack_require__.bind(__webpack_require__, /*! ./poster-url */ \"./utils/poster-url.js\"));\n const cloudinaryConfig = options?.cloudinaryConfig || {\n cloud_name: cloudName\n };\n const posterUrl = buildPosterUrl(cloudName, publicId, cloudinaryConfig);\n const fluid = options?.fluid !== false;\n const {\n videoElement: vEl,\n hadControls\n } = (0,_lazy_player__WEBPACK_IMPORTED_MODULE_0__.preparePlayerPlaceholder)(videoElement, posterUrl, {\n fluid,\n width: options?.width,\n height: options?.height,\n cropMode: options?.sourceOptions?.cropMode,\n sourceOptions: options?.sourceOptions,\n aspectRatio: options?.aspectRatio\n });\n sendScheduleImageAnalytics(options);\n const stub = {\n source: () => stub,\n loadPlayer: () => {\n if (hadControls) vEl.setAttribute('controls', '');\n return (0,_lazy_player__WEBPACK_IMPORTED_MODULE_0__.loadPlayer)({\n videoElement: vEl,\n options,\n ready\n });\n }\n };\n return stub;\n};\nconst DAY_MAP = {\n sunday: 0,\n sun: 0,\n monday: 1,\n mon: 1,\n tuesday: 2,\n tue: 2,\n tues: 2,\n wednesday: 3,\n wed: 3,\n thursday: 4,\n thu: 4,\n thur: 4,\n thurs: 4,\n friday: 5,\n fri: 5,\n saturday: 6,\n sat: 6\n};\n\n/**\n * Parse readable day-of-week string to JS Date.getDay() value (0=Sun .. 6=Sat).\n * @param {string} day - Full or abbreviated day name (case-insensitive)\n * @returns {number|null} 0-6, or null if invalid\n */\nconst parseDay = day => {\n if (typeof day !== 'string') return null;\n const key = day.toLowerCase().trim();\n return DAY_MAP[key] ?? null;\n};\n\n/**\n * Parse \"HH:mm\" string to minutes since midnight.\n * @param {string} timeStr - \"09:00\" or \"17:30\"\n * @returns {number|null} minutes, or null if invalid\n */\nconst parseTime = timeStr => {\n if (typeof timeStr !== 'string') return null;\n const match = timeStr.trim().match(/^(\\d{1,2}):(\\d{2})$/);\n if (!match) return null;\n const h = parseInt(match[1], 10);\n const m = parseInt(match[2], 10);\n if (h < 0 || h > 23 || m < 0 || m > 59) return null;\n return h * 60 + m;\n};\n\n/**\n * Check if a date falls within any configured weekly slot (local time).\n * @param {{ weekly?: Array<{ day: string, start: string, duration: number }> }} schedule - schedule config\n * @param {Date} date - date to check (uses local time)\n * @returns {boolean} true if within a slot\n */\nconst isWithinSchedule = (schedule, date) => {\n const weekly = schedule?.weekly;\n if (!Array.isArray(weekly) || weekly.length === 0) return true;\n const WEEK = 7 * 1440;\n const nowInWeek = date.getDay() * 1440 + date.getHours() * 60 + date.getMinutes();\n for (const slot of weekly) {\n const slotDay = parseDay(slot.day);\n if (slotDay === null) continue;\n const startMin = parseTime(slot.start);\n if (startMin === null || typeof slot.duration !== 'number' || slot.duration <= 0) continue;\n const slotStart = slotDay * 1440 + startMin;\n const durationMin = slot.duration * 60;\n const elapsed = (nowInWeek - slotStart + WEEK) % WEEK;\n if (elapsed < durationMin) return true;\n }\n return false;\n};\n\n\n//# sourceURL=webpack:///./utils/schedule.js?\n}"); /***/ } }]);