From e46f8a36a790c605c2e41b54dcac5417d8e42984 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 10 Apr 2020 17:09:40 +0200 Subject: [PATCH] Automatically update the list of members of the call --- assets/js/common/ws.js | 8 ++++++++ assets/js/components/calls/controller.js | 15 +++++++++++++++ assets/js/components/calls/window.js | 18 +++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js index c4d497ff..8b95b604 100644 --- a/assets/js/common/ws.js +++ b/assets/js/common/ws.js @@ -221,6 +221,14 @@ class UserWebSocket { SendEvent("commentDeleted", msg.data); break; + case "user_joined_call": + SendEvent("userJoinedCall", msg.data); + break; + + case "user_left_call": + SendEvent("userLeftCall", msg.data); + break; + default: console.error("WS Unspported kind of message!", msg); break; diff --git a/assets/js/components/calls/controller.js b/assets/js/components/calls/controller.js index 54fa8d44..ce9c7d06 100644 --- a/assets/js/components/calls/controller.js +++ b/assets/js/components/calls/controller.js @@ -76,6 +76,21 @@ class CallsController { } } +document.addEventListener("userJoinedCall", (e) => { + const detail = e.detail; + + if(OpenConversations.has(detail.callID)) + OpenConversations.get(detail.callID).AddMember(detail.userID) +}) + +document.addEventListener("userLeftCall", (e) => { + const detail = e.detail; + + if(OpenConversations.has(detail.callID)) + OpenConversations.get(detail.callID).RemoveMember(detail.userID) +}) + + document.addEventListener("wsClosed", () => { // Close all the current conversations OpenConversations.forEach((v) => v.Close(false)) diff --git a/assets/js/components/calls/window.js b/assets/js/components/calls/window.js index 854de7ef..28e16bcf 100644 --- a/assets/js/components/calls/window.js +++ b/assets/js/components/calls/window.js @@ -185,11 +185,27 @@ class CallWindow extends CustomEvents { async AddMember(userID) { // Apply user information - createElem2({ + const el = createElem2({ appendTo: this.membersArea, type: "span", innerHTML: (await user(userID)).fullName }); + el.setAttribute("data-call-member-name-id", userID) + + } + + + /** + * Remove a user from a call + * + * @param {number} userID The ID of the target user + */ + async RemoveMember(userID) { + + // Remove user name + const el = this.membersArea.querySelector("[data-call-member-name-id=\""+userID+"\"]") + if(el) + el.remove() } } \ No newline at end of file