// Player page rendering and bootstrap script assembly. const Handlebars = require('handlebars'); const path = require('path'); const packageMetadata = require('../../package.json'); const { mediaKind, safeJsonForScript, getPlayerPageTemplate, getPlayerPageAnnouncementsScript, getPlayerPageScript, getPlayerOnboardingLandingScript, getPlayerOnboardingFormScript, getPlayerRuntimeScripts } = require('./render-helpers'); const { createPageAuthBundle, createPageFetchAuthScript } = require('#src/request-auth'); const { getFontStylesheetHref } = require('#src/web/lib/media/font-library'); const PLAYER_MEDIA_DIR = path.join(__dirname, '..', '..', 'media'); function renderPage(template, options) { const stylesheetLinks = Array.isArray(options && options.stylesheets) ? options.stylesheets : []; return template({ TITLE: options.title, BODY_CLASS: options.bodyClass || '', BODY: new Handlebars.SafeString(options.body || ''), STYLESHEETS: new Handlebars.SafeString(stylesheetLinks.map(function (href) { return ``; }).join('')), SCRIPT_BLOCK: new Handlebars.SafeString(options.script || '') }); } function getPlayerServiceWorkerRegistrationScript() { const releaseVersion = encodeURIComponent(String(packageMetadata.version || 'development')); return [ '' ].join(''); } function renderOnboardingLandingBody(options) { const onboardingCode = String(options && options.pairingCode || '').trim(); const deviceId = String(options && options.deviceId || '').trim(); return [ '
', '
', '
', '
', '
', ' Onboarding QR code', '
', '

Scan this QR code with your phone

', '
', '
', '

Pulse Signage

', '

Quickly set up with your phone

', '
    ', '
  1. Open the camera and scan the QR code.
  2. ', '
  3. Log in to Pulse Signage and choose a screen.
  4. ', '
', '
', ' Pairing Code', ' ' + Handlebars.escapeExpression(onboardingCode || 'Loading...') + '', '
', '
', '
', '
', '
' ].join(''); } function renderOnboardingFormBody(deviceId) { return [ '
', '
', '

Pulse Signage

', '

Name this client

', '

Pick an existing screen and give this player a friendly name that will persist after refreshes.

', '
', ' ', ' ', ' ', ' ', ' ', '
', '
', '
', '
' ].join(''); } function renderOnboardingLandingScript() { return getPlayerOnboardingLandingScript()(); } function renderOnboardingFormScript(deviceId) { return getPlayerOnboardingFormScript()({ DEVICE_ID_JSON: new Handlebars.SafeString(JSON.stringify(deviceId || '')) }); } function renderPlayerPage(slug, initialData) { const serviceWorkerScript = getPlayerServiceWorkerRegistrationScript(); const template = getPlayerPageTemplate(); const hlsScriptTag = ''; const pageAuthToken = createPageAuthBundle({ scope: 'player', slug: String(slug || '').trim() }); const fontStylesheetHref = getFontStylesheetHref(PLAYER_MEDIA_DIR); const bootstrapScript = getPlayerPageScript()({ SLUG_JSON: new Handlebars.SafeString(JSON.stringify(slug)), INITIAL_DATA_JSON: new Handlebars.SafeString(safeJsonForScript(initialData || null)), REGION_SCRIPTS: '' }); const runtimeScriptTags = getPlayerRuntimeScripts().map(function (entry) { return ''; }).join(''); return renderPage(template, { title: 'Screen ' + slug, bodyClass: '', body: '
Loading screen...
', stylesheets: fontStylesheetHref ? [fontStylesheetHref] : [], script: createPageFetchAuthScript(pageAuthToken, '/ws/screens/' + encodeURIComponent(slug || '')) + hlsScriptTag + serviceWorkerScript + runtimeScriptTags + bootstrapScript + '' }); } function renderPlayerOnboardingLandingPage(options) { const pageAuthToken = createPageAuthBundle({ scope: 'onboarding' }); const fontStylesheetHref = getFontStylesheetHref(PLAYER_MEDIA_DIR); return renderPage(getPlayerPageTemplate(), { title: 'Onboard player', bodyClass: 'onboarding-page', body: renderOnboardingLandingBody(options), stylesheets: fontStylesheetHref ? [fontStylesheetHref] : [], script: createPageFetchAuthScript(pageAuthToken) + getPlayerServiceWorkerRegistrationScript() + renderOnboardingLandingScript() }); } function renderPlayerOnboardingFormPage(deviceId) { const pageAuthToken = createPageAuthBundle({ scope: 'onboarding', deviceId: String(deviceId || '').trim() }); const fontStylesheetHref = getFontStylesheetHref(PLAYER_MEDIA_DIR); return renderPage(getPlayerPageTemplate(), { title: 'Onboard screen', bodyClass: 'onboarding-page', body: renderOnboardingFormBody(deviceId), stylesheets: fontStylesheetHref ? [fontStylesheetHref] : [], script: createPageFetchAuthScript(pageAuthToken) + getPlayerServiceWorkerRegistrationScript() + renderOnboardingFormScript(deviceId) }); } module.exports = { mediaKind, renderPlayerPage, renderPlayerOnboardingLandingPage, renderPlayerOnboardingFormPage };