Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Contruct Method Exception #18

Closed
amtzm93 opened this issue Oct 8, 2020 · 1 comment
Closed

Session Contruct Method Exception #18

amtzm93 opened this issue Oct 8, 2020 · 1 comment

Comments

@amtzm93
Copy link

amtzm93 commented Oct 8, 2020

Problem

When I trying to create a session by using the example Create a token for a new session or an existing session from the README.md

$customSessionId = Str::random(20);
$sessionProperties = new SessionProperties(MediaMode::ROUTED, RecordingMode::MANUAL, OutputMode::COMPOSED, RecordingLayout::BEST_FIT, $customSessionId);
$session = OpenVidu::createSession($sessionProperties);

The parameter declares for the createSession function from OpenVidu Class is a SessionProperties Object. Inside this function create the Session Object (line 55, OpenVidu.php).

public function createSession(?SessionProperties $properties = null): Session
{
    $session = new Session($this->client(), $properties);
     Cache::store('openvidu')->forever($session->getSessionId(), $session->toJson());
     return $session;
}

For the creation of the Session by using its constructor (line 61, Session.php), it needs the next parameter in this order

  • $client :
    • Class: Client
    • Default value: null
  • $sessionId :
    • Class: Int
    • Default value: null
  • $properties :
    • Class : SessionProperties
    • Default value : null
public function __construct(Client $client, int $sessionId = null, ?SessionProperties $properties = null)
{
    $this->client = $client;
    if(!$sessionId) {
        $this->properties = $properties ? $properties : new SessionProperties(MediaMode::ROUTED, RecordingMode::MANUAL, OutputMode::COMPOSED, RecordingLayout::BEST_FIT);
        $this->sessionId = $this->getSessionId();
    }
}

Errors

  1. The parameter $sessionId is expected as an integer in the constructor, but in the example to create a token for a new session it's using a Str::random() and it returns a string.
  2. The Session constructor method expect as a second parameter a $sessionId, but we never send in the function createSession, but the sessionId is inside the SessionProperties Object.

Note

  • To resolve this, we need to remember the function getSession from OpenVidu.php (line 154), create a session but in the right way.
public function getSession(string $sessionId): Session
{
    if (Cache::store('openvidu')->has($sessionId)) {
        return (new Session($this->client(), $sessionId))->fromJson(Cache::store('openvidu')->get($sessionId));
    }
    throw new OpenViduSessionNotFoundException();
}

I hope I have been of your help, have a good day. 😄

@jcancig jcancig closed this as completed Oct 8, 2020
@jcancig
Copy link
Member

jcancig commented Oct 8, 2020

Thanks for the report, the class is now updated. The reason for passing the $sessionId parameter in the builder is to avoid creating a new class when rehydrating using the fromJson.
Now the parameter type is corrected, it is optional and it is a string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants