Ajout du service AirMedia

This commit is contained in:
alphayax 2016-05-14 15:54:59 +02:00
parent 3853017ca0
commit 75654ecc07
10 changed files with 320 additions and 3 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@
/vendor/*
# Project files
/exemple/AirMedia/app_token
/exemple/config/app_token
/exemple/download/app_token
/app_token

View File

@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
Freebox PHP API : A PHP implementation of the freebox v3 APIU
Copyright (C) 2016 Yann Ponzoni
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -52,12 +52,13 @@ $System = new \alphayax\freebox\api\v3\services\config\System( $App);
/** @var \alphayax\freebox\api\v3\models\SystemConfig $SystemConfig */
$SystemConfig = $System->getConfiguration();
\alphayax\utils\cli\IO::stdout( 'Uptime : '. $SystemConfig->uptime);
\alphayax\utils\cli\IO::stdout( 'Uptime : '. $SystemConfig->getUptime());
```
## Exemples
Les exemples sont disponibles dans le repertoire `exemple`. Ils sont classés par services :
- `AirMedia` : Exemple de lancement d'une video sur le Freebox Player
- `config`
- `check_dns` : Un script pour récuperer la configuration courrante du DHCP
- `DMZ` : Récupération de la confiugration de votre zone démilitarisée

View File

@ -0,0 +1,29 @@
<?php
/// Require Composer AutoLoader
require_once '../../vendor/autoload.php';
/// Define our application
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example_airmedia', 'Freebox PHP API Example (AirMedia)', '1.0.0');
$App->authorize();
$App->openSession();
$AirMediaService = new \alphayax\freebox\api\v3\services\AirMedia\AirMedia( $App);
// AirMedia Config
$Configuration = $AirMediaService->getConfiguration();
var_dump( $Configuration);
// AirMedia Receivers
$Receivers = $AirMediaService->getAirMediaReceivers();
var_dump( $Receivers);
// AirMedia Request
$Request = new \alphayax\freebox\api\v3\models\AirMedia\AirMediaReceiverRequest();
$Request->setAction( \alphayax\freebox\api\v3\symbols\AirMedia\Action::START);
$Request->setMediaType( \alphayax\freebox\api\v3\symbols\AirMedia\MediaType::VIDEO);
$Request->setMedia( 'http://anon.nasa-global.edgesuite.net/HD_downloads/GRAIL_launch_480.mov');
$Status = $AirMediaService->sendRequestToAirMediaReceiver( 'Freebox Player', $Request);
var_dump( $Status);

View File

@ -0,0 +1,38 @@
<?php
namespace alphayax\freebox\api\v3\models\AirMedia;
use alphayax\freebox\api\v3\Model;
/**
* Class AirMediaConfig
* @package alphayax\freebox\api\v3\models
*/
class AirMediaConfig extends Model {
/** @var bool Enable/Disable the airmedia server */
protected $enabled;
/** @var string (Write-only) : If not empty, the client will have to enter a password to be able to use this airmedia server */
protected $password;
/**
* @return boolean
*/
public function isEnabled(){
return $this->enabled;
}
/**
* @param boolean $enabled
*/
public function setEnabled( $enabled){
$this->enabled = $enabled;
}
/**
* @param string $password
*/
public function setPassword( $password){
$this->password = $password;
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace alphayax\freebox\api\v3\models\AirMedia;
use alphayax\freebox\api\v3\Model;
/**
* Class AirMediaReceiver
* @package alphayax\freebox\api\v3\models
*/
class AirMediaReceiver extends Model {
/** @var string (Read-only) : AirMedia name */
protected $name;
/** @var bool (Read-only) : Is set to true the receiver is protected by a password */
protected $password_protected;
/**
* @var array (Read-only) : List of receiver capabilities from the following list
* photo : can display photos
* audio : can play audio files
* video : can play video files
* screen : can display remote screen
*/
protected $capabilities = [];
/**
* @return string
*/
public function getName(){
return $this->name;
}
/**
* @return boolean
*/
public function isPasswordProtected(){
return $this->password_protected;
}
/**
* @return array
*/
public function getCapabilities(){
return $this->capabilities;
}
}

View File

@ -0,0 +1,110 @@
<?php
namespace alphayax\freebox\api\v3\models\AirMedia;
use alphayax\freebox\api\v3\Model;
/**
* Class AirMediaReceiver
* @package alphayax\freebox\api\v3\models
*/
class AirMediaReceiverRequest extends Model {
/**
* @var string
* @see alphayax\freebox\api\v3\symbols\AirMedia\Action
*/
protected $action;
/**
* @var string
* @see alphayax\freebox\api\v3\symbols\AirMedia\MediaType
*/
protected $media_type;
/** @var string : Optional receiver password */
protected $password;
/**
* @var int
* Start position for a video.
* The start position is expressed in percent * 1000, for instance 50000 means 50% of the video
*/
protected $position = 0;
/**
* @var string : The media to play
* For video media, you have to specify the media URL, for instance http://anon.nasa-global.edgesuite.net/HD_downloads/GRAIL_launch_480.mov
* For photo media, you have to specify the file path on the Freebox Server (base64 encoded as returned in fs/ls call), for instance L0Rpc3F1ZSBkdXIvUGhvdG9zL1JvY2tldHMvRFNDXzM0OTEuanBn
*/
protected $media;
/**
* @return string
*/
public function getAction(){
return $this->action;
}
/**
* @param string $action
*/
public function setAction( $action){
$this->action = $action;
}
/**
* @return string
*/
public function getMediaType(){
return $this->media_type;
}
/**
* @param string $media_type
*/
public function setMediaType( $media_type){
$this->media_type = $media_type;
}
/**
* @return string
*/
public function getPassword(){
return $this->password;
}
/**
* @param string $password
*/
public function setPassword( $password){
$this->password = $password;
}
/**
* @return int
*/
public function getPosition(){
return $this->position;
}
/**
* @param int $position
*/
public function setPosition( $position){
$this->position = $position;
}
/**
* @return string
*/
public function getMedia(){
return $this->media;
}
/**
* @param string $media
*/
public function setMedia( $media){
$this->media = $media;
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace alphayax\freebox\api\v3\services\AirMedia;
use alphayax\freebox\api\v3\models\AirMedia\AirMediaConfig;
use alphayax\freebox\api\v3\models\AirMedia\AirMediaReceiver;
use alphayax\freebox\api\v3\models\AirMedia\AirMediaReceiverRequest;
use alphayax\freebox\api\v3\Service;
/**
* Class AirMedia
* @package alphayax\freebox\api\v3\services\AirMedia
*/
class AirMedia extends Service {
const API_AIRMEDIA_CONFIG = '/api/v3/airmedia/config/';
const API_AIRMEDIA_RECEIVERS = '/api/v3/airmedia/receivers/';
/**
* @throws \Exception
* @return AirMediaConfig
*/
public function getConfiguration(){
$rest = $this->getAuthService( self::API_AIRMEDIA_CONFIG);
$rest->GET();
return new AirMediaConfig( $rest->getCurlResponse()['result']);
}
/**
* @param AirMediaConfig $new_AirMediaConfig
* @return AirMediaConfig
* @throws \Exception
*/
public function setConfiguration( AirMediaConfig $new_AirMediaConfig){
$rest = $this->getAuthService( self::API_AIRMEDIA_CONFIG);
$rest->PUT( $new_AirMediaConfig->toArray());
return new AirMediaConfig( $rest->getCurlResponse()['result']);
}
/**
* Get the list of AirMediaReceiver connected to the Freebox Server
* @return AirMediaReceiver[]
*/
public function getAirMediaReceivers(){
$rest = $this->getAuthService( self::API_AIRMEDIA_RECEIVERS);
$rest->GET();
$AirMediaReceiver_xs = $rest->getCurlResponse()['result'];
$AirMediaReceivers = [];
foreach( $AirMediaReceiver_xs as $airMediaReceiver_x) {
$AirMediaReceivers[] = new AirMediaReceiver( $airMediaReceiver_x);
}
return $AirMediaReceivers;
}
/**
* @param string $AirMediaReceiver_name
* @param AirMediaReceiverRequest $AirMediaReceiverRequest
* @return bool
*/
public function sendRequestToAirMediaReceiver( $AirMediaReceiver_name, AirMediaReceiverRequest $AirMediaReceiverRequest){
$rest = $this->getAuthService( self::API_AIRMEDIA_RECEIVERS . $AirMediaReceiver_name . DIRECTORY_SEPARATOR);
$rest->POST( $AirMediaReceiverRequest->toArray());
return $rest->getCurlResponse()['success'];
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace alphayax\freebox\api\v3\symbols\AirMedia;
/**
* Symbol Action
* @package alphayax\freebox\api\v3\symbols\AirMedia
*/
interface Action {
const START = 'start';
const STOP = 'stop';
}

View File

@ -0,0 +1,11 @@
<?php
namespace alphayax\freebox\api\v3\symbols\AirMedia;
/**
* Symbol MediaType
* @package alphayax\freebox\api\v3\symbols\AirMedia
*/
interface MediaType {
const PHOTO = 'photo';
const VIDEO = 'video';
}