_secret = $Secret; $this->_addressREST = '127.0.0.1'; $this->_accessURL[] = "/index/api/addFFmpegSource"; $this->_accessURL[] = "/index/api/addStreamProxy"; $this->_accessURL[] = "/index/api/close_stream"; $this->_accessURL[] = "/index/api/delFFmepgSource"; $this->_accessURL[] = "/index/api/delStreamProxy"; $this->_accessURL[] = "/index/api/getAllSession"; $this->_accessURL[] = "/index/api/getApiList"; $this->_accessURL[] = "/index/api/getMediaList"; $this->_accessURL[] = "/index/api/getServerConfig"; $this->_accessURL[] = "/index/api/getThreadsLoad"; $this->_accessURL[] = "/index/api/getWorkThreadsLoad"; $this->_accessURL[] = "/index/api/kick_session"; $this->_accessURL[] = "/index/api/restartServer"; $this->_accessURL[] = "/index/api/setServerConfig"; } function __destruct(){ } public function setAccessPointREST( $address ){ $this->_addressREST = $address; } private function composeURL( $idx ){ return "http://" . $this->_addressREST . ':' . $this->_addressPort . $this->_accessURL[$idx] . '?secret=' . $this->_secret; } public function getServerConfig(){ $pack['secret'] = $this->_secret; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $this->composeURL( GET_SERVER_CONFIG_IDX ) ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) ); $output = curl_exec( $ch ); curl_close( $ch ); $AN = json_decode( $output ); echo "Returned Transfer: " . $output ."\n\n"; } public function addStreamProxy( $src, $appname, $strim_id, $rtsp_ena = 0, $rtmp_ena = 0, $hls_ena = 1, $recode_ena = 0, $rtp_type = FETCH_STREAM_UDP, $vhost=ZL_DEFAULT_VHOST ){ $pack['secret'] = $this->_secret; $Params = '&vhost=' . urlencode( $vhost ) . '&app=' . urlencode( $appname ) . '&stream=' . $strim_id . '&url=' . $src . '&enable_rtsp=' . $rtsp_ena . '&enable_rtmp=' . $rtmp_ena . '&enable_hls=' . $hls_ena . '&enable_mp4=' . $recode_ena . '&rtp_type=' . $rtp_type; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $this->composeURL( ADD_STREAM_PROXY_IDX ) . $Params ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) ); $output = curl_exec( $ch ); curl_close( $ch ); $AN = json_decode( $output ); print_r( $AN ); if( $AN->code == 0 ) { $RK = substr( $AN->data->key, strlen( ZL_DEFAULT_VHOST . '/' )); return $RK; }; return ''; } public function delStreamProxy( $key ){ $pack['secret'] = $this->_secret; $Params = '&key=' . urlencode( ZL_DEFAULT_VHOST . '/' . $key ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $this->composeURL( DEL_STREAM_PROXY_IDX ) . $Params ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) ); $output = curl_exec( $ch ); curl_close( $ch ); $AN = json_decode( $output ); print_r( $AN ); if( $AN->code == 0 ){ return $AN->data->flag; }; return false; } public function listMedia(){ $pack['secret'] = $this->_secret; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $this->composeURL( LIST_MEDIA_IDX ) ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $pack ) ); $output = curl_exec( $ch ); curl_close( $ch ); echo "Returned Transfer: " . $output ."\n\n"; } } ?>