Skip to content

Commit

Permalink
/talk improvements: if the user logs in, try to re-open the room au…
Browse files Browse the repository at this point in the history
…tomatically (#68)

Re #16
  • Loading branch information
tackley committed Dec 2, 2021
1 parent 94129e4 commit 64d9c96
Showing 1 changed file with 43 additions and 12 deletions.
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

0 comments on commit 64d9c96

Please sign in to comment.