diff --git a/assets/js/common/ws.js b/assets/js/common/ws.js index 8b95b604..aa13d96a 100644 --- a/assets/js/common/ws.js +++ b/assets/js/common/ws.js @@ -229,6 +229,10 @@ class UserWebSocket { SendEvent("userLeftCall", msg.data); break; + case "new_call_signal": + SendEvent("newCallSignal", 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 02598a67..3fe9ccd3 100644 --- a/assets/js/components/calls/controller.js +++ b/assets/js/components/calls/controller.js @@ -90,6 +90,13 @@ document.addEventListener("userLeftCall", (e) => { OpenConversations.get(detail.callID).RemoveMember(detail.userID) }) +document.addEventListener("newCallSignal", (e) => { + const detail = e.detail + + if(OpenConversations.has(detail.callID)) + OpenConversations.get(detail.callID).NewSignal(detail.peerID, detail.data) +}); + 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 2fde4d96..2aecdfc1 100644 --- a/assets/js/components/calls/window.js +++ b/assets/js/components/calls/window.js @@ -271,5 +271,32 @@ class CallWindow extends CustomEvents { console.error("Peer error!", err); notify("An error occured while trying to connect!", "danger", 5) }); + + this.mainPeer.on("connect", () => console.info("Connected to remote peer!")) + + this.mainPeer.on("message", message => { + console.log("Message from remote peer: " + message); + }); + + this.mainPeer.on("stream", stream => { + console.log("mainPeer stream", stream) + alert("Stream on main peer!!!") + }); + } + + /** + * Handles new signals + * + * @param {Number} peerID Target peer ID + * @param {any} data Signal data + */ + NewSignal(peerID, data) { + + if(peerID == userID()) + this.mainPeer.signal(data) + + else + console.error("Unsupported type of signal!") + } } \ No newline at end of file