From 5a067001e9cd4b01a2d022a6feecf8942fbb5022 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 26 Jan 2019 15:59:06 +0100 Subject: [PATCH] Automatically close ring screen if other peer gives up with connection --- assets/js/components/calls/controller.js | 25 +++++++++++++++++++++++- assets/js/components/calls/ringScreen.js | 10 ++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/assets/js/components/calls/controller.js b/assets/js/components/calls/controller.js index cc8561c6..91a40f86 100644 --- a/assets/js/components/calls/controller.js +++ b/assets/js/components/calls/controller.js @@ -184,13 +184,36 @@ ComunicWeb.components.calls.controller = { } //Show ring screen - ComunicWeb.components.calls.ringScreen.show(name, 30, function(accept){ + var prompting = true; + var ringScreenInfo = ComunicWeb.components.calls.ringScreen.show(name, 30, function(accept){ + prompting = false; + undoIsProcessing(); ComunicWeb.components.calls.controller.applyReponseForCall(call, accept); }); + + //Regulary check if the call is still valid + var interval = setInterval(function(){ + + if(!prompting) + return clearInterval(interval); + + ComunicWeb.components.calls.interface.getInfo(call.id, function(info){ + + //Check for errors + if(info.error) + return; + + //Refuse the call if everyone has left it + if(ComunicWeb.components.calls.utils.hasEveryoneLeft(info)) + ringScreenInfo.respond(false); + }); + }, 2000); + + }); }); diff --git a/assets/js/components/calls/ringScreen.js b/assets/js/components/calls/ringScreen.js index c7dfbecc..ed39bba9 100644 --- a/assets/js/components/calls/ringScreen.js +++ b/assets/js/components/calls/ringScreen.js @@ -23,6 +23,7 @@ ComunicWeb.components.calls.ringScreen = { * @param {number} timeout Timeout after which the call is automatically * considered as rejected * @param {(accept : boolean) => any} callback Callback function + * @return {Object} Information about the window */ show: function(title, timeout, callback){ @@ -98,6 +99,15 @@ ComunicWeb.components.calls.ringScreen = { setTimeout(function(){ respond(false); }, timeout*1000); + + return { + + /** + * A function to programmatically respond to call + */ + respond: respond + + }; } } \ No newline at end of file