From ca5dd4b34c5c74343d736629537e01882fd6905e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 11 Apr 2020 09:13:54 +0200 Subject: [PATCH] Start to send signals --- assets/js/components/calls/window.js | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/assets/js/components/calls/window.js b/assets/js/components/calls/window.js index 28e16bcf..378fcdf3 100644 --- a/assets/js/components/calls/window.js +++ b/assets/js/components/calls/window.js @@ -15,6 +15,7 @@ class CallWindow extends CustomEvents { constructor(conv) { super() this.conv = conv; + this.callID = conv.ID; this.construct(conv); } @@ -73,11 +74,18 @@ class CallWindow extends CustomEvents { convID: this.conv.ID }) + // Get call configuration + this.callsConfig = await ws("calls/config"); + // Get the list of members of the call const currMembersList = await ws("calls/members", { callID: this.conv.ID }) + // Start to stream audio & video + await this.startStreaming(); + + // Apply this list of user for(const user of currMembersList) if(user != userID()) @@ -208,4 +216,49 @@ class CallWindow extends CustomEvents { el.remove() } + + /** + * Get call configuration + */ + callConfig() { + return { + iceServers: this.callsConfig.iceServers.map((e) => {return {urls: e}}) + }; + } + + /** + * Add video stream to the user + * + * + */ + addVideoStream(video) { + + } + + /** + * Start to send this client audio & video + */ + async startStreaming() { + + // First, query user media + const stream = await navigator.mediaDevices.getUserMedia({ + video: true, + audio: true + }) + + this.mainPeer = new SimplePeer({ + initiator: true, + trickle: true, // Allow exchange of multiple ice candidates + stream: stream, + config: this.callConfig() + }) + + this.mainPeer.on("signal", data => { + ws("call/signal", { + callID: this.callID, + peerID: userID(), + data: data + }) + }) + } } \ No newline at end of file