From be0306b309d3ece70c66285ed34cf06dc6cc5823 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 23 Feb 2019 18:27:31 +0100 Subject: [PATCH] Close ring screen if user respond to call on another client --- assets/js/components/calls/controller.js | 7 ++++++- assets/js/components/calls/ringScreen.js | 22 +++++++++++++++++----- assets/js/components/calls/utils.js | 17 +++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/assets/js/components/calls/controller.js b/assets/js/components/calls/controller.js index 61fb8b8b..95dee3f3 100644 --- a/assets/js/components/calls/controller.js +++ b/assets/js/components/calls/controller.js @@ -213,7 +213,12 @@ ComunicWeb.components.calls.controller = { //Refuse the call if everyone has left it if(ComunicWeb.components.calls.utils.hasEveryoneLeft(info)) - ringScreenInfo.respond(false); + ringScreenInfo.respond(false); + + //Close ring screen if user responded to the call on another Comunic client + if(ComunicWeb.components.calls.utils.getCurrentUserState(info) != "unknown") + ringScreenInfo.close(); + }); }, 2000); diff --git a/assets/js/components/calls/ringScreen.js b/assets/js/components/calls/ringScreen.js index ed39bba9..5749e159 100644 --- a/assets/js/components/calls/ringScreen.js +++ b/assets/js/components/calls/ringScreen.js @@ -71,20 +71,26 @@ ComunicWeb.components.calls.ringScreen = { innerHTML: "Accept" }); + var close = function(){ + + ComunicWeb.components.calls.ringScreen._song.stop(); + + //Remove elem + emptyElem(callContainer); + callContainer.remove(); + + } + var hasResponded = false; var respond = function(accept){ - ComunicWeb.components.calls.ringScreen._song.stop(); + close(); if(hasResponded) return; hasResponded = true; callback(accept); - - //Remove elem - emptyElem(callContainer); - callContainer.remove(); } rejectButton.addEventListener("click", function() { @@ -102,6 +108,12 @@ ComunicWeb.components.calls.ringScreen = { return { + /** + * A function to close the current ringscreen, without + * calling callback + */ + close: close, + /** * A function to programmatically respond to call */ diff --git a/assets/js/components/calls/utils.js b/assets/js/components/calls/utils.js index b10ae22b..f38032f9 100644 --- a/assets/js/components/calls/utils.js +++ b/assets/js/components/calls/utils.js @@ -22,6 +22,23 @@ ComunicWeb.components.calls.utils = { return allDisconnected; + }, + + /** + * Get the current user response to a call + * + * @param {Call} call Current call information + * @return The response of the current user to the call + */ + getCurrentUserState: function(call){ + + var userstate = undefined; + call.members.forEach(function(member){ + if(member.userID == userID()) + userstate = member.status + }); + + return userstate; } }; \ No newline at end of file