Skip to content

Commit

Permalink
Merge pull request #1141 from brave/dsuh-avatarurl
Browse files Browse the repository at this point in the history
Dsuh avatarurl
  • Loading branch information
dvdhs authored Jul 17, 2023
2 parents 6c5a5b7 + b87be2d commit c4c3263
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/web3/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function rememberAvatarUrl(url: string | undefined | null) {
* Gets the currently set avatar url, if any
* @returns {string|null} - The avatar url value or a null value
*/
export function getAvatarUrl(): string | null {
return window.sessionStorage.getItem(AVATAR_URL_SESSION_KEY);
export function getAvatarUrl(jwt: string): string | null {
const sessionAvatar = window.sessionStorage.getItem(AVATAR_URL_SESSION_KEY);
return sessionAvatar || jwt_decode(jwt).avatar_url || null;
}
27 changes: 23 additions & 4 deletions src/jitsi/conference-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ import {
* @param {JitsiOptions} options - Configuration options for the conference room
* @returns {IJitsiMeetApi} The Jitsi API instance for the conference room
*/

function clearAvatarInfoFromLocalStorage() {
const jitsiLocalStorageSettings =
window.localStorage.getItem("jitsiLocalStorage");
if (jitsiLocalStorageSettings) {
const jitsiLocalStorageSettingsObj = JSON.parse(jitsiLocalStorageSettings);
let baseSettings = jitsiLocalStorageSettingsObj["features/base/settings"];
if (baseSettings) {
baseSettings = JSON.parse(baseSettings);
baseSettings["avatarURL"] = "";
jitsiLocalStorageSettingsObj["features/base/settings"] =
JSON.stringify(baseSettings);
}
window.localStorage.setItem(
"jitsiLocalStorage",
JSON.stringify(jitsiLocalStorageSettingsObj)
);
}
}

export const renderConferencePage = async (
jitsiEventHandlers: JitsiEventHandler[],
options: JitsiOptions,
Expand All @@ -26,7 +46,7 @@ export const renderConferencePage = async (
const { roomName, jwt } = options;
reportMethod("renderConferencePage", { roomName, jwt });
reportMethod("JitsiMeetExternalAPI", options);

clearAvatarInfoFromLocalStorage();
const JitsiMeetJS = new JitsiMeetExternalAPI(config.webrtc_domain, options);
reportAction("JitsiMeetExternalAPI", { status: "activated!" });
updateSubject(JitsiMeetJS, options);
Expand All @@ -37,12 +57,11 @@ export const renderConferencePage = async (
context.inactiveInterval
);
}

const avatarUrl = getAvatarUrl();
const avatarUrl = getAvatarUrl(jwt);
if (avatarUrl) {
JitsiMeetJS.executeCommand("avatarUrl", avatarUrl);
}

window.sessionStorage.removeItem("avatar_url");
jitsiEventHandlers.forEach(({ name, fn }: JitsiEventHandler) => {
JitsiMeetJS.on(name, fn(JitsiMeetJS, context, options));
});
Expand Down

0 comments on commit c4c3263

Please sign in to comment.