AppLink sample code: applink_demo.html


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--    <script src="js/dapi.js"></script>              -->
        <script src="//localhost/js/dapi.js"></script>
        <script src="js/AppLinkHelper.js"></script>
<!--    <script src="//localhost/js/AppLinkHelper.js"></script>   -->
        <script>window.dapi || document.write('<script src="./dapi.js">\x3C/script>')</script>
        <script type="text/javascript">

            //BEGIN SETUP

            function output(message)
            {
                var output = document.getElementById("output");
                output.innerHTML = output.innerHTML + message + "\n";
            }
            window.onload = function() {


                output("\n" + "------ Begin AppLink Demo -----------" + "\n\n");
                output("After the AppLinkSession has been established, type some text" );
                output("in the Dolby Conference Phone UI Send field. Then hit the Send");
                output("button to transfer the text to the Dolby Voice Hub." + "\n");

                dapi.init(function (ok) {
                    if (!ok) {
                        output("FAILED to init dapi");
                        return;
                    }

                    output("SUCCESS: dapi has been initialized\n");

                    //  Create the dapi.appLinkSession callbacks via AppLinkHelper.
                    //  These are required before communication with the Dolby Conference
                    //  Phone app can be established.

                    AppLinkHelper.session.onConnect = function (succeeded) {
                        if (succeeded) {
                            output("AppLinkSession connected, reachable = " + (dapi.appLinkSession.reachable ? "true" : "false"));
                        } else {
                            output("AppLinkSession failed to connect");
                        }
                    }

                    AppLinkHelper.session.onDisconnect = function () {
                        output("AppLinkSession disconnected");
                    }

                    AppLinkHelper.session.onTextMessageReceived = function (message) {
                        output("AppLinkSession received message: '" + message + "'");

                        txt = "Echo from hub: "; 
                        dapi.appLinkSession.sendTextMessage(txt + message);
                    }

                    AppLinkHelper.session.onReachableChanged = function () {
                        output("AppLinkSession reachable changed to " + (dapi.appLinkSession.reachable ? "true" : "false"));
                    }

                    AppLinkHelper.init("MyTestSession");
                });
            }
            //END SETUP
        </script>

        <style type="text/css">
            html {
                height: 100%;
                width: 100%;
            }
            #output {
                width: 700px;
                height: 350px;
            }
        </style>
        <title>AppLink Demo</title>
    </head>
    <body>
        <h1>AppLink Demo</h1>
        <h3>Session messages</h3>
        <textarea id="output"></textarea>
        <br />

    </body>
</html>