diff --git a/lang/en/jitsi.php b/lang/en/jitsi.php index 3f08141b..6071109e 100644 --- a/lang/en/jitsi.php +++ b/lang/en/jitsi.php @@ -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'; diff --git a/lib.php b/lib.php index cbefdaed..c951bb7d 100644 --- a/lib.php +++ b/lib.php @@ -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; +} \ No newline at end of file diff --git a/locallib.php b/locallib.php index 54199459..ac24ab5b 100644 --- a/locallib.php +++ b/locallib.php @@ -75,4 +75,4 @@ function jitsi_update_calendar(stdClass $jitsi, $cmid) { } } return true; -} +} \ No newline at end of file diff --git a/settings.php b/settings.php index 5e1ae57b..39fcb535 100644 --- a/settings.php +++ b/settings.php @@ -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'), diff --git a/view.php b/view.php index c8bfaedf..5514c0c4 100644 --- a/view.php +++ b/view.php @@ -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 '
' . get_string('access_tab', 'jitsi') . '
'; + } + } else { echo $OUTPUT->box(get_string('nostart', 'jitsi', $jitsi->minpretime)); } @@ -151,4 +165,4 @@ function string_sanitize($string, $forcelowercase = true, $anal = false) { mb_strtolower($clean, 'UTF-8') : strtolower($clean) : $clean; -} +} \ No newline at end of file diff --git a/viewpriv.php b/viewpriv.php index 4aa84559..6252d210 100644 --- a/viewpriv.php +++ b/viewpriv.php @@ -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 '
' . get_string('access_tab', 'jitsi') . '
'; +} echo $CFG->jitsi_help; echo $OUTPUT->footer();