graciously handle call errors

This commit is contained in:
m5r
2021-09-04 00:19:32 +08:00
parent b4ca27ca87
commit 55a705d3d7
2 changed files with 59 additions and 8 deletions

View File

@ -40,17 +40,24 @@ export default function useMakeCall({ recipient, onHangUp }: Params) {
// @ts-ignore
window.ddd = outgoingConnection;
// TODO: remove event listeners
outgoingConnection.on("error", (error) => {
outgoingConnection.off("cancel", endCall);
outgoingConnection.off("disconnect", endCall);
setState(() => {
// hack to trigger the error boundary
throw error;
});
});
outgoingConnection.once("accept", (call: Call) => setState("call_in_progress"));
outgoingConnection.on("cancel", endCall);
outgoingConnection.on("disconnect", endCall);
outgoingConnection.on("error", (error) => {
console.error("call error", error);
alert(error);
});
}
function endCall() {
outgoingConnection?.off("cancel", endCall);
outgoingConnection?.off("disconnect", endCall);
outgoingConnection?.disconnect();
setState("call_ending");
setTimeout(() => {
setState("call_ended");