Skip to content

Commit

Permalink
Feature/star 951 (#11)
Browse files Browse the repository at this point in the history
* Add starategy mode for jaas mode jitsi

* Add variable to TestCase

* Add package_status in testcase

* Correct bug

* Add try catch

* Add try catch

* Add debug

* Add debug

* Add debug

* Repair tests

* Add priority for mode video conference

* Remove secret key from config

* Add ServiceProvider to testCase

* REmove on provider

* Add missing provider totestbench

* Add provider to testcase file

* Remove courses from jitsi composer

* Add missing field to config

* Change config to jitsi, change generate url

* Update composer.json

Co-authored-by: Hubert Krzysztofiak <[email protected]>
Co-authored-by: Mateusz Qunabu <[email protected]>
  • Loading branch information
3 people authored Nov 30, 2022
1 parent 2cd44aa commit a801ba3
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"orchestra/testbench": ">=5.0"
"orchestra/testbench": "^6"
},
"license": "MIT",
"authors": [
Expand Down
7 changes: 7 additions & 0 deletions config/jitsi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@

'package_status' => PackageStatusEnum::ENABLED,

'jaas_host' => env('JAAS_HOST', 'https://8x8.vc/'),
'aud' => env('JAAS_AUD', 'jitsi'),
'iss' => env('JAAS_ISS', 'chat'),
'sub' => env('JAAS_SUB', ''),
'kid' => env('JAAS_KEY_ID', ''),
'private_key' => env('JAAS_PRIVATE_KEY', '')

];
18 changes: 15 additions & 3 deletions src/Services/JitsiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JitsiService implements JitsiServiceContract
public function __construct()
{
$this->mode = $this->getMode();
$this->config = $this->mode ? config($this->mode) : config(JitsiEnum::DEFAULT_CONFIG);
$this->config = config(JitsiEnum::DEFAULT_CONFIG);
}

public function generateJwt(
Expand Down Expand Up @@ -87,6 +87,7 @@ public function getChannelData(
]
];
$jwt = '';
$url = '';
if ($this->mode) {
$className = ucfirst($this->mode) .
'VideoConferenceModeStrategy';
Expand All @@ -98,6 +99,13 @@ public function getChannelData(
$channelName,
$isModerator
);
$url = StrategyHelper::useStrategyPattern(
$className,
'VideoConferenceModeStrategy',
'getUrl',
$jwt,
$channelName
);
}
if (!empty($jwt)) {
$data['jwt'] = $jwt;
Expand All @@ -106,7 +114,11 @@ public function getChannelData(
return [
'data' => $data,
'domain' => $this->config[$this->mode . '_host'],
'url' => "https://" . $this->config[$this->mode . '_host'] . "/" . $channelName . (!empty($jwt) ? "?jwt=" . $jwt : ""),
'url' => $url ?: "https://" .
$this->config[$this->mode . '_host'] .
"/" .
$channelName .
(!empty($jwt) ? "?jwt=" . $jwt : ""),
];
}

Expand Down Expand Up @@ -141,7 +153,7 @@ private function getMode(): string
$jaasKeys = collect(['jaas_host', 'aud', 'iss', 'kid', 'private_key']);
$jaasConfigUse = true;
$jaasKeys->each(function (string $key) use (&$jaasConfigUse) {
if (!config('jaas.' . $key)) $jaasConfigUse = false;
if (!config('jitsi.' . $key)) $jaasConfigUse = false;
});
if ($jaasConfigUse) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
interface VideoConferenceModeStrategyContract
{
public function generateJwt(array $data): ?string;
public function getUrl(array $data): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class JaasVideoConferenceModeStrategy implements VideoConferenceModeStrategyCont

public function __construct()
{
$this->config = config('jaas');
$this->config = config('jitsi');
$this->jaasService = app(JaasServiceContract::class);
}

Expand All @@ -30,6 +30,20 @@ public function generateJwt(array $data): ?string
return null;
}

public function getUrl(array $data): string
{
$jwt = $data[0] ?? '';
$channelName = $data[1] ?? '';

return 'https://' .
$this->config['jaas_host'] .
'/' .
$this->config['sub'] .
'/' .
$channelName .
(!empty($jwt) ? "?jwt=" . $jwt : "");
}

private function shouldGenerateJWT(): bool
{
return !(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public function generateJwt(array $data): ?string
return null;
}

public function getUrl(array $data): string
{
$jwt = $data[0] ?? '';
$channelName = $data[1] ?? '';

return 'https://' .
$this->config['jitsi_host'] .
'/' .
$channelName .
(!empty($jwt) ? "?jwt=" . $jwt : "");
}

private function shouldGenerateJWT(): bool
{
return !(!$this->config["app_id"] && !$this->config["secret"]);
Expand Down
16 changes: 8 additions & 8 deletions tests/Services/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public function testServiceWithJwtJaas()
'private_key_bits' => 1024,
'private_key_type' => OPENSSL_KEYTYPE_RSA
]);
\Config::set('jaas.private_key', $private_key);
\Config::set('jaas.sub', Str::random(40));
\Config::set('jaas.kid', Str::random(40));
$config = config('jaas');
\Config::set('jitsi.private_key', $private_key);
\Config::set('jitsi.sub', Str::random(40));
\Config::set('jitsi.kid', Str::random(40));
$config = config('jitsi');
$data = Jitsi::getChannelData($this->user, $this->faker->text(15));
$jwt = $this->decodeJWT($data['data']['jwt']);
$this->assertEquals($data['data']['domain'], $config['jaas_host']);
Expand All @@ -71,10 +71,10 @@ public function testServiceWithJwtAndSettingsJaas()
'private_key_bits' => 1024,
'private_key_type' => OPENSSL_KEYTYPE_RSA
]);
\Config::set('jaas.private_key', $private_key);
\Config::set('jaas.sub', Str::random(40));
\Config::set('jaas.kid', Str::random(40));
$config = config('jaas');
\Config::set('jitsi.private_key', $private_key);
\Config::set('jitsi.sub', Str::random(40));
\Config::set('jitsi.kid', Str::random(40));
$config = config('jitsi');
$data = Jitsi::getChannelData($this->user, "Test Channel Name", true, ['foo' => 'bar'], ['bar' => 'foo']);
$jwt = $this->decodeJWT($data['data']['jwt']);
$this->assertEquals($data['data']['domain'], $config['jaas_host']);
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ protected function getEnvironmentSetUp($app)
$app['config']->set('jitsi.jitsi_host', 'localhost');
$app['config']->set('jitsi.package_status', PackageStatusEnum::ENABLED);

$app['config']->set('jaas.jaas_host', 'localhost');
$app['config']->set('jaas.aud', 'jitsi');
$app['config']->set('jaas.iss', 'chat');
$app['config']->set('jaas.sub', '');
$app['config']->set('jaas.kid', '');
$app['config']->set('jitsi.jaas_host', 'localhost');
$app['config']->set('jitsi.aud', 'jitsi');
$app['config']->set('jitsi.iss', 'chat');
$app['config']->set('jitsi.sub', '');
$app['config']->set('jitsi.kid', '');
}
}

0 comments on commit a801ba3

Please sign in to comment.