Untitled

 avatar
unknown
plain_text
10 months ago
12 kB
14
Indexable
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Netflix Launcher Sample</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            background-color: #f0f2f5;
            padding: 20px;
            color: #333;
        }
        .container {
            background: #ffffff;
            padding: 2.5rem;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            max-width: 600px;
            width: 100%;
            text-align: center;
        }
        h1 {
            color: #e50914;
            font-size: 2rem;
            margin-bottom: 1rem;
        }
        p {
            font-size: 1rem;
            color: #666;
            margin-bottom: 2rem;
        }
        button {
            background-color: #e50914;
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 8px;
            font-size: 1rem;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        button:hover {
            background-color: #f40612;
        }
        .log-container {
            margin-top: 2rem;
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 8px;
            padding: 1.5rem;
            text-align: left;
            max-height: 300px;
            overflow-y: auto;
        }
        pre {
            white-space: pre-wrap;
            word-wrap: break-word;
            font-family: 'Courier New', Courier, monospace;
            font-size: 0.85rem;
            color: #495057;
        }
        .log-message {
            margin-bottom: 0.5rem;
        }
        .log-success {
            color: #28a745;
        }
        .log-failure {
            color: #dc3545;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Netflix Launcher</h1>
        <p>Click the button below to simulate launching the Netflix application on a webOS TV. The process includes registering an authentication token and passing required parameters, with all steps logged below.</p>
        <button id="launchButton">Launch Netflix</button>
        <div class="log-container">
            <h3>Debug Log</h3>
            <pre id="logOutput"></pre>
        </div>
    </div>
    <script src="js/hcap.js"></script>
    <script src="js/jquery.js"></script>
    <script>

        const NETFLIX_APP_ID = 'netflix'; // Netflix App ID from documentation
        const NETFLIX_TOKEN = "=";
        const HOTEL_ID = "JHL";
        const LAUNCHER_VERSION = "1.0";
        

        // --- Debugging and Logging Utilities ---
        const logOutput = document.getElementById('logOutput');
        function log(message, type = 'info') {
            const time = new Date().toLocaleTimeString();
            const logElement = document.createElement('div');
            logElement.className = `log-message log-${type}`;
            logElement.textContent = `[${time}] ${message}`;
            logOutput.appendChild(logElement);
            logOutput.scrollTop = logOutput.scrollHeight;
            console.log(`[${time}] ${message}`); // Also log to console for development
        }

        // --- Application Logic ---
        document.addEventListener('DOMContentLoaded', () => {
            const launchButton = document.getElementById('launchButton');
            

            // Listener for the registration result
            document.addEventListener("application_registration_result_received", function (param) {
                log('Event "application_registration_result_received" received.');
                if (param.detail.tokenResult) {
                    log(`Token for app ID "${param.detail.id}" successfully registered.`, 'success');
                    
                    // Proceed with launching the application with required parameters
                    const launchParams = {
                        reason: 'launcher',
                        params: {
                            hotel_id: hotelId,
                            launcher_version: launcherVersion
                        }
                    };

                    hcap.preloadedApplication.launchPreloadedApplication({
                        id: netflixAppId,
                        parameters: JSON.stringify(launchParams),
                        onSuccess: function() {
                            // On a real device, this would indicate the app is launching
                            log("onSuccess: Netflix launch API call successful.", 'success');
                        },
                        onFailure: function(f) {
                            // On a real device, this would indicate a launch error
                            log("onFailure: Netflix launch failed. Reason: " + f.errorMessage, 'failure');
                        }
                    });

                } else {
                    log(`Token for app ID "${param.detail.id}" failed to register. Error: ${param.detail.errorMessage}`, 'failure');
                }
            }, false);

            // Handle the button click
            launchButton.addEventListener('click', () => {
                logOutput.innerHTML = ''; // Clear log
                log('Starting Netflix launch process...');

                // Register the Netflix token
                // hcap.application.RegisterSIApplicationList({
                //     tokenList: [{
                //         id: 'netflix',
                //         token: netflixToken
                //     }],
                //     onSuccess: function(s) {
                //         log(`onSuccess: RegisterSIApplicationList API call successful for "${s.id}". Waiting for registration result...`);
                //         // The launch will proceed inside the 'application_registration_result_received' event listener
                //     },
                //     onFailure: function(f) {
                //         log("onFailure: Token registration failed. Reason: " + f.errorMessage, 'failure');
                //     }
                // });
                Launch_app();
            });
        });

        function Launch_app(){
            hcap_js_version = "0.00";
            hcap.property.getProperty ({
                "key" : "hcap_js_extension_version",
                "onSuccess" : function(s) {
                    log("getProperty Success, hcap_js_version : "+s.value);
                    hcap_extension_version = s.value.substring(0,4)

                    if(hcap_extension_version>="1.24"){
                        // We have the latest hcap.js extension so check the television middleware version
                        log("We have the latest hcap.js extension so check the television middleware version");
                        Check_TV_middleware();
                    }else{
                        // We don’t have the latest hcap.js extension so just use old method of launching
                        log("We don’t have the latest hcap.js extension so just use old method of launching");
                    }
                },
                "onFailure" : function(f) {
                    log("getProperty Failed! reason : " + f.errorMessage);
                }
            });
            
        }

        function Check_TV_middleware() {
            hcap_mware_version = "0.00";
            hcap.property.getProperty ({
                "key" : "hcap_middleware_version",
                "onSuccess" : function(s) {
                    log("getProperty Success,: hcap_mware_version "+s.value);
                    hcap_middleware_ver = s.value.substring(0,4)
                    if(hcap_middleware_ver >="1.24"){
                        // We have the latest hcap.js and the TV supports it so register the SI token and use the new method with parameters to launch apps
                        log("We have the latest hcap.js and the TV supports it so register the SI token and use the new method with parameters to launch apps");
                        launchNetflix();
                    }else{
                        // we have the latest extension but the TV doesn’t support it so launch using the old method
                        log("we have the latest extension but the TV doesn’t support it so launch using the old method");
                    }
                },
                "onFailure" : function(f) {
                }
            });
            
        }

        function launchNetflix(){
            log("Registering SI token for Netflix");
            getPreloadedAppList();
            hcap.application.RegisterSIApplicationList({
                tokenList: [{
                    id: NETFLIX_APP_ID,
                    token: NETFLIX_TOKEN
                }],
                onSuccess: function(s) {
                    log(`onSuccess: RegisterSIApplicationList API call successful for "${s.id}". Waiting for registration result...`);
                    // The launch will proceed inside the 'application_registration_result_received' event listener
                    getPreloadedAppList();
                    
                },
                onFailure: function(f) {
                    log("onFailure: Token registration failed. Reason: " + f.errorMessage, 'failure');
                }
            });
            log("Processing register SI token for Netflix");

            document.addEventListener(
            "application_registration_result_received",
                function (param) {
                    // {String} param.id - ID of the app that requested by hcap.application.RegisterSIApplicationList().
                    // {Boolean} param.tokenResult- true if the app is registered successfully, else false.
                    // {String} param.errorMessage - in case of failure, this message provides thedetails.
                    log(
                        "Event 'application_registration_result_received' is received.\n" +
                        "tokenResult = " + param.tokenResult + "\n" +
                        "Error message = " + param.errorMessage + "\n" +
                        "id = " + param.id
                    );

                    hcap.preloadedApplication.launchPreloadedApplication({
                        "id" : NETFLIX_APP_ID,
                        "parameters" : "{'reason':'launcher','params':{'hotel_id':'"+HOTEL_ID+"','launcher_version':'1.0'}}",
                        "onSuccess" : function() {
                            log("onSuccess");
                        },
                        "onFailure" : function(f) {
                            log("onFailure : errorMessage = " + f.errorMessage);
                        }
                    });
                },
                false
            );
        }


        function getPreloadedAppList() {
            hcap.preloadedApplication.getPreloadedApplicationList({
            "onSuccess" : function(s) {
                log("onSuccess : list length = " + s.list.length);
                for (var i = 0; i < s.list.length; i++) {
                    log(
                    "list[" + i + "].id = " + s.list[i].id + ", " +  s.list[i].title
                    );
                }
            },
            "onFailure" : function(f) {
                log("onFailure : errorMessage = " + f.errorMessage);
            }
            });
        }

        function handleKeyDown(event) {
            console.log(event.keyCode)
            switch (event.keyCode) {
                case 13: 
                    window.location.href = "home.html";
                    break;
                default:
                    break;
            }
        }


        $(document).ready(function() {
            $('body').keydown(function(event) {
                Launch_app();
            });
        });

    </script>
</body>
</html>
Editor is loading...
Leave a Comment