From 26a1416c337cdc99259af6e5001722b1c8ea8745 Mon Sep 17 00:00:00 2001 From: Henry Brink Date: Thu, 15 Apr 2021 23:12:20 +0200 Subject: [PATCH 1/3] Added: Feature to open a conference in a new tab --- lang/en/jitsi.php | 6 +++ lib.php | 98 +++++++++++++++++++++++++++++++++++++++++++++++ locallib.php | 2 +- settings.php | 3 ++ view.php | 17 +++++++- 5 files changed, 123 insertions(+), 3 deletions(-) diff --git a/lang/en/jitsi.php b/lang/en/jitsi.php index 0b781ce8..af8f29a0 100644 --- a/lang/en/jitsi.php +++ b/lang/en/jitsi.php @@ -94,3 +94,9 @@ $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'; \ No newline at end of file diff --git a/lib.php b/lib.php index cbefdaed..50208ca3 100644 --- a/lib.php +++ b/lib.php @@ -199,3 +199,101 @@ 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 + */ +function jitsi_get_url_parameters($meetingId, $name, $jwt) { + global $CFG; + + $configString = ''; + + $toolbarButtons = ['microphone', 'camera', 'desktop', 'fullscreen', 'hangup', 'fodeviceselection', + 'chat', 'profile', 'recording', 'etherpad', 'settings', 'raisehand', 'videoquality', 'stats', 'shortcuts', + 'help', 'mute-everyone', 'mute-video-everyone']; + + if ($CFG->jitsi_securitybutton) { + $toolbarButtons[] = 'security'; + } + + if ($CFG->jitsi_invitebuttons) { + $toolbarButtons[] = 'invite'; + } else { + $configString = 'config.disableInviteFunctions=true&'; + } + + if ($CFG->jitsi_shareyoutube) { + $toolbarButtons[] = 'livestreaming'; + } + + if ($CFG->jitsi_blurbutton) { + $toolbarButtons[] = 'select-background'; + } + + if ($CFG->jitsi_shareyoutube) { + $toolbarButtons[] = 'sharevideo'; + } + + $configString .= "config.startWithAudioMuted=true&config.startWithVideoMuted=true&userInfo.displayName=%22" . $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..19e7009d 100644 --- a/view.php +++ b/view.php @@ -125,7 +125,20 @@ 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); + } + + echo '
' . get_string('access_tab', 'jitsi') . '
'; + } + } else { echo $OUTPUT->box(get_string('nostart', 'jitsi', $jitsi->minpretime)); } @@ -151,4 +164,4 @@ function string_sanitize($string, $forcelowercase = true, $anal = false) { mb_strtolower($clean, 'UTF-8') : strtolower($clean) : $clean; -} +} \ No newline at end of file From 39ecdcf34d69c94014e70e50bdde6e48d9aab1fb Mon Sep 17 00:00:00 2001 From: Henry Brink Date: Fri, 16 Apr 2021 09:41:37 +0200 Subject: [PATCH 2/3] fix: Tileview not visible & double check for youtube-embed --- lib.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib.php b/lib.php index 50208ca3..4aaf65bf 100644 --- a/lib.php +++ b/lib.php @@ -216,7 +216,7 @@ function jitsi_get_url_parameters($meetingId, $name, $jwt) { $toolbarButtons = ['microphone', 'camera', 'desktop', 'fullscreen', 'hangup', 'fodeviceselection', 'chat', 'profile', 'recording', 'etherpad', 'settings', 'raisehand', 'videoquality', 'stats', 'shortcuts', - 'help', 'mute-everyone', 'mute-video-everyone']; + 'help', 'mute-everyone', 'mute-video-everyone', 'tileview']; if ($CFG->jitsi_securitybutton) { $toolbarButtons[] = 'security'; @@ -229,17 +229,13 @@ function jitsi_get_url_parameters($meetingId, $name, $jwt) { } if ($CFG->jitsi_shareyoutube) { - $toolbarButtons[] = 'livestreaming'; + $toolbarButtons[] = 'sharevideo'; } if ($CFG->jitsi_blurbutton) { $toolbarButtons[] = 'select-background'; } - if ($CFG->jitsi_shareyoutube) { - $toolbarButtons[] = 'sharevideo'; - } - $configString .= "config.startWithAudioMuted=true&config.startWithVideoMuted=true&userInfo.displayName=%22" . $name . '%22&'; $configString .= "interfaceConfig.TOOLBAR_BUTTONS=" . urlencode(json_encode($toolbarButtons)) . ""; From 689883332fd8020e225e216173f196bf556235ed Mon Sep 17 00:00:00 2001 From: Henry Brink Date: Fri, 16 Apr 2021 09:58:31 +0200 Subject: [PATCH 3/3] Added option to private settings as well --- lib.php | 16 +++++++++++++--- view.php | 3 ++- viewpriv.php | 9 ++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib.php b/lib.php index 4aaf65bf..c951bb7d 100644 --- a/lib.php +++ b/lib.php @@ -208,13 +208,15 @@ function jitsi_myprofile_navigation(core_user\output\myprofile\tree $tree, $user * @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) { +function jitsi_get_url_parameters($meetingId, $name, $jwt, $teacher, $desktop) { global $CFG; $configString = ''; - $toolbarButtons = ['microphone', 'camera', 'desktop', 'fullscreen', 'hangup', 'fodeviceselection', + $toolbarButtons = ['microphone', 'camera', 'fullscreen', 'hangup', 'fodeviceselection', 'chat', 'profile', 'recording', 'etherpad', 'settings', 'raisehand', 'videoquality', 'stats', 'shortcuts', 'help', 'mute-everyone', 'mute-video-everyone', 'tileview']; @@ -236,7 +238,15 @@ function jitsi_get_url_parameters($meetingId, $name, $jwt) { $toolbarButtons[] = 'select-background'; } - $configString .= "config.startWithAudioMuted=true&config.startWithVideoMuted=true&userInfo.displayName=%22" . $name . '%22&'; + 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) { diff --git a/view.php b/view.php index 19e7009d..5514c0c4 100644 --- a/view.php +++ b/view.php @@ -136,7 +136,8 @@ $jwt = jitsi_get_jwt_token($moderation ? 'owner' : 'member', $CFG->jitsi_showavatars ? $avatar : null, $nom, $sesparam, $moderation); } - echo ''; + $desktop = has_capability('mod/jitsi:sharedesktop', $context); + echo ''; } } else { 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 ''; +} echo $CFG->jitsi_help; echo $OUTPUT->footer();