<?php
session_start();
require '../../conf/url_page.php';

$server_ip = $Public_ip;
$name = $_SESSION['user'];
$user = $name;
$pass = $_SESSION['pass'];
$server = $server_ip;
$domain = $server_ip;
$sokect ='8089';
$path ='/ws';


// echo "The server's IP address is: " . $server_ip;
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">

        <title>Browser Phone</title>
        <meta name="description" content="Browser Phone is a fully featured browser based WebRTC SIP phone for Asterisk. Designed to work with Asterisk PBX. It will connect to Asterisk PBX via web socket, and register an extension.  Calls are made between contacts, and a full call detail is saved. Audio and Video Calls can be recorded locally.">

        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>

        <!-- Progressive Web App (PWA) -->
        <meta name="HandheldFriendly" content="true">
        <meta name="format-detection" content="telephone=no"/>
        <meta name="mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-capable" content="yes"/>
        <meta name="theme-color" media="(prefers-color-scheme: light)" content="#f6f6f6">
        <meta name="theme-color" media="(prefers-color-scheme: dark)"  content="#292929">
        <link rel="apple-touch-icon" type="image/png" href="icons/512.png">
        <link rel="manifest" type="application/manifest+json" href="manifest.json">
        <script type="text/javascript">
            // If you don't want to use a service worker, you can just take this code out.
            if ('serviceWorker' in navigator) {
                navigator.serviceWorker.register("sw.js").catch(function(error) {
                    console.error('Service Worker Error', error);
                });
            } else {
                console.warn("Cannot make use of ServiceWorker");
            }
        </script>

        <!-- Cache -->
        <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
        <meta http-equiv="Expires" content="0"/>

        <link rel="icon" type="image/x-icon" href="favicon.ico">

        <!-- Styles -->
        <link rel="stylesheet" type="text/css" href="https://dtd6jl0d42sve.cloudfront.net/lib/Normalize/normalize-v8.0.1.css"/>
        <link rel="stylesheet preload prefetch" type="text/css" as="style" href="https://dtd6jl0d42sve.cloudfront.net/lib/fonts/font_roboto/roboto.css"/>
        <link rel="stylesheet preload prefetch" type="text/css" as="style" href="https://dtd6jl0d42sve.cloudfront.net/lib/fonts/font_awesome/css/font-awesome.min.css"/>
        <link rel="stylesheet" type="text/css" href="https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-ui-1.13.2.min.css"/>
        <link rel="stylesheet" type="text/css" href="https://dtd6jl0d42sve.cloudfront.net/lib/Croppie/Croppie-2.6.4/croppie.css"/>
        <link rel="stylesheet" type="text/css" href="phone.css"/>

        <!-- Provisioning -->
        <script type="text/javascript">
            // Provision runtime options can go here.
            function getPhoneOptions() {
        let urlParams = new URLSearchParams(window.location.search);
        let DND = urlParams.has("DND") ? urlParams.get("DND") : null;

        let phoneOptions = {
            loadAlternateLang: false,
            SingleInstance: true,
            VoiceMailSubscribe: false,
            RegisterExpires: 30,
            EnableVideoCalling: false,
            Notifications: true,
            DoNotDisturbEnabled: DND ? DND === 'true' : false,
            profileName: "<?= $name ?>",
            wssServer: "<?= $server ?>",
            WebSocketPort: "<?= $sokect ?>",
            ServerPath: "<?= $path ?>",
            SipDomain: "<?= $domain ?>",
            SipUsername: "<?= $user ?>",
            SipPassword: "<?= $pass ?>"
            
        };

        console.log("Phone Options: ", phoneOptions); // For debugging
        return phoneOptions;
    }

    // Call the function to get the phone options
    var phoneOptions = getPhoneOptions();

            // Occurs after the language file is loaded
            document.addEventListener("language_pack_loaded", function(lang){
                console.log("web_hook_on_language_pack_loaded", lang);
            });
            var web_hook_on_language_pack_loaded = function(lang){
                // console.log("web_hook_on_language_pack_loaded", lang);
            }
            // Occurs After the Language Packs load, at the start of the InitUi() function 
            var web_hook_on_before_init = function(options){
                // console.log("web_hook_on_before_init", options);
            }
            // Occurs at the end of the InitUi() function, before the User Agent is created.
            // In order to follow events after the User Agent is created, use the register
            // and transport events below. 
            var web_hook_on_init = function(){
                // console.log("web_hook_on_init");
            }
            // Occurs after the UserAgent is created.
            // Note: The registration state would not be know yet, but the registration may have been sent.
            var web_hook_on_userAgent_created = function(ua){
                // console.log("web_hook_on_userAgent_created", ua);
            }
            // Connection and Calling Events
            var web_hook_on_transportError = function(t, ua){
                // console.log("web_hook_on_transportError",t, ua);
            }
            var web_hook_on_register = function(ua){
                // console.log("web_hook_on_register", ua);
            }
            var web_hook_on_registrationFailed = function(e){
                // console.log("web_hook_on_registrationFailed", e);
            }
            var web_hook_on_unregistered = function(){
                // console.log("web_hook_on_unregistered");
            }
            var web_hook_on_invite = function(session){
                // console.log("web_hook_on_invite", session);
            }
            var web_hook_on_message = function(message){
                // console.log("web_hook_on_message", message);
            }
            var web_hook_on_modify = function(action, session){
                // console.log("web_hook_on_modify", action, session);
            }
            var web_hook_on_dtmf = function(item, session){
                // console.log("web_hook_on_dtmf", item, session);
            }
            var web_hook_on_terminate = function(session){
                // console.log("web_hook_on_terminate", session);
            }
            var web_hook_on_notify = function(ContentType, buddyObj, notify){
                // console.log("web_hook_on_notify", ContentType, buddyObj, notify);
            }
            var web_hook_on_self_notify = function(ContentType, notify){
                // console.log("web_hook_on_self_notify", ContentType, notify);
            }

            // UI events
            var web_hook_dial_out = function(event){
                // console.log("web_hook_dial_out", event);
            }
            var web_hook_on_add_buddy = function(event){
                // console.log("web_hook_on_add_buddy", event);
            }
            var web_hook_on_edit_buddy = function(buddyJson){
                // console.log("web_hook_on_edit_buddy", buddyJson);
            }            
            var web_hook_on_config_menu = function(event){
                // console.log("web_hook_on_config_menu", event);
            }
            var web_hook_on_messages_waiting = function(newMsg, oldMsg, ugentNew, ugentOld){
                // console.log("web_hook_on_messages_waiting", newMsg, oldMsg, ugentNew, ugentOld);
            }
            var web_hook_on_missed_notify = function(missed){
                // console.log("web_hook_on_missed_notify", missed);
            }
            var web_hook_on_expand_video_area = function(lineNum){
                // console.log("web_hook_on_expand_video_area", lineNum);
            }
            var web_hook_on_restore_video_area = function(lineNum){
                // console.log("web_hook_on_restore_video_area", lineNum);
            }
            var web_hook_on_message_action = function(buddy, obj){
                // console.log("web_hook_on_message_action", buddy, obj);
            }
            var web_hook_disable_dnd = function(){
                // console.log("web_hook_disable_dnd");
            }
            var web_hook_enable_dnd = function(){
                // console.log("web_hook_enable_dnd");
            }
            var web_hook_on_edit_media = function(lineNum, obj){
                // console.log("web_hook_on_edit_media", lineNum, obj);
            }
            var web_hook_sort_and_filter = function(event){
                // console.log("web_hook_sort_and_filter", event);
            }

        </script>
    </head>

    <body>
        <!-- Loading Animation -->
        <div class=loading>
            <span class="fa fa-circle-o-notch fa-spin"></span>
        </div>

        <!-- The Phone -->
        <div id=Phone></div>
    </body>

    <!-- Loadable Scripts -->
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-3.6.1.min.js"></script>
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery-ui-1.13.2.min.js"></script>
    <script type="text/javascript" src="phone.js"></script>

    <!-- Deferred Scripts -->
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/jquery/jquery.md5-min.js" defer="true"></script>
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/Chart/Chart.bundle-2.7.2.min.js" defer="true"></script>
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/SipJS/sip-0.20.0.min.js" defer="true"></script>
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/FabricJS/fabric-2.4.6.min.js" defer="true"></script>
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/Moment/moment-with-locales-2.24.0.min.js" defer="true"></script>
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/Croppie/Croppie-2.6.4/croppie.min.js" defer="true"></script>
    <script type="text/javascript" src="https://dtd6jl0d42sve.cloudfront.net/lib/XMPP/strophe-1.4.1.umd.min.js" defer="true"></script>

</html>