mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Can get calls configuration
This commit is contained in:
		
							
								
								
									
										46
									
								
								RestControllers/CallsController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								RestControllers/CallsController.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Calls controller
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class CallsController {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get call configuration
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @url POST /calls/config
 | 
			
		||||
	 */
 | 
			
		||||
	public function getConfig(){
 | 
			
		||||
		user_login_required();
 | 
			
		||||
		return self::CallsConfigToAPI(components()->calls->getConfig());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a CallsConfig object into an API entry
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param $config The config to convert
 | 
			
		||||
	 * @return array Generated API entry
 | 
			
		||||
	 */
 | 
			
		||||
	private static function CallsConfigToAPI(CallsConfig $config) : array {
 | 
			
		||||
 | 
			
		||||
		$data = array();
 | 
			
		||||
 | 
			
		||||
		$data["enabled"] = $config->get_enabled();
 | 
			
		||||
 | 
			
		||||
		//Give full configuration calls are enabled
 | 
			
		||||
		if($config->get_enabled()){
 | 
			
		||||
			$data["signal_server_name"] = $config->get_signal_server_name();
 | 
			
		||||
			$data["signal_server_port"] = $config->get_signal_server_port();
 | 
			
		||||
			$data["stun_server"] = $config->get_stun_server();
 | 
			
		||||
			$data["turn_server"] = $config->get_turn_server();
 | 
			
		||||
			$data["turn_username"] = $config->get_turn_username();
 | 
			
		||||
			$data["turn_password"] = $config->get_turn_password();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $data;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								classes/components/CallsComponent.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								classes/components/CallsComponent.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Calls components
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class CallsComponents {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get and return calls configuration
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @return CallsConfig Calls configuration / invalid object
 | 
			
		||||
	 * if none found (empty config)
 | 
			
		||||
	 */
 | 
			
		||||
	public function getConfig() : CallsConfig {
 | 
			
		||||
 | 
			
		||||
		$callConfig = cs()->config->get("calls");
 | 
			
		||||
 | 
			
		||||
		//If no call config was found
 | 
			
		||||
		if(!$callConfig || !is_array($callConfig) || !$callConfig["enabled"])
 | 
			
		||||
			return new CallsConfig();
 | 
			
		||||
 | 
			
		||||
		$config = new CallsConfig();
 | 
			
		||||
		$config->set_enabled($callConfig["enabled"]);
 | 
			
		||||
		$config->set_signal_server_name($callConfig["signal_server_name"]);
 | 
			
		||||
		$config->set_signal_server_port($callConfig["signal_server_port"]);
 | 
			
		||||
		$config->set_stun_server($callConfig["stun_server"]);
 | 
			
		||||
		$config->set_turn_server($callConfig["turn_server"]);
 | 
			
		||||
		$config->set_turn_username($callConfig["turn_username"]);
 | 
			
		||||
		$config->set_turn_password($callConfig["turn_password"]);
 | 
			
		||||
 | 
			
		||||
		return $config;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Register class
 | 
			
		||||
Components::register("calls", new CallsComponents());
 | 
			
		||||
							
								
								
									
										112
									
								
								classes/models/CallsConfig.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								classes/models/CallsConfig.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,112 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Calls configuration object
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class CallsConfig {
 | 
			
		||||
 | 
			
		||||
	//Private fields
 | 
			
		||||
	private $enabled = false;
 | 
			
		||||
	private $signal_server_name;
 | 
			
		||||
	private $signal_server_port;
 | 
			
		||||
	private $stun_server;
 | 
			
		||||
	private $turn_server;
 | 
			
		||||
	private $turn_username;
 | 
			
		||||
	private $turn_password;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//Set and get enabled state
 | 
			
		||||
	public function set_enabled(bool $enabled){
 | 
			
		||||
		$this->enabled = $enabled;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function get_enabled() : bool {
 | 
			
		||||
		return $this->enabled;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	//Get Set Signal Server name
 | 
			
		||||
	public function set_signal_server_name(string $signal_server_name){
 | 
			
		||||
		$this->signal_server_name = $signal_server_name == "" ? null : $signal_server_name;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function has_signal_server_name() : bool {
 | 
			
		||||
		return $this->signal_server_name != null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function get_signal_server_name() : string {
 | 
			
		||||
		return $this->signal_server_name != null ? $this->signal_server_name : "null";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//Set and get Signal Server Port
 | 
			
		||||
	public function set_signal_server_port(int $signal_server_port){
 | 
			
		||||
		$this->signal_server_port = $signal_server_port;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function has_signal_server_port() : bool {
 | 
			
		||||
		return $this->signal_server_port > 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function get_signal_server_port() : int {
 | 
			
		||||
		return $this->signal_server_port;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//Get and set stun server
 | 
			
		||||
	public function set_stun_server(string $stun_server){
 | 
			
		||||
		$this->stun_server = $stun_server == "" ? null : $stun_server;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function has_stun_server() : bool {
 | 
			
		||||
		return $this->stun_server != null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function get_stun_server() : string {
 | 
			
		||||
		return $this->stun_server != null ? $this->stun_server : "null";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//Get and set turn server
 | 
			
		||||
	public function set_turn_server(string $turn_server){
 | 
			
		||||
		$this->turn_server = $turn_server == "" ? null : $turn_server;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function has_turn_server() : bool {
 | 
			
		||||
		return $this->turn_server != null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function get_turn_server() : string {
 | 
			
		||||
		return $this->turn_server != null ? $this->turn_server : "null";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	//Get and set turn username
 | 
			
		||||
	public function set_turn_username(string $turn_username){
 | 
			
		||||
		$this->turn_username = $turn_username == "" ? null : $turn_username;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function has_turn_username() : bool {
 | 
			
		||||
		return $this->turn_username != null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function get_turn_username() : string {
 | 
			
		||||
		return $this->turn_username != null ? $this->turn_username : "null";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	//Get and set turn password
 | 
			
		||||
	public function set_turn_password(string $turn_password){
 | 
			
		||||
		$this->turn_password = $turn_password == "" ? null : $turn_password;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function has_turn_password() : bool {
 | 
			
		||||
		return $this->turn_password != null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function get_turn_password() : string {
 | 
			
		||||
		return $this->turn_password != null ? $this->turn_password : "null";
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								config/calls.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								config/calls.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Calls configuration file
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Calls through clients are disabled by default.
 | 
			
		||||
 */
 | 
			
		||||
$config->set("calls", false);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Copy the lines of code below to the overwrite.php file
 | 
			
		||||
 * if you would like to enable calls on your instance of
 | 
			
		||||
 * Comunic
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
/*
 | 
			
		||||
$config->set("calls", array(
 | 
			
		||||
	"enabled" => true,
 | 
			
		||||
	"signal_server_name" => "localhost",
 | 
			
		||||
	"signal_server_port" => 8081,
 | 
			
		||||
	"stun_server" => "stun:127.0.0.1:3478",
 | 
			
		||||
	"turn_server" => "turn:127.0.0.1:3478",
 | 
			
		||||
	"turn_username" => "anonymous",
 | 
			
		||||
	"turn_password" => "anonymous"
 | 
			
		||||
));
 | 
			
		||||
*/
 | 
			
		||||
		Reference in New Issue
	
	Block a user