From 59cd9e0fb445e25fea3e788933ca114a2c4ddae5 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 11 Apr 2020 14:50:37 +0200 Subject: [PATCH] Rady to connect to other peers --- assets/js/common/ws.js | 5 +++++ assets/js/components/calls/controller.js | 7 +++++++ assets/js/components/calls/window.js | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js index aa13d96a..ac0d31a0 100644 --- a/assets/js/common/ws.js +++ b/assets/js/common/ws.js @@ -232,6 +232,11 @@ class UserWebSocket { case "new_call_signal": SendEvent("newCallSignal", msg.data); break; + + case "call_peer_ready": + SendEvent("callPeerReady", msg.data); + break; + default: console.error("WS Unspported kind of message!", msg); diff --git a/assets/js/components/calls/controller.js b/assets/js/components/calls/controller.js index 3fe9ccd3..675c8f40 100644 --- a/assets/js/components/calls/controller.js +++ b/assets/js/components/calls/controller.js @@ -97,6 +97,13 @@ document.addEventListener("newCallSignal", (e) => { OpenConversations.get(detail.callID).NewSignal(detail.peerID, detail.data) }); +document.addEventListener("callPeerReady", (e) => { + const detail = e.detail; + + if(OpenConversations.has(detail.callID)) + OpenConversations.get(detail.callID).PeerReady(detail.peerID) +}) + document.addEventListener("wsClosed", () => { // Close all the current conversations diff --git a/assets/js/components/calls/window.js b/assets/js/components/calls/window.js index fd337f3f..bb199422 100644 --- a/assets/js/components/calls/window.js +++ b/assets/js/components/calls/window.js @@ -96,6 +96,11 @@ class CallWindow extends CustomEvents { callID: this.conv.ID }) + // Start to connect to ready pears + for(const user of currMembersList) + if(user.userID != userID() && user.ready) + await this.PeerReady(user.userID) + // Start to stream audio & video await this.startStreaming(); @@ -195,6 +200,10 @@ class CallWindow extends CustomEvents { convID: this.conv.ID }) + + if(this.mainPeer) + this.mainPeer.destroy(); + if(propagate) this.emitEvent("close"); } @@ -325,6 +334,10 @@ class CallWindow extends CustomEvents { }); } + async PeerReady(peerID) { + alert("Start to receive " + peerID) + } + /** * Handles new signals *