-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(desktop): throw error after refreshing within classroom and devic…
…e check (#1248)
- Loading branch information
1 parent
bd02188
commit 0f29a81
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; |