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

/talk improvements: if the user logs in, try to re-open the room automatically #68

Merged
merged 1 commit into from
Dec 2, 2021
Merged
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
55 changes: 43 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,27 @@ const main = async () => {
} catch (e) {}
}

if (!orderId) {
// backwards compatibility - remove once the order param is implemented everywhere
orderId = params.get("orderId");
}
let autoJoinRoom: string | undefined;

if (intent === "provision" && orderId) {
if (orderId) {
try {
const s = await import("./subscriptions");
await s.provisionOrder(orderId);
} catch (e) {}
} else if (intent === "recover" && orderId) {
try {
const s = await import("./subscriptions");
await s.recoverCredsIfRequired(orderId);
if (intent === "provision") {
await s.provisionOrder(orderId);
} else if (intent === "recover") {
await s.recoverCredsIfRequired(orderId);
}
autoJoinRoom = getAutoOpenRoom();
} catch (e) {}
}

// fast track check for whether we should immediately try to join a room
const browser = await calcBrowserCapabilities();
const joinRoom = checkJoinRoom(extractRoomNameFromUrl(), browser);

const joinRoom = checkJoinRoom(
extractRoomNameFromUrl() ?? autoJoinRoom,
browser
);

if (!joinRoom || joinRoom === "widget") {
const context: Context = {
Expand Down Expand Up @@ -596,7 +597,9 @@ const joinConferenceRoom = async (
showStartCall: true,
roomNameOverride: roomName,
});
setAutoOpenRoom(roomName);
setTimeout(() => joinConferenceRoom(roomName, false), 5_000);

return;
}
}
Expand Down Expand Up @@ -625,6 +628,34 @@ const isRoomValid = (room: string) => {
return typeof room === "string" && room.match(/^[A-Za-z0-9-_]{43}$/);
};

const AUTO_OPEN_ROOM_KEY = "talk_auto_open_room";

const setAutoOpenRoom = (roomName: string) => {
try {
window.sessionStorage.setItem(
AUTO_OPEN_ROOM_KEY,
JSON.stringify({ roomName, exp: new Date().getTime() + 1000 * 60 * 5 })
);
} catch {
// ignore
}
};

const getAutoOpenRoom = (): string | undefined => {
try {
const s = window.sessionStorage.getItem(AUTO_OPEN_ROOM_KEY);
if (s) {
const obj = JSON.parse(s);
if (obj.exp && obj.exp >= new Date().getTime()) {
reportAction("autoOpenRoom", obj.roomName);
return obj.roomName;
}
}
} catch {
// ignore
}
};

const notice = (text: string) => {
const element = document.getElementById("notice_text")!;

Expand Down