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