const Handlebars = require('handlebars'); const { mediaKind, safeJsonForScript, getPlayerPageTemplate, getPlayerClientNameScript, getPlayerPageOfflineScript, getPlayerPagePlaylistScript, getPlayerPageCommandsScript, getPlayerPageRenderingScript, getPlayerPagePlaybackScript, getPlayerPageScript, getPlayerRegionScripts, getPlayerOnboardingLandingScript, getPlayerOnboardingFormScript } = require('./render-helpers'); const { createPageAuthBundle, createPageFetchAuthScript } = require('../request-auth'); function renderPage(template, options) { return template({ TITLE: options.title, BODY_CLASS: options.bodyClass || '', BODY: new Handlebars.SafeString(options.body || ''), SCRIPT_BLOCK: new Handlebars.SafeString(options.script || '') }); } function getPlayerServiceWorkerRegistrationScript() { return [ '' ].join(''); } function renderOnboardingLandingBody() { return [ '
', '
', '

Pulse Signage

', '

Onboard this player

', '

Choose an existing screen, name the client, and either scan the QR code or finish right here with a keyboard and mouse.

', '
', '
', '
', ' Onboarding QR code', '
', '
Preparing onboarding link...
', '
', '
', ' ', ' ', ' ', '
', '
', '
', '
', '
' ].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 onboardingScript = getPlayerClientNameScript()(); const offlineScript = getPlayerPageOfflineScript()(); const playlistScript = getPlayerPagePlaylistScript()(); const commandScript = getPlayerPageCommandsScript()(); const renderingScript = getPlayerPageRenderingScript()(); const playbackScript = getPlayerPagePlaybackScript()(); const serviceWorkerScript = getPlayerServiceWorkerRegistrationScript(); const template = getPlayerPageTemplate(); const hlsScriptTag = ''; const pageAuthToken = createPageAuthBundle({ scope: 'player', slug: String(slug || '').trim() }); const script = getPlayerPageScript()({ SLUG_JSON: new Handlebars.SafeString(JSON.stringify(slug)), INITIAL_DATA_JSON: new Handlebars.SafeString(safeJsonForScript(initialData || null)), REGION_SCRIPTS: new Handlebars.SafeString(getPlayerRegionScripts()) }); return renderPage(template, { title: 'Screen ' + slug, body: '
Loading screen...
', script: createPageFetchAuthScript(pageAuthToken) + hlsScriptTag + serviceWorkerScript + '' + '' + '' + '' + '' + onboardingScript + script }); } function renderPlayerOnboardingLandingPage() { const pageAuthToken = createPageAuthBundle({ scope: 'onboarding' }); return renderPage(getPlayerPageTemplate(), { title: 'Onboard player', bodyClass: 'onboarding-page', body: renderOnboardingLandingBody(), script: createPageFetchAuthScript(pageAuthToken) + getPlayerServiceWorkerRegistrationScript() + renderOnboardingLandingScript() }); } function renderPlayerOnboardingFormPage(deviceId) { const pageAuthToken = createPageAuthBundle({ scope: 'onboarding', deviceId: String(deviceId || '').trim() }); return renderPage(getPlayerPageTemplate(), { title: 'Onboard screen', bodyClass: 'onboarding-page', body: renderOnboardingFormBody(deviceId), script: createPageFetchAuthScript(pageAuthToken) + getPlayerServiceWorkerRegistrationScript() + renderOnboardingFormScript(deviceId) }); } module.exports = { mediaKind, renderPlayerPage, renderPlayerOnboardingLandingPage, renderPlayerOnboardingFormPage };