Skip to content

Commit

Permalink
fix(desktop): throw error after refreshing within classroom and devic…
Browse files Browse the repository at this point in the history
…e check (#1248)
  • Loading branch information
BlackHole1 committed Dec 27, 2021
1 parent bd02188 commit 0f29a81
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion desktop/renderer-app/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { initRegisterApps } from "./init-register-apps";
import { initWhiteSDK } from "./init-white-sdk";
import { initUI } from "./init-ui";
import { initURLProtocol } from "./init-url-protocol";
import { initWaitRTC } from "./init-wait-rtc";

const tasks = [initEnv, initURLProtocol, initWhiteSDK, initUI, initRegisterApps];
const tasks = [initEnv, initURLProtocol, initWhiteSDK, initWaitRTC, initUI, initRegisterApps];

export default tasks;
35 changes: 35 additions & 0 deletions desktop/renderer-app/src/tasks/init-wait-rtc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// if the classroom page is refreshed, the rtc code will be used immediately
// if we do not force a wait, the classroom page will report an error
export const initWaitRTC = async (): Promise<void> => {
// e.g:
// ["#", "classroom", "BigClass"]
// ["#"]
const hashList = document.location.hash.split("/");

if (hashList.length <= 1) {
return;
}

// e.g: ["classroom", "device"];
const currentPagePrefix = hashList[1];

// currently, only the classroom and device pages use the RTC
// so when the user is refreshing on both pages, we need to force a wait for rtcEngine to be ready.
const needWaitRTCPagesPrefix = ["classroom", "device"];

const result = needWaitRTCPagesPrefix.includes(currentPagePrefix);

if (!result) {
return;
}

await new Promise<void>(resolve => {
// after actual testing, here it will probably wait until 200ms ~ 500ms
const id = setInterval(() => {
if (window.rtcEngine) {
clearInterval(id);
resolve();
}
}, 50);
});
};

0 comments on commit 0f29a81

Please sign in to comment.