From 3786c5c4e9d806ed0880848566153d4ca31bcfff Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 22 Jan 2019 17:39:45 +0100 Subject: [PATCH] Can get calls configuration --- RestControllers/CallsController.php | 46 +++++++++++ classes/components/CallsComponent.php | 39 +++++++++ classes/models/CallsConfig.php | 112 ++++++++++++++++++++++++++ config/calls.php | 29 +++++++ 4 files changed, 226 insertions(+) create mode 100644 RestControllers/CallsController.php create mode 100644 classes/components/CallsComponent.php create mode 100644 classes/models/CallsConfig.php create mode 100644 config/calls.php diff --git a/RestControllers/CallsController.php b/RestControllers/CallsController.php new file mode 100644 index 0000000..8207d85 --- /dev/null +++ b/RestControllers/CallsController.php @@ -0,0 +1,46 @@ +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; + } +} \ No newline at end of file diff --git a/classes/components/CallsComponent.php b/classes/components/CallsComponent.php new file mode 100644 index 0000000..6ea9005 --- /dev/null +++ b/classes/components/CallsComponent.php @@ -0,0 +1,39 @@ +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()); \ No newline at end of file diff --git a/classes/models/CallsConfig.php b/classes/models/CallsConfig.php new file mode 100644 index 0000000..ac16c81 --- /dev/null +++ b/classes/models/CallsConfig.php @@ -0,0 +1,112 @@ +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"; + } +} \ No newline at end of file diff --git a/config/calls.php b/config/calls.php new file mode 100644 index 0000000..6cf065b --- /dev/null +++ b/config/calls.php @@ -0,0 +1,29 @@ +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" +)); +*/ \ No newline at end of file