Picture of Khalil 5054
Registered 4 years 322 days
Khalil 5054 Thursday, 24 September 2020, 08:59 AM
Check if PbxAppLoginAutomaton was successful from outside of class
Hi,

I have an authentication class that looks like this (attached screenshot).
As you can see in the second method called ReceiveInitialAppLoginResult I check if the authentication was successful but I actually want to do this outside the class. Kinda like this:

$app = new PbxAppLoginAutomaton($pbxdns, new AppPlatform\AppServiceCredentials($pbxapp, $pbxpw));
$app->run();
$status = $app->getIsLoggedIn();

Where I check if $app has authenticated successfully or not, to be able to stop further actions towards the pbx. Is there a way to check this from outside of the class. The documentation says: "As soon as this is completed, we are logged in to the PBX (we could verify the login success by calling $app->getIsLoggedIn()."
http://wiki.innovaphone.com/index.php?title=Reference13r1:Concept_Talking_to_the_v13_Application_Platform_using_PHP#Using_the_RCC_API

But I always end up with bool(false), even if the authentication was successful.

Are there anyone who can help me with this?

Best regards,
Khalil
Screenshot_2020-09-24_at_08.52.48.png

Picture of Khalil 5054
Registered 4 years 322 days
Khalil 5054 Thursday, 24 September 2020, 10:11 AM
Re: Check if PbxAppLoginAutomaton was successful from outside of class
I also wanted to add, is there a way to make sure a call goes through when using the RCCAPI in php, I only get a call id from ReceiveInitialUserCallResult, but it does not tell me if the user answer or if the call didnt go through or anything.


Thanks in advance,
Khalil
Andreas Fink
Moderator Registered 13 years 110 days
Andreas Fink (innovaphone) Thursday, 24 September 2020, 06:00 PM in response to Khalil 5054
1 of 1 users consider this post helpful
Re: Check if PbxAppLoginAutomaton was successful from outside of class
Hello Khalil,

it seems you are replacing the function ReceiveInitialAppLoginResult from websocket.class.php with your own implementation. This is the reason, you have no correct value returned by the function getIsLoggedIn(), cause this part of the original function ReceiveInitialAppLoginResult is never executed:

if ((isset($msg->ok) ? $msg->ok : false) != "true") {
$this->log("login failed", "error");
$response->setMt("AppLoginFailure");
$this->isLoggedIn = false;
} else {
$this->log("successfully logged in", "runtime");
$response->setMt("AppLoginSuccess");
$this->isLoggedIn = true;
}

I would suggest to take a look on the RCC API axample implementation, which uses the PbxAppLoginAutomaton class without overloading its functions:

<?php

/*
* sample code to access PBX RCC API
* (c) innovaphone AG 2020
*/
date_default_timezone_set("Europe/Berlin");

// pbx data, you can override it by placing similar next 4 lines into file my-pbx-data.php
$pbxdns = "sindelfingen.sample.dom";
$pbxpw = "ip411";
$pbxapp = "rccapi";
// end of local pbx data
@include 'my-pbx-data.php';

require_once 'classes/websocket.class.php';
print "<pre>";

// turn on log output
AppPlatform\Log::logon();

// turn off all log messages
AppPlatform\Log::setLogLevel("", "", false);
// turn on log messages of some major categories for all sources
AppPlatform\Log::setLogLevel("", array("error", "runtime"), true);
// if you want to see a message trace, uncomment next line
AppPlatform\Log::setLogLevel("", array("smsg", "debug"), true);
// turn on all catgeories for the calling script
AppPlatform\Log::setLogLevel("script", "", true);


/*
* authenticate towards the PBX as an App service
*/
class PbxAppLoginAutomaton extends AppPlatform\AppLoginAutomaton {

/**
* @var string PBX IP address
*/
protected $pbxUrl;

/**
* @var \WebSocket\WSClient websocket to PBX
*/
protected $pbxWS;

function __construct($pbx, AppPlatform\AppServiceCredentials $cred, $useWS = false) {
$this->pbxUrl = (strpos($pbx, "s://") !== false) ? $pbx :
$this->pbxUrl = ($useWS ? "ws" : "wss") . "://$pbx/PBX0/APPS/websocket";
// create websocket towards the well known PBX URI
$this->pbxWS = new AppPlatform\WSClient("PBXWS", $this->pbxUrl);
parent::__construct($this->pbxWS, $cred);
}

}

/*
use the PbxAdminApi at PBX sindelfingen.sample.dom
There must be an App object with name "pbxadminapi" and password "ip411"
it needs to have the "Admin" and "PbxApi" flags set
*/

$app = new PbxAppLoginAutomaton($pbxdns, new AppPlatform\AppServiceCredentials($pbxapp, $pbxpw));
$app->run();

echo("getIsLoggedIn(): ");
var_dump($app->getIsLoggedIn());


// the class utilizes the PbxApi
class PbxApiSample extends AppPlatform\FinitStateAutomaton {

public function ReceiveInitialStart(\AppPlatform\Message $msg) {
$this->sendMessage(new AppPlatform\Message("Initialize", "api", "RCC"));
}

public function ReceiveInitialUserInfo(\AppPlatform\Message $msg) {
$this->log("UserInfo");
}

public function ReceiveInitialInitializeResult(\AppPlatform\Message $msg) {
$this->log("InitializeResult: " . $msg->api);
$this->sendMessage(new AppPlatform\Message("Devices", "api", "RCC","cn","test"));
}

public function ReceiveInitialDevicesResult(\AppPlatform\Message $msg) {
foreach( $msg->devices as $device) $hws[] = $device->hw;
$this->log("DevicesResult: " . implode($hws));
$this->sendMessage(new AppPlatform\Message("UserInitialize", "api", "RCC","cn","test", "hw", $hws[0]));
}

public function ReceiveInitialUserInitializeResult(\AppPlatform\Message $msg) {
$this->log("UserInitializeResult userid: " . $msg->user);
$userid = $msg->user;
//var_dump($msg);
//return "Dead";
$this->sendMessage(new AppPlatform\Message("UserCall", "api", "RCC","user", $msg->user, "e164", "91234"));
}

public function ReceiveInitialUserCallResult(\AppPlatform\Message $msg) {
$this->log("UserCallResult callid: " . $msg->call);
//$userid = $msg->user;
//var_dump($msg);
//return "Dead";
//$this->sendMessage(new AppPlatform\Message("UserCall", "api", "RCC","cn","Andreas (Trainer)", "hw", $hws[0]));
//return "Dead";
}

public function ReceiveInitialCallInfo(\AppPlatform\Message $msg) {
$this->log("CallInfo");
var_dump($msg);
if($msg->msg == 'r-conn' ) return "Dead";
}

}

AppPlatform\Log::setLogLevel("", "debug", true);
$pbxapi = new PbxApiSample($app->getWs(), "PBX");
$pbxapi->run();
?>

In this example is also a function ReceiveInitialCallInfo is implemented to log the call states infos, like connected etc.


Best Regards
Andreas Fink
Picture of Khalil 5054
Registered 4 years 322 days
Khalil 5054 Friday, 2 October 2020, 04:04 PM
Re: Check if PbxAppLoginAutomaton was successful from outside of class
Thanks Andreas Fink, this helped a lot.

Is it possble to check from the outside the class if the call connected, is it possible to return something if the r-conn is recieved or is there a function to call on the class objected created when the rccapi application is initiated?


Best Regards,
Khalil
← You can define your color theme preference here