How to make Twilio video chat private?

Published

I’m building a Job Search web application using Laravel and Vue.js. I’m using Twilio’s Video SDK to add the ability for Employers and Candidates to have video interviews within our app.
After speaking with a Twilio support agent, he said a common thing developers do to achieve this is to set the RoomName to something like employerName_candidateName.

Right now I have a Calendar.vue file that stores the users interviews inside a Calendar.
On this page I have a button that submits a form with both User information i.e. candidate_user_id and employer_user_id.

So now I’m trying to store the roomName in a session in the getCurrentInterviewUsers() method, so that I can use it in the method generate_token().

AccessTokenController.php:

public function getCurrentInterviewUsers(Request $request)
    {
        $candidate = DB::table('users')->where('id', $request->candidate_user_id)->first();
        $employer = DB::table('users')->where('id', $request->employer_user_id)->first();
        $roomName = $employer->name . '_' . $candidate->name;
        session(['room_name' => $roomName]);

        dd(session('room_name'));
    }

    public function generate_token()
    {
        // Substitute your Twilio Account SID and API Key details
        $accountSid = 'xxx';
        $apiKeySid = 'xxx';
        $apiKeySecret = 'xxx';

        $identity = uniqid();

        // Create an Access Token
        $token = new AccessToken(
            $accountSid,
            $apiKeySid,
            $apiKeySecret,
            3600,
            $identity
        );

        // Grant access to Video
        $grant = new VideoGrant();
        $grant->setRoom(Session::get('roomName'));
        $token->addGrant($grant);

        // Serialize the token as a JWT
        echo $token->toJWT();
    }

When I dd(session('room_name'));, it returns correctly Sally Jane_John Kip.
But when I try to get the session in the generate_token() method, it returns null.
Any idea how I can save something in a global session so that I can access it from anywhere?

Source: Laravel

Published
Categorised as laravel, session, twilio Tagged , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq