### Example: Read XML Config File Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Demonstrates reading an XML configuration file using its ContentID. This example loads the SDK, configures an XML input, and then reads the content. ```html+jinja Example of reading an XML file {{ __loadsdk__ }} {{ __config__(name="config_file", type="xml", label="XML config") }} ``` -------------------------------- ### Use signageVisible Promise Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md This example demonstrates how to use the `window.signageVisible` promise to execute code only after the 'show' event has fired, ensuring the app is visible before proceeding. It's useful for starting timers or updating UI elements that depend on visibility. ```html+jinja Sample App with Visible Promise {# When using Javascript you need to load the Signage SDK first #} {{ __loadsdk__ }}
``` -------------------------------- ### Handle App Visibility and Start Animation Source: https://github.com/onsigntv/apps/blob/master/samples/social/facebook/app.html Starts the content animation and interval for displaying items once the app becomes visible. Includes a small delay to synchronize timers. ```javascript // signageVisible promise resolves when app is visible // For more info on our promises, check: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md#signage-promises window.signageVisible.then(function () { // Sometimes devices have a slightly offset time between their timers // and Javascript timers. A timeout of up to a second fixes this issue. setTimeout(function () { // Enable animation and set interval to display each item. document.body.classList.add('animate'); setInterval(displayItem, window.appConfig.duration * 1000); }, 500); }); ``` -------------------------------- ### Load SDK and Configuration Source: https://github.com/onsigntv/apps/blob/master/samples/clock/date-time-fullscreen/app.html Ensures the SDK is loaded and configures user-selectable options for color scheme, language, and time format. This setup is crucial for all apps using Javascript. ```html {# Make sure you load the SDK in all apps that use Javascript before starting configuration! #} {{ __loadsdk__() }} {# Check https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md for info on how to add user-configurable variables. #} {{ __config__(name="cs", type="choice", label="Color scheme", choices=[ ("black", "Black"), ("sandstone", "Sandstone"), ("teal", "Teal"), ("olive", "Olive"), ("coral", "Coral"), ]) }} {{ __config__(name="lang", type="choice", label="Language", choices=[ ("en", "English"), ("pt-br", "Brazilian Portuguese"), ("es", "Spanish"), ("it", "Italian"), ("da", "Danish"), ("fr", "French"), ("nn", "Norwegian Nynorwk"), ("sv", "Swedish"), ("zh", "Chinese"), ("ja", "Japanese"), ]) }} {{ __config__(name="format", type="choice", label="Time format", choices=[ ("ampm", "AM/PM"), ("24h", "24H"), ]) }} ``` -------------------------------- ### Start Content Animation and Interval Source: https://github.com/onsigntv/apps/blob/master/samples/rss/uol-rss/app.html Starts the content animation and sets an interval to display items after the signageVisible promise resolves. Includes a timeout to adjust for device timer offsets. ```javascript window.signageVisible.then(function () { setTimeout(function () { document.body.classList.add('animate'); setInterval(displayItem, window.appConfig.duration * 1000); }, 500); }); ``` -------------------------------- ### Load Signage SDK and Configure App Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md This example demonstrates how to load the Signage SDK and configure app settings like background color. It also includes a basic Javascript event listener for size changes. ```html+jinja Sample App with Events {# When using Javascript you need to load the Signage SDK first #} {{ __loadsdk__ }} {# After loading you can add your configuration #} {{ __config__(type="color", name="background_color", label="Text background color", value="#FFFFFF") }}
SIZE: ?x?
``` -------------------------------- ### Initialize and Render Data Source: https://github.com/onsigntv/apps/blob/master/samples/datafeed-movie-quotes/app.html Fetches initial data and sets up a listener for subsequent updates. It then renders the initial data and waits for the app to become visible before starting the update loop. ```javascript window.dataFeed.then(function(data) { // At each loop interval, check if there's an update pending. // If so, replace the current data with the pending data and clear the pending update. if (pendingQuotes) { currentQuotes = pendingQuotes; pendingQuotes = null; } // If there is data to display, show the next quote. Otherwise, show the "no content" message. if (currentQuotes.length > 0) { showNextQuote(); } else { showNoData(); } }); window.dataFeed.then(function(data) { // When the data feed promise resolves for the first time, save the data // to the list that will be used to render the content. currentQuotes = data.source; data.update.then(function update(pendingData) { // When the data feed updates again, store the new data in a temporary variable // so it doesn’t immediately replace the currently displayed content. // This allows the update to be applied on the next loop iteration. pendingQuotes = pendingData.source; // Ensure the function stays subscribed to future updates and always receives the latest data. // Multiple pending data might happen in sequence, so as soon as the update Promise is fullfilled // the pending data should be overwritten. pendingData.update.then(update); }) // When the initial data feed promise resolves, render the data. // Do NOT start the loop yet, wait until the `signageVisible` promise resolves. // At this point the app will be rendered but not yet visible on screen. renderData(); }); ``` -------------------------------- ### Choice Configuration using __config__ function Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md Use the __config__ function with the 'choices' parameter for a more concise way to define user choices. This example also sets the background color. ```html+jinja Sample App {{ __config__(name="background", type="choice", label="Background Color", choices=[ ("transparent", "Transparent Color"), ("light", "Light Color"), ("dark", "Dark Color"), ]) }}

Hello User!

``` -------------------------------- ### Access App Configuration with js=True Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md This example shows how to access app configuration values, specifically a 'userDate', within JavaScript using the `window.appConfig` object. It ensures the SDK is loaded before accessing configuration and formats the date according to the app's locale. This is useful for dynamically displaying user-provided settings. ```html+javascript appConfig Example {{ __loadsdk__ }} {{ __config__(name="userDate", type="date", label="Date to be displayed", js=True) }}
``` -------------------------------- ### Web Feed App Configuration Example Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md This Jinja2 template demonstrates how to configure and render content from a web feed. It iterates through feed entries, displaying their titles, publish dates, content, images, and extra information. ```html+jinja App with Web Feed {{ __config__(type="webfeed", name="webfeed", label="RSS or Atom Feed URL", value="http://webfeed.rss") }} {% for entry in webfeed %}
{{ entry.title }} {# More info on formatting dates at http://strftime.org/ #} {{ entry.publish_date.strftime("%m/%d/%Y") }} {% if entry.content %}

{{ entry.content }}

{% endif %} {% if entry.image %} {% endif %} {% if entry.extra %}

{{ entry.extra.summary }}

{% endif %}
{% endfor %} ``` -------------------------------- ### HTML Structure and Styling Source: https://github.com/onsigntv/apps/blob/master/samples/datafeed-media-cycling/app.html Basic HTML and CSS setup for the media cycling app, ensuring elements fill the available space and defining styles for play buttons and aspect ratio adjustments. ```html html, body { margin: 0; padding: 0; overflow: hidden; background-color: transparent; } html, body, img, video, #container, #play-box { width: 100%; height: 100%; } img, video { object-fit: contain; } #container, #play-box { display: flex; align-items: center; justify-content: center; } #play-box { position: absolute; background-color: rgba(0, 0, 0, 0.5); } .play-btn { width: 80px; height: 80px; background-color: rgba(0, 0, 0, 0.5); border: 2px solid #fff; border-radius: 50%; position: relative; cursor: pointer; } .play-btn::before { content: ''; position: absolute; top: 18px; left: 28px; border-style: solid; border-width: 20px 0 20px 30px; border-color: transparent transparent transparent #fff; } .fit-height { height: 100%; width: auto; } .fit-width { width: 100%; height: auto; } .fill { object-fit: fill; } .cover { object-fit: cover; } ``` -------------------------------- ### Handle Signage Visibility and Timer Source: https://github.com/onsigntv/apps/blob/master/samples/weather/small-weather-forecast/app.html Starts a timer to cycle through forecast displays only after the application becomes visible on screen. This ensures resources are not wasted when the app is not in view. ```javascript // window.signageVisible resolves when the app becomes visible on screen. // Start the day-cycling timer only after the app is actually visible. // For more info on signage promises, check: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md#signagevisible window.signageVisible.then(function() { var activeForecast = 1; window.setInterval(function cycleWeather() { activeForecast += 1; if (activeForecast > 3) { activeForecast = 1; } document.querySelector('.forecast').setAttribute('data-active', activeForecast); }, 5000); }); ``` -------------------------------- ### Load Facebook SDK Source: https://github.com/onsigntv/apps/blob/master/samples/social/facebook/app.html Ensure the Facebook SDK is loaded in all applications using Javascript before initializing the configuration. Refer to the provided GitHub link for detailed setup instructions. ```html {{ __loadsdk__ }} ``` -------------------------------- ### Choice Configuration using Meta Tags Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md Configure user choices using multiple meta tags with the same name. The 'value' attribute is mandatory. This example sets the background color. ```html+jinja Sample App

Hello User!

``` -------------------------------- ### Initialize Carousel on Signage Visibility Source: https://github.com/onsigntv/apps/blob/master/samples/rss/uol-rss/app2.html Starts the item display interval after the signage becomes visible. Includes a small delay to account for potential timer offsets. Assumes `window.signageVisible` promise and `window.appConfig.duration` are available. ```javascript window.signageVisible.then(function () { setTimeout(function () { document.body.classList.add('animate'); setInterval(displayItem, window.appConfig.duration * 1000); }, 500); }); ``` -------------------------------- ### Specify Thumbnail Timing with JavaScript Source: https://github.com/onsigntv/apps/blob/master/docs/THUMBNAILING.md To control when a thumbnail is taken, add `` and set the element ID to `signage-take-screenshot` when the app is ready. This example fetches data and then signals readiness after rendering. ```html

Some loaded content:

``` -------------------------------- ### Get Playback Information Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Retrieves a stringified JSON object containing details about the player and the current campaign. It's recommended to wrap this in a try/catch block as the signage object might not be available and JSON parsing can fail. ```javascript try { // Get the stringified JSON object representing the `playbackInfo` data from the signage object. var data = signage.playbackInfo(); // Parse data into a JSON object var playbackInfo = JSON.parse(data); // Log the player name: console.log(playbackInfo.player.name); } catch (ex) { console.error('Signage object not available or data var does not contain a valid JSON string.'); } ``` -------------------------------- ### Generated Richtext HTML Example Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md Example of HTML content generated for a richtext field with inlined CSS styles and relative font units. ```html

Title

Subtitle

Have fun styling your text with a variety of options.

This is a WYSIWYG editor. Be creative!

``` -------------------------------- ### Start Quote Loop After Visibility Source: https://github.com/onsigntv/apps/blob/master/samples/datafeed-movie-quotes/app.html Starts the quote loop only after both the data feed has loaded and the signage becomes visible. Includes a timeout to synchronize timers on Android devices. ```javascript Promise.all([window.dataFeed, window.signageVisible]).then(function() { // Sometimes Android devices have a slightly offset time between Android // and Javascript timers. This was causing some apps to flash a new item // before it is changed to a different content. // The 500ms timeout below fixes this issue and ensures the current position is // correcly saved through `localStorage`. // The first item will be shown for an additional 500ms. setTimeout(function() { // Initializes the quote loop and sets the interval for content updates // based on the configured display duration. Ensures each quote is shown // for the specified number of seconds before changing to the next. setInterval(renderData, Math.max(window.appConfig.quote_duration * 1000, 1000)); }, 500); }); ``` -------------------------------- ### Load SDK and Configuration Source: https://github.com/onsigntv/apps/blob/master/samples/weather/weather-forecast-horizontal-bar/app.html Ensures the SDK is loaded before configuration. Provides links to user configuration documentation. ```html {# Make sure you load the SDK in all apps that use Javascript before starting configuration! #} {{ __loadsdk__ }} {# Check https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md for info on how to add user-configurable variables. #} ``` -------------------------------- ### Initialize Weather Data and Display Source: https://github.com/onsigntv/apps/blob/master/samples/weather/small-weather-forecast/app.html Sets up global variables for forecast data, localization strings, and temperature scale. It then defines functions to display temperature and the daily forecast, and loads the initial forecast data. ```javascript var PRELOADED_FORECAST = {{ weather.forecast_data|safe }}; var TODAY = { 'pt-br': 'hoje', 'es': 'hoy', 'en': 'today', 'it': 'oggi', 'da': 'i dag', 'fr': "aujourd'hui", 'nn': 'i dag', 'sv': 'i dag', 'zh': '今天', 'ja': '今日' }['{{ lang }}']; var WEEK_DAYS = { 'pt-br': ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'], 'es': ['Dom', 'Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab'], 'en': ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 'it': ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'], 'da': ['søn', 'man', 'tir', 'ons', 'tor', 'fre', 'lør'], 'fr': ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'], 'nn': ['sun', 'mån', 'tys', 'ons', 'tor', 'fre', 'lau'], 'sv': ['sön', 'mån', 'tis', 'ons', 'tor', 'fre', 'lör'], 'zh': ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], 'ja': ['日', '月', '火', '水', '木', '金', '土'] }['{{ lang }}']; var SCALE = '{{ scale }}'; function displayTemperature(celsius) { celsius = parseInt(celsius, 10); if (!isFinite(celsius)) { return '-'; } // If the scale is in Fahrenheit we must convert if (SCALE == 'f') { celsius = (celsius * 1.8) + 32; } return Math.round(celsius) + '°'; } function displayForecast(forecast) { var today = Math.floor((Date.now() + (forecast.offset * 60 * 60 * 1000)) / (1000 * 60 * 60 * 24)) * (60 * 60 * 24); var weekday = (new Date()).getDay(); var forecasts = document.querySelectorAll('.forecast-day'); for (var i = 0; i < forecasts.length; i++) { var el = forecasts[i]; var date = today + (3600 * 24 * i); el.className = 'forecast-day ' + forecast.daily[date].icon; el.querySelector('.max').innerHTML = displayTemperature(forecast.daily[date].temperatureMax); el.querySelector('.min').innerHTML = displayTemperature(forecast.daily[date].temperatureMin); if (i === 0) { el.querySelector('.date').innerHTML = TODAY; } else { el.querySelector('.date').innerHTML = WEEK_DAYS[(weekday + i) % 7]; } } } function loadForecast() { var forecast = PRELOADED_FORECAST; try { var cached = JSON.parse(localStorage.getItem('weather:{{ weather.forecast_url }}')); if (cached) { var max_cached = Math.max.apply(window, Object.keys(cached.hourly)); var max_preloaded = Math.max.apply(window, Object.keys(PRELOADED_FORECAST.hourly)); if (max_cached > max_preloaded) { forecast = cached; } } } catch (e) { console.log("Unable to use cached data", e); } try { displayForecast(forecast); } catch (e) { console.error('got exception loading weather', e); } var now = Math.floor((Date.now() + (forecast.offset * 60 * 60 * 1000)) / (1000 * 60 * 60)) * (60 * 60); var hourly = Object.keys(forecast.hourly).sort(); var position = hourly.indexOf('' + now); if (position < 0 || position >= 3) { var request = new XMLHttpRequest(); request.open('GET', '{{ weather.forecast_url }}', true); request.onload = function apiResponse() { if (request.status >= 200 && request.status < 400) { try { var forecast = JSON.parse(request.responseText); displayForecast(forecast); // Try to save it locally as a cache localStorage.setItem('weather:{{ weather.forecast_url }}', request.responseText); } catch (e) { console.error('Unable to update weather', e); } } }; request.send(); } } loadForecast(); ``` -------------------------------- ### Load SDK and Configure App Source: https://github.com/onsigntv/apps/blob/master/samples/rss/uol-rss/app2.html Ensures the SDK is loaded before app configuration. User-configurable variables can be added as described in the provided documentation link. ```html {# Make sure you load the SDK in all apps that use Javascript before starting configuration! #} {{ __loadsdk__ }} {# Check https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md for info on how to add user-configurable variables. #} {{ __config__(name="section", type="choice", label="Categoria:", choices=[ ("world", "UOL - Internacional"), ("sports", "UOL - Esportes"), ("economy", "UOL - Economia"), ("daily", "UOL - Cotidiano"), ("celebrities", "UOL - Celebridades"), ("politics", "UOL - Política"), ("entertainment", "UOL - Entretenimento"), ("television", "UOL - Televisão"), ]) }} {{ __config__(name="duration", type="number", label="Mostrar cada notícia por (segundos)", value=10, js=True) }} {{ __config__(name="animation", type="bool", label="Animação entre as notícias", value=True) }} ``` -------------------------------- ### signage.getBrightness Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Get the current value of screen brightness, from 0 to 100. ```APIDOC ## signage.getBrightness ### Description Get the current value of screen brightness, from `0` to `100`. ### Method `signage.getBrightness()` ### Response #### Success Response - **value** (number) - The current screen brightness level (0-100). ``` -------------------------------- ### Load SDK and Configuration Source: https://github.com/onsigntv/apps/blob/master/samples/weather/weather-forecast-bar/app.html Ensures the SDK is loaded and provides configuration options for location, language, and temperature scale. User-configurable variables are managed via the __config__ function. ```html {# Make sure you load the SDK in all apps that use Javascript before starting configuration! #} {{ __loadsdk__ }} {# Check https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md for info on how to add user-configurable variables. #} {{ __config__(name="weather", type="location", label="Forecast location", help="Type the location of the forecast and choose from the dropdown") }} {{ __config__(name="lang", type="choice", label="Language", choices=["en", "pt-br", "es", "it", "da", "fr", "nn", "sv", "zh", "ja"]) }} {{ __config__(name="weather_format", type="choice", label="Temperature Scale", choices=["fahrenheit", "celsius"]) }} ``` -------------------------------- ### Font Face and Family CSS Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md These examples show the resulting CSS for `@font-face` and `font-family` when a font is selected. ```html ``` -------------------------------- ### signage.ttsStop Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Stops any utterance currently being spoken. If there are enqueued utterances, the oldest one is immediately dequeued and started. ```APIDOC ## `signage.ttsStop()` ### Description Stops any utterance currently being spoken. If there are enqueued utterances, the oldest one is immediately dequeued and started. To completely stop the engine, call `signage.ttsFlush()` before calling `signage.ttsStop()`. ``` -------------------------------- ### Check App Visibility Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Returns a boolean indicating whether the app is currently visible. Apps are often preloaded before playback starts. ```javascript console.log('App is visible?', signage.isVisible()); ``` -------------------------------- ### signage.getVolume Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Get the current hardware volume, from 0 to 100. This method represents the volume of the hardware itself, not the volume your app is configured to use. ```APIDOC ## signage.getVolume ### Description Get the current hardware volume, from `0` to `100`. This method represents the volume of the hardware itself, not the volume your app is configured to use. ### Method `signage.getVolume()` ### Response #### Success Response - **value** (number) - The current hardware volume level (0-100). ``` -------------------------------- ### Get Screen Brightness Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Retrieves the current screen brightness level, ranging from 0 to 100. This value reflects hardware or software configuration. ```javascript signage.getBrightness() ``` -------------------------------- ### Configure Facebook Feed Source: https://github.com/onsigntv/apps/blob/master/samples/social/facebook/app.html Configure the Facebook feed with a name, type, label, and help text. The feed URL must start with 'https://www.facebook.com/'. ```html {{ __config__(name="feed", type="webfeed", label="Facebook page", help="Enter the Facebook page URL you want to show. It should start with https://www.facebook.com/") }} ``` -------------------------------- ### App Configuration with __config__ Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md This Jinja2 template demonstrates how to use the `__config__` function to define various configuration parameters for an application, including text input and color pickers. It shows how to set default values, labels, and optional groups for these configurations. ```html+jinja Sample App With __config___ {{ __config__(name="user_text", type="text", label="Text to be displayed", help="Enter any amount of text here and it will be displayed in a paragraph", ) }} {{ __config__(name="text_color", type="color", value="#8F3627", optional=True, label="Color of the text", optgroup="Style", help="The color the text will be displayed in", ) }} {{ __config__(name="bg_color", type="color", value="#FFFFFF", optional=True, label="Color of the background", optgroup="Style", help="The background color of the text, should have a nice contrast with the color above", ) }}

{{ user_text }}

``` -------------------------------- ### Play Local Audio File Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Plays a local audio file specified by its URI. The URI is typically obtained when rendering the template, for example, from uploaded media. ```html+jinja Example of referencing an audio {{ __loadsdk__ }} ``` -------------------------------- ### Configure and Display User-Submitted Video Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md This snippet demonstrates how to load the SDK, configure a video input type, and embed the video using HTML and Jinja templating. It includes basic JavaScript for handling video playback, such as looping and autoplay. ```html+jinja App with User-Submitted Video {# All apps containing JavaScript, must always load the SDK before configuration! #} {{ __loadsdk__ }} {{ __config__(type="video", name="background_video", label="Background Video") }} ``` -------------------------------- ### Basic CSS Styling Source: https://github.com/onsigntv/apps/blob/master/samples/clock/date-time-fullscreen/app.html Provides essential CSS for setting up the fullscreen layout, box-sizing, and default body styles. It also includes conditional background colors and text colors based on the 'cs' configuration variable. ```css html, body { height: 100%; width: 100%; } body, div, p, img { padding: 0; margin: 0; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } body { background-color: black; {% if cs == 'black' %} background-color: #000000; color: #161616; {% elif cs == 'sandstone' %} background-color: #776c5c; color: #887A66; {% elif cs == 'teal' %} background-color: #007184; color: #1C7E88; {% elif cs == 'olive' %} background-color: #666514; color: #776F22; {% elif cs == 'coral' %} background-color: #ff6346; color: #fe7f68; {% endif %} width: 1280px; font-family: Roboto, Helvetica, Arial, Tahoma, sans-serif; font-weight: bold; overflow: hidden; -webkit-transform-origin: 0 0; transform-origin: 0 0; } ``` -------------------------------- ### Get Player Attribute Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Retrieves the current value of a specified player attribute. Attributes must be pre-created on the platform. Returns null if the attribute does not exist or is not set. ```javascript signage.getPlayerAttribute("name") ``` -------------------------------- ### Example Playback Loops Data Structure Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md This object represents the data structure returned by the signage.playbackLoops() API, detailing the timestamp and information about each active playback loop and its content. ```javascript { "ts": 1702061023000, "loops": [ { "name": "PRIMARY", "start": 1702060000000, "rect": [0, 0, 1920, 1080], "content": { "id": "32UXjbLV", "playId": "#c122", "kind": "TRACKS", "name": "Playlist With Multiple Items", "attrs": { "__tags__": ["playlist-tag"], "Customer Name": "some brand" }, "reason": "LOOP", "start": 1702061023000, "tracks": [ { "name": "__32UXjbLV#0__", "rect": [0, 0, 1920, 1080], "content": { "id": "02Ub7L1x", "playId": "#c123", "kind": "TRACKS", "name": "Campaign With Two Timelines And Audio Track", "attrs": { "__tags__": ["some-tag", "other tag"], "__category__": "Category", "Customer Value": 55 }, "reason": "LOOP", "start": 1702061023000, "tracks": [ { "name": "user-defined track name", "rect": [0, 0, 1920, 700], "content": { "id": "jaUpoPKV", "playId": "#c124", "kind": "IMAGE", "name": "a.png", "attrs": { "__tags__": ["another-tag"] }, "reason": "LOOP", "start": 1702061023000, } }, { "name": "__02Ub7L1x#0__", "rect": [0, 700, 1920, 340], "content": { "id": "32UXZyPl", "playId": "#c124", "kind": "IMAGE", "name": "b.png", "attrs": {}, "reason": "TOUCH", "start": 1702061028000, } }, { "name": "empty named track", "rect": [0, 0, 1920, 1080] } { "name": "__02Ub7L1x#3__", "content": { "id": "jaUpoPKV", "playId": "#c124", "kind": "AUDIO", "name": "misery.mp3", "attrs": {}, "reason": "LOOP", "start": 1702061023000 } } ] } } ] } } ] } ``` -------------------------------- ### Initialize YouTube Player and Handle Events Source: https://github.com/onsigntv/apps/blob/master/samples/social/youtube/app.html This snippet initializes the YouTube IFrame Player API, sets up event listeners for player readiness and state changes, and integrates with the OnSign TV signage bridge for resizing and visibility. ```javascript var isVisible = false; var player = null; var isReady = false; function onYouTubeIframeAPIReady() { // signageLoaded promise resolves when signage methods are available window.signageLoaded.then(function () { player = new YT.Player('player', { height: signage.height(), // signage.height and signage.width will return current dimensions width: signage.width(), videoId: "{{ video_id[0] }}", playerVars: { controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0 }, events: { 'onReady': function onPlayerReady(event) { isReady = true; if (isVisible) { player.setVolume(100); player.playVideo(); } }, 'onStateChange': function onPlayerStateChange(event) { if (event.data === YT.PlayerState.ENDED) { player.playVideo(); } } } }); }); } // The 'sizechanged' event is a debounced version of the 'resize' event. // You can get the current size through object 'event.detail' attributes 'width' and 'height'. // For more info on our custom events, check: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md#signage-events document.addEventListener('sizechanged', function onResize(event) { if (player) { player.setSize(event.detail.width, event.detail.height); } }, false); // signageVisible promise resolves when app is visible // For more info on our promises, check: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md#signage-promises window.signageVisible.then(function() { isVisible = true; if (player && isReady) { player.setVolume(100); player.playVideo(); } }); ``` -------------------------------- ### Advanced HTML Meta Tags with Help, Default Value, and Optional Fields Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md Enhance user configuration with optional attributes like 'help' for instructions, 'value' for initial settings, and 'optional' to make fields non-required. Always check for values in optional fields to prevent configuration failures. ```html+jinja Sample App With Better Instructions

{{ user_text }}

``` -------------------------------- ### Get Region Height Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Retrieves the height of the region where the App is displayed in pixels. Note that the WebView viewport size might differ due to screen density scaling. ```javascript console.log('Height:', signage.height()); ``` -------------------------------- ### Get Region Width Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Retrieves the width of the region where the App is displayed in pixels. Note that the WebView viewport size might differ due to screen density scaling. ```javascript console.log('Width:', signage.width()); ``` -------------------------------- ### Configure RSS/Atom Feed and Display Options Source: https://github.com/onsigntv/apps/blob/master/samples/rss/flexible-news-fullscreen/app.html Sets up the RSS or Atom feed URL, article display duration, transition animation, content display format, and publication date formatting. These configurations control how news content is fetched and presented. ```html {{ __loadsdk__() }} {{ __config__(name="feed", type="webfeed", label="RSS or Atom Feed URL") }} {{ __config__(name="article_time", type="number", label="Show each article for (seconds)", value=10, js=True) }} {{ __config__(name="animation", type="bool", label="Animate article transition", value=False) }} {{ __config__(name="display_content", type="choice", label="Article options", choices=[ ("title_content", "Show title and content"), ("title", "Show title only"), ("content", "Show content only"), ]) }} {{ __config__(name="datetime_format", type="choice", label="Publication date:", choices=[ ("empty", "Don't show"), ("%m/%d/%Y %-I:%M%p", "Show as 12/31/2015 1:00PM"), ("%m/%d/%Y %-H:%M", "Show as 12/31/2015 13:00"), ("%d/%m/%Y %-I:%M%p", "Show as 31/12/2015 1:00PM"), ("%d/%m/%Y %-H:%M", "Show as 31/12/2015 13:00"), ("%Y-%m-%d %-H:%M", "Show as 2015-12-31 13:00"), ]) }} ``` -------------------------------- ### Configure Animation Transition Source: https://github.com/onsigntv/apps/blob/master/samples/social/facebook/app.html Enable or disable animated transitions between posts. This is a boolean configuration. ```html {{ __config__(name="animation", type="bool", label="Enable animated transition between posts", value=True) }} ``` -------------------------------- ### Location App with Weather Forecast Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md This snippet demonstrates how to load the SDK, configure a location app, and display weather forecast data. It uses preloaded data and makes an asynchronous request for updated information. ```html+jinja Location App {# All apps containing JavaScript, must always load the SDK before configuration! #} {{ __loadsdk__ }} {{ __config__(type="location", name="weather", label="Forecast location") }}
Temperature
``` -------------------------------- ### Initiating Text Scroller Animation on Visibility Source: https://github.com/onsigntv/apps/blob/master/samples/text/crawler/app.html Starts the text scroller animation once the application becomes visible on the screen. This ensures the animation only runs when the content is actually displayed to the user. ```javascript // window.signageVisible resolves when the app becomes visible on screen. // For more info on signage promises, check: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md#signagevisible window.signageVisible.then(startAnimation); ``` -------------------------------- ### Initialize and Animate News Items Source: https://github.com/onsigntv/apps/blob/master/samples/rss/flexible-news-fullscreen/app.html Initializes the news item transition and sets up an interval to cycle through items based on the configured article time. This function is called when the app becomes visible. ```javascript window.signageVisible.then(function () { // Sometimes devices have a slightly offset time between their timers // and Javascript timers. A timeout of up to a second fixes this issue. setTimeout(function () { // Enable animation and set interval to display each item. transition(true); setInterval(transition, window.appConfig.article_time * 1000); }, 500); }); ``` -------------------------------- ### Get Hardware Volume Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Retrieves the current hardware volume level, from 0 to 100. This reflects the system's audio output volume, not the app's configured volume. ```javascript signage.getVolume() ``` -------------------------------- ### document.addEventListener("show") Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Listens for the 'show' event, which is fired when the signage becomes visible. Available in all versions. ```APIDOC ## document.addEventListener("show") ### Description Attaches an event listener to the document to detect when the signage becomes visible. ### Method JavaScript Event Listener ### Parameters - **event name** (string) - "show" - **callback function** (function) - The function to execute when the event is fired. ### Response None explicitly documented. ``` -------------------------------- ### Get Geolocation with Promise Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Returns a Promise that resolves with the player's location, determined by GPS, user settings, or IP address. This is the preferred method for obtaining location data for geographic restrictions. ```javascript if (signage && signage.getGeoLocation) { signage.getGeoLocation().then(function(geo) { console.log(geo.src, geo.lat, geo.lng); }); } ``` -------------------------------- ### Get Playback Loops Information Source: https://github.com/onsigntv/apps/blob/master/docs/JSBRIDGE.md Call signage.playbackLoops() after the signage SDK has loaded to retrieve information about currently playing content. The returned Promise resolves with an object containing playback loop details. ```javascript window.signageLoaded.then(function() { signage.playbackLoops().then(function(info) { // Check the sample below to view the structure available on info. }); }); ``` -------------------------------- ### Load YouTube SDK Source: https://github.com/onsigntv/apps/blob/master/samples/social/youtube/app.html Ensure the YouTube SDK is loaded in all JavaScript-enabled applications before initializing the player. This is a prerequisite for video playback functionality. ```html {{ __loadsdk__ }} ``` -------------------------------- ### Media Selection Configuration Source: https://github.com/onsigntv/apps/blob/master/docs/USERCONF.md Configures a media selection input for images and videos. The variable will contain a list of media items, each with a URL, width, height, and optionally duration for videos. ```html+jinja Media App {{ __config__(type="media" name="images" label="Choose your images" help="Set of images to show on screen.") }}
{% for image in images %} {% endfor %}
``` -------------------------------- ### Get Integer from Local Storage Source: https://github.com/onsigntv/apps/blob/master/samples/rss/flexible-news-fullscreen/app.html Retrieves an integer from local storage, appending the current path to the key. Returns 0 if the value is not a valid integer or if an error occurs. Defaults to 0 if the item is not found. ```javascript function getIntFromStorage(name, default_value) { try { return parseInt(localStorage.getItem(name + window.location.pathname.replace('/', '_')), 10) || 0; } catch (e) { return default_value; } } ``` -------------------------------- ### Configure Photo Duration Source: https://github.com/onsigntv/apps/blob/master/samples/social/instagram/app.html Set up the configuration for the duration of each photo in seconds, enabling Javascript. ```html {{ __config__(name="interval", type="number", label="Duration of each photo (seconds)", value=10, js=True) }} ``` -------------------------------- ### Configure Temperature Scale Source: https://github.com/onsigntv/apps/blob/master/samples/weather/small-weather-forecast/app.html Set up a user-configurable variable for the temperature scale. Users can choose between Fahrenheit and Celsius. ```html {{ __config__(name="scale", type="choice", label="Temperature Scale", choices=[ ("f", "Fahrenheit"), ("c", "Celsius") ]) }} ```