diff --git a/web-service/server/src/peer.js b/web-service/server/src/peer.js index 707c04de41af67edf5b570e3963a7825b65c60f1..b96b93fce19e0430656b02d2407bf88c9ccf09e6 100644 --- a/web-service/server/src/peer.js +++ b/web-service/server/src/peer.js @@ -58,12 +58,13 @@ function Peer(ws) { } } - let close = (event) => { + let close = () => { + console.log("connection closed") this.status = kDisconnected; this._notify("disconnect", this); } - let error = (event) => { + let error = () => { console.error("Socket error"); this.sock.close(); this.status = kDisconnected; @@ -71,9 +72,9 @@ function Peer(ws) { //if undefined, client is using peer if(this.sock.on === undefined){ - console.log("THIS.SOCK", this.sock); this.sock.onopen = (event) => { - this.sock.send(encode([1, '__handshake__'])) + this.sock.send(encode([0, '__handshake__'])); + console.log("socket was opened") } //Server is using peer }else{ @@ -94,7 +95,6 @@ function Peer(ws) { this.close(); } }); - this.send("__handshake__", kMagic, kVersion, [my_uuid]); } @@ -225,7 +225,7 @@ Peer.prototype.send = function(name, ...args) { } Peer.prototype.close = function() { - this.sock.close(); + this.sock.close = close; this.status = kDisconnected; } @@ -255,4 +255,5 @@ Peer.prototype.on = function(evt, f) { this.events[evt].push(f); } + module.exports = Peer; diff --git a/web-service/server/src/public/js/bundle.js b/web-service/server/src/public/js/bundle.js index be1155ac4edfebda5e27049f1391eca8bac5e9ad..317a0f6f29e4d1da4e92e13ab3da27688da886e9 100644 --- a/web-service/server/src/public/js/bundle.js +++ b/web-service/server/src/public/js/bundle.js @@ -4305,12 +4305,13 @@ function Peer(ws) { } } - let close = (event) => { + let close = () => { + console.log("connection closed") this.status = kDisconnected; this._notify("disconnect", this); } - let error = (event) => { + let error = () => { console.error("Socket error"); this.sock.close(); this.status = kDisconnected; @@ -4318,9 +4319,9 @@ function Peer(ws) { //if undefined, client is using peer if(this.sock.on === undefined){ - console.log("THIS.SOCK", this.sock); this.sock.onopen = (event) => { - this.sock.send(encode([1, '__handshake__'])) + this.sock.send(encode([0, '__handshake__'])); + console.log("socket was opened") } //Server is using peer }else{ @@ -4341,7 +4342,6 @@ function Peer(ws) { this.close(); } }); - this.send("__handshake__", kMagic, kVersion, [my_uuid]); } @@ -4472,7 +4472,7 @@ Peer.prototype.send = function(name, ...args) { } Peer.prototype.close = function() { - this.sock.close(); + this.sock.close = close; this.status = kDisconnected; } @@ -4502,6 +4502,7 @@ Peer.prototype.on = function(evt, f) { this.events[evt].push(f); } + module.exports = Peer; }).call(this,require("buffer").Buffer) @@ -4509,6 +4510,7 @@ module.exports = Peer; const Peer = require('../../peer') let current_data = {}; +let peer; checkIfLoggedIn = async () => { // const token = window.localStorage.getItem('token') @@ -4564,10 +4566,10 @@ videoPlayer = () => { */ renderThumbnails = async () => { const thumbnails = await getAvailableStreams(); - console.log('THUMBNAILS', thumbnails) + // console.log('THUMBNAILS', thumbnails) const containerDiv = document.getElementById('container') containerDiv.innerHTML = ''; - console.log(containerDiv) + // console.log(containerDiv) for(var i=0; i<thumbnails.length; i++){ const encodedURI = encodeURIComponent(thumbnails[i]) current_data.uri = encodedURI @@ -4636,16 +4638,6 @@ createCard = (url, viewers) => { </div>` } -connectToStream = () => { - const ws = new WebSocket('ws://localhost:8080/'); - current_data.peer = new Peer(ws); - console.log("websocket", current_data.peer.sock) - console.log("still working") - current_data.peer.onopen = (event) => { - current_data.peer.send() - } - //setTimeout 1s, ask for the amount of frames user has selected -} //FOR LAPTOP // const createCard = () => { @@ -4656,6 +4648,15 @@ connectToStream = () => { // </div>` // } + +connectToStream = () => { + const ws = new WebSocket('ws://localhost:8080/') + current_data.peer = new Peer(ws); + + return console.log('successfully connected to stream') + //setTimeout 1s, ask for the amount of frames user has selected +} + const cardLogic = () => { const cards = document.getElementsByClassName('ftlab-card-component'); } diff --git a/web-service/server/src/public/js/index.js b/web-service/server/src/public/js/index.js index c34242d526bc64b9e65a95e179a2889a7a0ed2a8..335d9b5d944a252ecb8c9d1030e7d8a4acebe73f 100644 --- a/web-service/server/src/public/js/index.js +++ b/web-service/server/src/public/js/index.js @@ -1,6 +1,7 @@ const Peer = require('../../peer') let current_data = {}; +let peer; checkIfLoggedIn = async () => { // const token = window.localStorage.getItem('token') @@ -56,10 +57,10 @@ videoPlayer = () => { */ renderThumbnails = async () => { const thumbnails = await getAvailableStreams(); - console.log('THUMBNAILS', thumbnails) + // console.log('THUMBNAILS', thumbnails) const containerDiv = document.getElementById('container') containerDiv.innerHTML = ''; - console.log(containerDiv) + // console.log(containerDiv) for(var i=0; i<thumbnails.length; i++){ const encodedURI = encodeURIComponent(thumbnails[i]) current_data.uri = encodedURI @@ -128,16 +129,6 @@ createCard = (url, viewers) => { </div>` } -connectToStream = () => { - const ws = new WebSocket('ws://localhost:8080/'); - current_data.peer = new Peer(ws); - console.log("websocket", current_data.peer.sock) - console.log("still working") - current_data.peer.onopen = (event) => { - current_data.peer.send() - } - //setTimeout 1s, ask for the amount of frames user has selected -} //FOR LAPTOP // const createCard = () => { @@ -148,6 +139,15 @@ connectToStream = () => { // </div>` // } + +connectToStream = () => { + const ws = new WebSocket('ws://localhost:8080/') + current_data.peer = new Peer(ws); + + return console.log('successfully connected to stream') + //setTimeout 1s, ask for the amount of frames user has selected +} + const cardLogic = () => { const cards = document.getElementsByClassName('ftlab-card-component'); } \ No newline at end of file diff --git a/web-service/server/src/utils/config.js b/web-service/server/src/utils/config.js index 99f9a002b3cfad02486f638e480b1c14d33f1c0a..546dd8d2fa3b29d9e19e137121d94af9deeb86a4 100644 --- a/web-service/server/src/utils/config.js +++ b/web-service/server/src/utils/config.js @@ -1,3 +1,5 @@ module.exports = { + //This needs to be changed, + //Currently linked to Sami's mongo-atlas account MONGODB_URI: 'mongodb+srv://ftl:sOgIX%2638@FTL-w141e.mongodb.net/FTL?retryWrites=true&w=majority' } \ No newline at end of file