<?php

class WebRTCController extends Controller
{
    public $layout = 'webRTC';

    public function actionVertoConfig()
    {
        $vertoConfigs = array(
            
            "name" => "",
            "email" => "",
            "login" => "",
            "password" => "",
            "callerid" => "",            
            "hostname" => "",
            "wsURL" => "",
            "autologin" => "true"
        );

        $user = app()->user->getSudoUserInstance();
        
        if ($user) {
            $vertoConfigs["name"] = getFormatedNameToUser($user, "sudoBar");
            $vertoConfigs["email"] = $user->email;
            $vertoConfigs["callerid"] = $user->extension;
        }
        
        $sipaccount = SipAccounts::model()->findByAttributes(array("authname" => $user->extension));
        if ($sipaccount) {
            
            $vertoConfigs["login"] = $sipaccount->authname;
            $vertoConfigs["password"] = $sipaccount->secret;
        }
        $vertoConfigs["hostname"] = cfg("SIP_HOST");
        $vertoConfigs["wsURL"] = cfg("WEBRTC_WSS_URL");
        
        echo json_encode($vertoConfigs);
    }
}