Untitled

Anonymous
Plain Text
08/30/2025 9:41 AM
12.6 KB
25
Indexable
Never
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Netflix Integration with PMS + Remote Control</title>
    <style>
        body {
            font-family: sans-serif;
            background: black;
            color: white;
            padding: 20px;
        }
        .button-container {
            margin-top: 20px;
        }
        button {
            padding: 12px 20px;
            font-size: 16px;
            margin-right: 20px;
            background: #333;
            color: white;
            border: 2px solid transparent;
            border-radius: 5px;
        }
        button:focus, .button-focused {
            outline: none;
            border-color: lime;
            background: #555;
        }
        .log-area {
            background: #111;
            padding: 10px;
            font-size: 12px;
            height: 150px;
            overflow-y: auto;
            border-top: 1px solid #444;
            margin-top: 30px;
        }
    </style>
</head>
<body>

    <h2>🎮 Netflix + PMS Integration with Remote</h2>
    <p>Status PMS: <span id="pms-status">--</span></p>
    <p>Status Token: <span id="token-status">--</span></p>

    <div class="button-container">
        <button id="btn-toggle" class="button-focused">🔁 Toggle Dummy PMS</button>
        <button id="btn-launch">🚀 Launch Netflix</button>
    </div>

    <div class="log-area" id="log-area">
        <b>Logs:</b><br>
    </div>

    <script src="js/hcap.js"></script>
    <script src="js/idcap.js"></script>

    <script>
        const NETFLIX_APP_ID = "244115188075859013"; //"netflix"; 
        const NETFLIX_TOKEN = "token_netflix"
        const HOTEL_ID = "LGE";
        const LAUNCHER_VERSION = "1.0";

        let hcap_version = "0.00";
        let dummyPmsStatus = true;
        let pmsEnabled = true;
        let netflixTokenValid = false;

        const buttons = ['btn-toggle', 'btn-launch'];
        let focusIndex = 0;

        function log(msg) {
            const logArea = document.getElementById('log-area');
            const ts = new Date().toLocaleTimeString();
            logArea.innerHTML += `[${ts}] ${msg}<br>`;
            logArea.scrollTop = logArea.scrollHeight;
        }

        function updateFocus() {
            buttons.forEach((id, index) => {
                const btn = document.getElementById(id);
                if (index === focusIndex) {
                    btn.classList.add('button-focused');
                } else {
                    btn.classList.remove('button-focused');
                }
            });
        }

        function togglePMS() {
            dummyPmsStatus = !dummyPmsStatus;
            document.getElementById('pms-status').textContent = dummyPmsStatus ? "ENABLED" : "DISABLED";
            netflixTokenValid = false;
            setupNetflixIntegration();
        }

        function setupNetflixIntegration() {
            log("🔍 Checking HCAP version...");
            hcap.property.getProperty({
                key: "hcap_js_extension_version",
                onSuccess: function (s) {
                    hcap_version = s.value.substring(0, 4);
                    log("HCAP Version: " + hcap_version);
                    if (hcap_version >= "1.24") {
                        checkDummyPMSAndRegisterToken();
                    } else {
                        log("❌ HCAP version too old. Netflix not supported.");
                    }
                },
                onFailure: function (f) {
                    log("❌ Failed to get HCAP version: " + f.errorMessage);
                }
            });
        }

        function checkDummyPMSAndRegisterToken() {
            log("📡 Checking dummy PMS...");
            pmsEnabled = dummyPmsStatus;
            document.getElementById('pms-status').textContent = pmsEnabled ? "ENABLED" : "DISABLED";

            if (!pmsEnabled) {
                log("❌ PMS is not active. Skipping token registration.");
                document.getElementById('token-status').textContent = "NOT REGISTERED";
                return;
            }

            log("✅ PMS is active. Registering Netflix token...");
            log("ℹ️ App ID: " + NETFLIX_APP_ID);
            log("ℹ️ Token: " + NETFLIX_TOKEN);
            // hcap.application.RegisterSIApplicationList({
            //     siAppList: [
            //         { id: NETFLIX_APP_ID, token: NETFLIX_TOKEN }
            //     ],
            //     onSuccess: function () {
            //         log("📤 Token registration request sent.");
            //     },
            //     onFailure: function (f) {
            //         log("❌ Token registration failed: " + f.errorMessage);
            //         document.getElementById('token-status').textContent = "FAILED";
            //     }
            // });

            hcap.application.RegisterSIApplicationList({
                "tokenList" : [{"id":NETFLIX_APP_ID,"token":NETFLIX_TOKEN}],
                "onSuccess" : function(s) {
                    // console.log("onSuccess RegisterSIApplicationList: Netflix registered!");
                    log("📤 Token registration request sent.");
                },
                "onFailure" : function(f) {
                    log("❌ Token registration failed: " + f.errorMessage);
                }
            });

            listAvailableApps();

            // idcap.request( "idcap://application/register" , {
            //     "parameters": {
            //     "tokenList":[
            //             {
            //                 "id":"netflix",
            //                 "token":"example_token=="
            //             }
            //     ]
            //     },
            //     "onSuccess": function () {
            //         console.log("onSuccess :");
            //         log("📤 Token registration request sent.");
            //     },
            //     "onFailure": function (err) {
            //         log("❌ Token registration failed: " + err.errorMessage);
            //         document.getElementById('token-status').textContent = "FAILED";
            //     }
            // });

            document.addEventListener("application_registration_result_received", function (param) {
                if (param.id === NETFLIX_APP_ID) {
                    if (param.tokenResult === true) {
                        netflixTokenValid = true;
                        log("✅ Netflix token registered successfully.");
                        document.getElementById('token-status').textContent = "VALID";
                    } else {
                        log("❌ Netflix token registration failed: " + param.errorMessage);
                        document.getElementById('token-status').textContent = "INVALID";
                    }
                }
            });

            document.addEventListener(
                "idcap::application_registration_result_received",
                function (param) {
                    // {String} param.id - ID of the app that requested by idcap://application/register.
                    // {Boolean} param.tokenResult- true if the app is registered successfully, else false.
                    // {String} param.errorMessage - in case of failure, this message provides the details.

                    log(
                        "Event 'application_registration_result_received' is received.\n" +
                        "App Id = " + param.id + "\nToken result = " + param.tokenResult + "\n"
                    );

                    listAvailableApps();
                },
                false
            );
        }

        function listAvailableApps() {
            log("📋 Listing available applications...");
            // idcap.request( "idcap://application/list" , {
            //     "parameters": {},
            //     "onSuccess": function (s) {
            //         log("onSuccess : list length = " + s.list.length);
            //         for (var i = 0; i < s.list.length; i++) {
            //             log(
            //                 "\nlist[" + i + "].title = " + s.list[i].title +
            //                 "\nlist[" + i + "].appId = " + s.list[i].appId +
            //                 "\nlist[" + i + "].iconPath = " + s.list[i].iconPath +
            //                 "\nlist[" + i + "].version = " + s.list[i].version +
            //                 "\nlist[" + i + "].installed = " + s.list[i].installed +
            //                 "\nlist[" + i + "].type = " + s.list[i].type
            //             );
            //         }
            //     },

            //     "onFailure": function (err) {
            //         console.log("onFailure : errorMessage = " + err.errorMessage);
            //     }
            // });

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

        document.addEventListener("application_registration_result_received", function (param) {
            if (param.id === NETFLIX_APP_ID) {
                if (param.tokenResult === true) {
                    netflixTokenValid = true;
                    log("✅ Netflix token registered successfully.");
                    document.getElementById('token-status').textContent = "VALID";
                } else {
                    log("❌ Netflix token registration failed: " + param.errorMessage);
                    document.getElementById('token-status').textContent = "INVALID";
                }
            }
        });

        function launchNetflix() {
            if (!pmsEnabled) {
                log("❌ Cannot launch Netflix: PMS is not active.");
                return;
            }

            if (!netflixTokenValid) {
                log("❌ Cannot launch Netflix: Token is not valid.");
                return;
            }

            log("🚀 Launching Netflix...");
            const params = JSON.stringify({
                reason: "launcher",
                params: {
                    hotel_id: HOTEL_ID,
                    launcher_version: LAUNCHER_VERSION
                }
            });

            hcap.preloadedApplication.launchPreloadedApplication({
                id: NETFLIX_APP_ID,
                parameters: params,
                onSuccess: function () {
                    log("✅ Netflix launched successfully.");
                },
                onFailure: function (f) {
                    log("❌ Failed to launch Netflix: " + f.errorMessage);
                }
            });

            // idcap.request( "idcap://application/launch" , {
            //     "parameters" : {
            //         "id" : "netflix",
            //         "params" :
            //         {
            //             'params': {'hotel_id':'JHL_HOTEL','launcher_version':'1.0'},
            //             'reason':'hotKey'
            //         },
            //         "noSplash" : false
            //     },
            //     "onSuccess": function () {
            //         log("idcap://application/launch onSuccess");
            //     },
            //     "onFailure": function (err) {
            //         log("onFailure : errorMessage = " + err.errorMessage);
            //     }
            // });
        }

        function handleKeyDown(event) {
            const key = event.keyCode;

            if (key === 37 || key === 38) { // ← atau ↑
                focusIndex = (focusIndex - 1 + buttons.length) % buttons.length;
                updateFocus();
            } else if (key === 39 || key === 40) { // → atau ↓
                focusIndex = (focusIndex + 1) % buttons.length;
                updateFocus();
            } else if (key === 13) { // ENTER / OK
                const current = buttons[focusIndex];
                if (current === 'btn-toggle') togglePMS();
                else if (current === 'btn-launch') launchNetflix();
            }
        }

        window.onload = function () {
            document.getElementById('pms-status').textContent = dummyPmsStatus ? "ENABLED" : "DISABLED";
            updateFocus();
            setupNetflixIntegration();
            document.addEventListener('keydown', handleKeyDown);
        };
    </script>

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