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

Open a conference in a new tab #79

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lang/en/jitsi.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@
$string['privatesessionsex'] = 'Add private sessions to user profiles';
$string['showavatars'] = 'Show avatars in Jitsi';
$string['showavatarsex'] = 'Show the avatar of the user in Jitsi. If the user has no profile picture this will load the default profile picture from Moodle instead of the initials Jitsi will show when no picture is set.';

$string['conferencemode'] = 'Conference Mode';
$string['conferencemodeex'] = 'Controls how the user joins the conference, either via the iframe embedded into moodle or via a new tab.';
$string['conferencemode_iframe_tab'] = 'Iframe and new tab';
$string['conferencemode_iframe'] = 'Iframe';
$string['conferencemode_tab'] = 'New tab';
$string['access_tab'] = 'Open in new tab';
$string['buttonopeninbrowser'] = 'Open in browser';
$string['buttonopenwithapp'] = 'Join this meeting using the app';
$string['buttondownloadapp'] = 'Download application';
Expand Down
104 changes: 104 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,107 @@ function jitsi_myprofile_navigation(core_user\output\myprofile\tree $tree, $user
}
return true;
}

/**
* Creates a string with the settings for a conference which can be
* appended to a conference link to set specific options like in the
* external api.
*
* @param meetingId string id to join the meeting
* @param name Display name of the user who want's to join
* @param jwt string | null JWT-Token
* @param teacher boolean true if user is teacher
* @param desktop boolean true if user can share desktop
*/
function jitsi_get_url_parameters($meetingId, $name, $jwt, $teacher, $desktop) {
global $CFG;

$configString = '';

$toolbarButtons = ['microphone', 'camera', 'fullscreen', 'hangup', 'fodeviceselection',
'chat', 'profile', 'recording', 'etherpad', 'settings', 'raisehand', 'videoquality', 'stats', 'shortcuts',
'help', 'mute-everyone', 'mute-video-everyone', 'tileview'];

if ($CFG->jitsi_securitybutton) {
$toolbarButtons[] = 'security';
}

if ($CFG->jitsi_invitebuttons) {
$toolbarButtons[] = 'invite';
} else {
$configString = 'config.disableInviteFunctions=true&';
}

if ($CFG->jitsi_shareyoutube) {
$toolbarButtons[] = 'sharevideo';
}

if ($CFG->jitsi_blurbutton) {
$toolbarButtons[] = 'select-background';
}

if ($teacher && $CFG->jitsi_livebutton) {
$toolbarButtons[] = 'livestreaming';
}

if ($desktop) {
$toolbarButtons[] = 'desktop';
}

$configString .= "config.startWithAudioMuted=true&config.startWithVideoMuted=true&userInfo.displayName=%22" . str_replace("+", "%20", urlencode($name)) . '%22&';
$configString .= "interfaceConfig.TOOLBAR_BUTTONS=" . urlencode(json_encode($toolbarButtons)) . "";

if (!$jwt) {
return 'https://' . $CFG->jitsi_domain . '/' . $meetingId . '#' . $configString;
} else {
return 'https://' . $CFG->jitsi_domain . '/' . $meetingId . '?jwt=' . $jwt . '#' . $configString;
}
}

/**
* Returns a JWT-Token
* based on the algorythm in session.php / sessionpriv.php
*
* @param affiliation string Role of the user owner | member
* @param avatar string | null URL to the user avatar
* @param name string (Display) name of the user
* @param session string Session id for the conference
* @param moderator boolean whether the user is moderator
*/
function jitsi_get_jwt_token($affiliation, $avatar, $name, $session, $moderator) {
global $CFG;

$header = json_encode([
"kid" => "jitsi/custom_key_name",
"typ" => "JWT",
"alg" => "HS256"
], JSON_UNESCAPED_SLASHES);
$base64urlheader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header));

$payload = json_encode([
"context" => [
"user" => [
"affiliation" => $affiliation,
"avatar" => $avatar,
"name" => $name,
"email" => "",
"id" => ""
],
"group" => ""
],
"aud" => "jitsi",
"iss" => $CFG->jitsi_app_id,
"sub" => $CFG->jitsi_domain,
"room" => urlencode($session),
"exp" => time() + 24 * 3600,
"moderator" => $moderator

], JSON_UNESCAPED_SLASHES);
$base64urlpayload = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($payload));

$secret = $CFG->jitsi_secret;
$signature = hash_hmac('sha256', $base64urlheader . "." . $base64urlpayload, $secret, true);
$base64urlsignature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature));

return $base64urlheader . "." . $base64urlpayload . "." . $base64urlsignature;
}
2 changes: 1 addition & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ function jitsi_update_calendar(stdClass $jitsi, $cmid) {
}
}
return true;
}
}
3 changes: 3 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@

$settings->add(new admin_setting_configcheckbox('jitsi_showavatars', get_string('showavatars', 'jitsi'), get_string('showavatarsex', 'jitsi'), 1));

$settings->add(new admin_setting_configselect('jitsi_conferencemode', get_string('conferencemode', 'jitsi'), get_string('conferencemodeex', 'jitsi'),
'iframe_tab', ['iframe_tab' => get_string('conferencemode_iframe_tab', 'jitsi'), 'iframe' => get_string('conferencemode_iframe', 'jitsi'), 'tab' => get_string('conferencemode_tab', 'jitsi')]));

$settings->add(new admin_setting_heading('bookmodeditdefaults',
get_string('tokennconfig', 'jitsi'), get_string('tokenconfigurationex', 'jitsi')));
$settings->add(new admin_setting_configtext('jitsi_app_id', get_string('appid', 'jitsi'),
Expand Down
18 changes: 16 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,21 @@
if ($today[0] > (($jitsi->timeopen) - ($jitsi->minpretime * 60))||
(in_array('editingteacher', $rolestr) == 1)) {
echo $OUTPUT->box(get_string('instruction', 'jitsi'));
echo $OUTPUT->single_button(new moodle_url('/mod/jitsi/session.php', $urlparams), get_string('access', 'jitsi'), 'post');

if ($CFG->jitsi_conferencemode == 'iframe' || $CFG->jitsi_conferencemode == 'iframe_tab') {
echo $OUTPUT->single_button(new moodle_url('/mod/jitsi/session.php', $urlparams), get_string('access', 'jitsi'), 'post');
}

if ($CFG->jitsi_conferencemode == 'tab' || $CFG->jitsi_conferencemode == 'iframe_tab') {
$jwt = null;
if ($CFG->jitsi_app_id != null && $CFG->jitsi_secret != null) {
$jwt = jitsi_get_jwt_token($moderation ? 'owner' : 'member', $CFG->jitsi_showavatars ? $avatar : null, $nom, $sesparam, $moderation);
}

$desktop = has_capability('mod/jitsi:sharedesktop', $context);
echo '<div class="singlebutton"><a href="' . jitsi_get_url_parameters($sesparam, $nom, $jwt, $moderation, $desktop) . '" class="btn btn-secondary" target="_blank">' . get_string('access_tab', 'jitsi') . '</a></div>';
}

} else {
echo $OUTPUT->box(get_string('nostart', 'jitsi', $jitsi->minpretime));
}
Expand All @@ -151,4 +165,4 @@ function string_sanitize($string, $forcelowercase = true, $anal = false) {
mb_strtolower($clean, 'UTF-8') :
strtolower($clean) :
$clean;
}
}
9 changes: 8 additions & 1 deletion viewpriv.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@
't' => $moderation);

echo $OUTPUT->box(get_string('instruction', 'jitsi'));
echo $OUTPUT->single_button(new moodle_url('/mod/jitsi/sessionpriv.php', $urlparams), get_string('access', 'jitsi'), 'post');

if ($CFG->jitsi_conferencemode == 'iframe' || $CFG->jitsi_conferencemode == 'iframe_tab') {
echo $OUTPUT->single_button(new moodle_url('/mod/jitsi/sessionpriv.php', $urlparams), get_string('access', 'jitsi'), 'post');
}

if ($CFG->jitsi_conferencemode == 'tab' || $CFG->jitsi_conferencemode == 'iframe_tab') {
echo '<div class="singlebutton"><a href="' . jitsi_get_url_parameters($sesparam, $nom, null, $moderation, true) . '" class="btn btn-secondary" target="_blank">' . get_string('access_tab', 'jitsi') . '</a></div>';
}

echo $CFG->jitsi_help;
echo $OUTPUT->footer();
Expand Down