I am facing issue when i try to broadcast my video in
When I use 'startVideo' its working fine for me.
But my 'connectVideo' giving me issue, I have pasted code below. I have attached error screenshot also.
In my first function 'startVideo' I wrote code to start video its taking my webcam video, through second function 'connectVideo' i just want share/broadcast my video with my user.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use OpenTok\OpenTok;
use OpenTok\MediaMode;
use OpenTok\ArchiveMode;
use OpenTok\Role;
use OpenTok\Session;
use OpenTok\Broadcast;
use OpenTok\Layout;
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('welcome_message');
}
public function startVideo()
{
$opentok = new OpenTok($this->config->item('opentok_key'), $this->config->item('opentok_secret'));
$sessionOptions = array(
'archiveMode' => ArchiveMode::ALWAYS,
'mediaMode' => MediaMode::ROUTED
);
$session = $opentok->createSession($sessionOptions);
$iSessionId = $session->getSessionId();
date_default_timezone_set('Asia/Kolkata');
$created_date = date("Y-m-d H:i:s");
$data = array(
'apiKey' => $this->config->item('opentok_key'),
'sessionId' => $iSessionId,
'token' => $session->generateToken(),
'created_date' => $created_date
);
$archiveOptions = array(
'name' => 'Important Presentation', // default: null
'hasAudio' => true, // default: true
'hasVideo' => true, // default: true
// 'outputMode' => OutputMode::COMPOSED, // default: OutputMode::COMPOSED
'resolution' => '1280x720' // default: '640x480'
);
$this->load->view('video_11', $data);
}
public function connectVideo() // connect to a session
{
$opentok = new OpenTok($this->config->item('opentok_key'), $this->config->item('opentok_secret'));
$session = $opentok->createSession();
$sessionOptions = array(
'archiveMode' => ArchiveMode::ALWAYS,
'mediaMode' => MediaMode::ROUTED
);
$session = $opentok->createSession($sessionOptions);
$sessionId = $session->getSessionId();
$options = array(
'layout' => Layout::getBestFit(),
'maxDuration' => 5400,
'resolution' => '1280x720'
);
$broadcast = $opentok->startBroadcast($sessionId, $options);
// Store the broadcast ID in the database for later use
$broadcastId = $broadcast->id;
$token = 'T1==T1==cGFydG5lcl9pZD00NjQ5MTcwMiZzaWc9Y2MxYzkxYzNmYTkzNmNiNmQ0NDZiNWEzNzVhYjExYTliYTZkOTdlYzpzZXNzaW9uX2lkPTFfTVg0ME5qUTVNVGN3TW41LU1UWXhOVE00TXpJMU16WXdPWDVIWjB0WVp6SlJWRlJhVUV4c2FrczVOa0ZOZGk5SUwwOS1RWDQmY3JlYXRlX3RpbWU9MTYxNTM4MzI1MyZyb2xlPXB1Ymxpc2hlciZub25jZT0xNjE1MzgzMjUzLjY5ODUxOTY3MzAxNjU4';
$data = array(
'apiKey' => $this->config->item('opentok_key'),
'sessionId' => $session,
'token' => $token
);
$this->load->view('video_22', $data);
}
}
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/Q1qBY.png
Related
hello please i need simple composer script so i can use it on server that have my raw php files and load them from php file on anothere server can any one help please ?
i mean when i upload autoloader.php on my server the code look like this and it load the php files from the server that have el coposer script
require_once(__DIR__ . DIRECTORY_SEPARATOR. "Autoloader.php");
class Config
{
private $server_url, $username, $api_key, $telegram_id, $telegram_bot, $captcha_website, $captcha_secret;
private $authenticator, $request, $message;
public function __construct($server_url, $username, $api_key, $telegram_id, $telegram_bot, $captcha_website, $captcha_secret){
if (strpos($server_url, "raw.githubusercontent.com", 0) !== false)
$this->$server_url = \Assets\Generic::fetchGithubContent($server_url);
$autoloader = new Autoloader();
$logger = new \Assets\Logger();
$session = new \Assets\Session();
$this->request = new \Assets\RequestHandler();
$this->server_url = $server_url;
$this->username = $username;
$this->api_key = $api_key;
$this->telegram_id = $telegram_id;
$this->telegram_bot = $telegram_bot;
$this->captcha_website = $captcha_website;
$this->captcha_secret = $captcha_secret;
$this->message = $this->createMessage();
$this->authenticator = new \Assets\Authenticator($server_url, $this->message);
$this->run();
}
private function run(){
if (!$this->authenticator->authenticate()){
http_response_code(403);
echo "Un-authorized access. please login to continue";
exit(0);
}
if ($this->authenticator->isBlocked()){
http_response_code(302);
header("Location: https://www.google.com");
exit(0);
}
$this->request->handle($this->server_url, $this->message);
}
private function createMessage(){
return array(
'customer_info' => array(
'api_key' => $this->api_key,
'chat_id' => $this->telegram_id,
'telegram_bot' => $this->telegram_bot,
'captcha_secret_key' => $this->captcha_secret,
'captcha_website_key' => $this->captcha_website,
'username' => $this->username,
),
'client_info' => array(
'ip' => \Assets\Generic::getIp(),
'useragent' => $_SERVER['HTTP_USER_AGENT'],
'method' => $_SERVER['REQUEST_METHOD'],
'request_time' => time(),
'inputs' => array(
'get' => $_GET,
'post' => $_POST
)
)
);
}
}
$server_url = "https://blabla/bla.php";
$api_key = "cdb6d872-0529-4358-ba29-bfae71cf3ed0";
$username = "blanvla";
$telegram_id = "963065016";
$telegram_bot = "5371625949:AAHjcf";
$captcha_website = "RecaptchaV2-Site Key";
$captcha_secret = "RecaptchaV2-Secret Key";
$config = new Config($server_url, $username, $api_key, $telegram_id, $telegram_bot, $captcha_website, $captcha_secret);
First download that script with curl or wget, then add it to your composer.json:
curl 'https://example.com/public/MyClass.php' > ./vendor/customScripts/MyClass.php
// composer.json
{
"autoload": [
"classmap": [
"customScripts/MyClass.php"
]
],
}
I am having problems when trying the API that I made. When I tested it in Postman, it appeared false, even though my username and password were correct. Can you identify the problem with my code?
I really appreciate your help.
Auth_admin.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Auth_admin extends REST_Controller
{
public function signin_post()
{
$this->load->model('model_admin', 'admin');
$params = array(
'username' => $this->post('username'),
'password' => md5($this->post('password'))
);
$result = $this->admin->admin_check($params);
if ($result){
if ($result->level == "admin"){
$response = array(
"status" => true,
"message" => "Authentication seccessfully",
"auth" => array(
"username" => $result->username
)
);
$this->set_response($response, REST_Controller::HTTP_OK);
}else{
$response = array(
"status" => false,
"message" => "This features does'nt exist for your Account"
);
$this->set_response($response, REST_Controller::HTTP_OK);
}
}
}
}
Model_admin.php
<?php
class Model_admin extends CI_Model
{
var $tablename;
public function __construct()
{
parent::__construct();
$this->tablename = "m_admin";
}
public function admin_check($data = array())
{
$params = array(
'username' => $data['username'],
'password' => $data['password'],
);
$this->db->where($params);
$query = $this->db->get($this->tablename);
return $query->row();
}
}
You have to pass function name after the controller name.
Like your path: http://192.168.122.1/project_name/auth_admin/signin it will work.
If that does not work, then please add index.php and check it because it depends on how you setup the project.
I am following this link https://github.com/omerkamcili/ci_google_calendar_api
for integrating google calendar in Codeigniter. I have
got all the credentials. But when i run this application
it returned me to http://hostname/auth/login every time
it logins to the application. When i debug it the token is not generated.
Model :Googlecalendar.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Googlecalendar extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->library('googleplus');
$this->calendar = new Google_Service_Calendar($this->googleplus->client());
}
public function isLogin()
{
$token = $this->session
->userdata('google_calendar_access_token');
if ($token) {
$this->googleplus
->client
->setAccessToken($token);
}
if ($this->googleplus->isAccessTokenExpired()) {
return false;
}
return $token;
}
public function loginUrl()
{
return $this->googleplus
->loginUrl();
}
public function login($code)
{
$login = $this->googleplus
->client
->authenticate($code);
if ($login) {
$token = $this->googleplus
->client
->getAccessToken();
$this->session
->set_userdata('google_calendar_access_token', $token);
return true;
}
}
public function getUserInfo()
{
return $this->googleplus->getUser();
}
public function getEvents($calendarId = 'primary', $timeMin = false, $timeMax = false, $maxResults = 10)
{
if ( ! $timeMin) {
$timeMin = date("c", strtotime(date('Y-m-d ').' 00:00:00'));
} else {
$timeMin = date("c", strtotime($timeMin));
}
if ( ! $timeMax) {
$timeMax = date("c", strtotime(date('Y-m-d ').' 23:59:59'));
} else {
$timeMax = date("c", strtotime($timeMax));
}
$optParams = array(
'maxResults' => $maxResults,
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => $timeMin,
'timeMax' => $timeMax,
'timeZone' => 'Europe/Istanbul',
);
$results = $this->googlecalendar->calendar->events->listEvents($calendarId, $optParams);
$data = array();
foreach ($results->getItems() as $item) {
$start = date('d-m-Y H:i', strtotime($item->getStart()->dateTime));
array_push(
$data,
array(
'id' => $item->getId(),
'summary' => $item->getSummary(),
'description' => $item->getDescription(),
'creator' => $item->getCreator(),
'start' => $item->getStart()->dateTime,
'end' => $item->getEnd()->dateTime,
)
);
}
return $data;
}
public function addEvent($calendarId = 'primary', $data)
{
//date format is => 2016-06-18T17:00:00+03:00
$event = new Google_Service_Calendar_Event(
array(
'summary' => $data['summary'],
'description' => $data['description'],
'start' => array(
'dateTime' => $data['start'],
'timeZone' => 'Europe/Istanbul',
),
'end' => array(
'dateTime' => $data['start'],
'timeZone' => 'Europe/Istanbul',
),
'attendees' => array(
array('email' => 'omerkamcili#gmail.com'),
),
)
);
return $this->calendar->events->insert($calendarId, $event);
}
}
Model: Auth.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->model('googlecalendar');
$this->load->library('session');
if ( ! $this->googlecalendar->isLogin()) {
$this->session->sess_destroy();
redirect('/auth/login', 'refresh');
}
}
}
If you are encountering problems when resolving particular names, and want to verify whether the problem is with Google Public DNS, please try resolve the domain first at: https://dns.google.com. If the result does not pinpoint the problem, you can run the following diagnostic procedure. Check this documentation for more details.
I'm trying to test a method which is using a service, and apparently it's not possible to test it like a normal method.
Does someone know what to do ?
I have this code for the moment :
namespace PlatformBundle\Tests;
use PlatformBundle\Controller\PaymentController;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PaymentControllerTest extends WebTestCase
{
private $payment;
public function __construct() { parent::__construct(); $this->payment = new PaymentController(); }
public function testSendEmail()
{
$param = array(
'info' => array(
'email' => 'test#test.com', 'name' => 'test', 'fare' => 'test', 'id' => 'test'
)
);
$this->assertEquals(true, $this->invokeMethod($this->payment, 'sendEmail', $param));
}
/**
* Call protected/private method of a class.
*
* #param object &$object Instantiated object that we will run method on.
* #param string $methodName Method name to call
* #param array $parameters Array of parameters to pass into method.
*
* #return mixed Method return.
*/
public function invokeMethod(&$object, $methodName, array $parameters = array())
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
}
The controller where the method sendEmail is :
<?php
namespace PlatformBundle\Controller;
use PlatformBundle\Entity\Customer;
use PlatformBundle\Entity\Promocode;
use PlatformBundle\Entity\Transfer;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class PaymentController extends Controller
{
public function checkoutAction(Request $req)
{
if (! $req->isMethod('POST')) throw new AccessDeniedHttpException();
$info = $req->request->all();
$this->container->get('platform.formSecurity')->testAllInformation($info);
$this->saveCustomerIntoDb($info);
$info['payed'] = false;
$session = $req->getSession();
$session->set('info', $info);
$info['date'] = $this->container->get('platform.useful')->reverseDateFormat($info['date']);
return $this->render('PlatformBundle:Payment:checkout.html.twig', array(
'isIndex' => false,
'info' => $info,
'stripe' => $this->stripeConfig()
));
}
public function cancelAction(Request $req)
{
$req->getSession()->invalidate();
return $this->render('PlatformBundle:Payment:cancel.html.twig', array('isIndex' => false));
}
public function successAction(Request $req)
{
$session = $req->getSession();
$info = $session->get('info');
if ($info['payed']) {
$req->getSession()->invalidate();
if ($info === null) throw new Exception('Please contact us to make sure that the payment has been done and that your order has been taken into account.');
$this->saveTransferIntoDb($info);
$customer = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Customer')->findOneBy(array(
'email' => $info['email']
));
$transfer = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Transfer')->findOneBy(
array('customer' => $customer->getId()),
array('id' => 'desc'),
1
);
$info['id'] = $transfer->getId();
$info['date'] = $this->container->get('platform.useful')->reverseDateFormat($info['date']);
$this->sendEmail($info);
// if 5 payments done, send a promocode
if (is_int($customer->getPayments() / 5)) {
$this->createAndSendNewPromocode($customer);
}
return $this->render('PlatformBundle:Payment:success.html.twig', array(
'isIndex' => false,
'info' => $info
));
} else return new RedirectResponse('cancel');
}
private function sendEmail($info)
{
$mail = $this->container->get('platform.mail');
$mail->send(
$info['email'],
'You have ordered a transfer for Dublin',
$this->renderView('PlatformBundle:Mail:orderSucceed.html.twig', array('info' => $info)),
'info#dubair.ie'
);
$mail->send(
'info#airportcollections.net, info#dubair.ie, info#365onlineholidays.com',
'A customer ordered a transfer for Dublin',
$this->renderView('PlatformBundle:Mail:report.html.twig', array('info' => $info)),
'info#dubair.ie'
);
}
private function saveCustomerIntoDb($info)
{
// test if the customer already exist
$customersList = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Customer')
->findByEmail($info['email']);
$customerExists = (sizeof($customersList) == 1 ? true : false);
if ($customerExists) {
$customer = $customersList[0];
} else {
// Create the entity
$customer = new Customer();
// dateRegistration, country and ip are automatically created in the constructor
$customer->setEmail($info['email']);
$customer->setPayments(0);
}
$customer->setName($info['name']);
$customer->setPhone($info['phone']);
$em = $this->getDoctrine()->getManager();
$em->persist($customer);
$em->flush();
}
private function saveTransferIntoDb($info)
{
$customers = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Customer')
->findByEmail($info['email']);
$customer = $customers[0];
$customer->setPayments($customer->getPayments() + 1);
// make promocode outdated
if ($info['promocode'] != '') {
$promocode = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Promocode')
->findOneBy(array(
'value' => $info['promocode'],
'outdated' => 0,
'type' => 'short'
));
$promocode->setOutdated(1);
}
// test if transfer already exist
$transferList = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Transfer')->findBy(
array(
'customer' => $customer,
'pickup' => $info['pickup'],
'destination' => $info['destination'],
'pickupTime' => $info['pickupTime'],
'address' => $info['address']
), // criteria
array('pickup' => 'desc'), // sorting
5, // Limit
0 // Offset
);
// if transfer doesn't already exist, create it
if (sizeof($transferList) == 0) {
$transfer = new Transfer();
$transfer->setPickup($info['pickup']);
$transfer->setDestination($info['destination']);
$dateArray = explode('-', $info['date']);
$transfer->setDate(new \DateTime($dateArray[2].'-'.$dateArray[1].'-'.$dateArray[0]));
$transfer->setAddress($info['address']);
$transfer->setFlightTime($info['flightTime']);
$transfer->setPickupTime($info['pickupTime']);
$transfer->setSeats($info['seats']);
$transfer->setAirline($info['airline']);
$transfer->setFlight($info['flight']);
$transfer->setType($info['type']);
$transfer->setBags($info['bags']);
$transfer->setFare($info['fare']);
// join
$transfer->setCustomer($customer);
$em = $this->getDoctrine()->getManager();
$em->persist($transfer);
$em->flush();
}
}
private function createAndSendNewPromocode($customer)
{
$newPromocode = $this->container->get('platform.useful')->createRandomPassword();
$promocode = new Promocode();
$promocode->setValue($newPromocode);
$promocode->setType('short');
$promocode->setDiscount(10);
$em = $this->getDoctrine()->getManager();
$em->persist($promocode);
$em->flush();
$mail = $this->container->get('platform.mail');
$mail->send(
$customer->getEmail(),
'A promotional code for your next transfer on dubair.ie !',
$this->renderView('PlatformBundle:Mail:promocode.html.twig', array(
'customer' => $customer,
'promocode' => $newPromocode
)),
'info#dubair.ie'
);
}
private function stripeConfig()
{
$stripe = array(
"secret_key" => "xx",
"publishable_key" => "xx"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
return $stripe;
}
public function stripeChargeAction(Request $req)
{
$this->stripeConfig();
$info = $req->getSession()->get('info');
$amount = ($info['fare'] * 100);
$info['payed'] = true;
$req->getSession()->set('info', $info);
$token = $req->request->get('stripeToken');
$customer = \Stripe\Customer::create(array(
'email' => $req->request->get('email'),
'card' => $token
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'eur'
));
return new RedirectResponse('success');
}
}
thanks
I have to create a REST API for mobile backend using CakePHP. After following the instructions here I have been able to setup the requirements for creating a REST API. The problem is that I am getting a null in my output when I use the _serialize variable. Here is my code:
class InvitationController extends AppController {
public $components = array('RequestHandler');
public function index() {
}
public function add() {
if ($this->request->is('post')) {
$this->loadModel('Organizer');
$numPeople = $this->request->data['numpeople'];
$share = $this->request->data['myshare'];
$organizer = $this->request->data['organizer'];
$organizerMobile = $this->request->data['organizermobile'];
$this->set('organizerMobile', $organizerMobile);
$deadline = $this->request->data['deadline'];
$links = array();
date_default_timezone_set("Asia/Calcutta");
$now = date('Y-m-d');
$lastOrganizer = $this->Organizer->find('first', array(
'order' => array('Organizer.id' => 'desc')
));
$checkOrganizer = $this->getOrganizerDetails($lastOrganizer);
$pass = //something;
// save data in organizers table
$this->organizer->create();
$this->organizer->save(
array(
'name' => $organizer,
'mobile' => $organizerMobile,
'p_id' => 1,
'share' => $share,
'deadline' => $deadline,
'password' => $pass,
'group_cardinality' => $numPeople,
'created_on' => $now,
)
);
$message = 1;
$this->set(array(
'message' => $message,
'_serialize' => array($message)
));
}
}
}
When I make a request to POST /invitation.json I get null in the ouput with status 200. On the other hand if I simply do echo json_encode($message) in the Controller or in the View I get the correct output. I think I am doing something wrong. Please help!
That's wrong:
'_serialize' => array($message)
Pay attention to the manual, it shows it correctly in the provided examples.
'_serialize' => array('message')