diff --git a/web-service/server/src/peer.js b/web-service/server/src/peer.js index b96b93fce19e0430656b02d2407bf88c9ccf09e6..db8e50667f54a7bdf1c907b7f4bd18d708e76845 100644 --- a/web-service/server/src/peer.js +++ b/web-service/server/src/peer.js @@ -59,7 +59,6 @@ function Peer(ws) { } let close = () => { - console.log("connection closed") this.status = kDisconnected; this._notify("disconnect", this); } @@ -72,10 +71,14 @@ function Peer(ws) { //if undefined, client is using peer if(this.sock.on === undefined){ + console.log("THIS.SOCK", this.sock); this.sock.onopen = (event) => { + console.log("socket opened") this.sock.send(encode([0, '__handshake__'])); - console.log("socket was opened") + this.sock.send('get_stream'); } + this.sock.onerror = error; + console.log("Ready state", this.sock) //Server is using peer }else{ this.sock.on("message", message); @@ -224,8 +227,12 @@ Peer.prototype.send = function(name, ...args) { } } +//This was a problem and needed to change it so that +//this.sock.close() can only be called by server (!=undefined) Peer.prototype.close = function() { - this.sock.close = close; + if(this.sock.on !== undefined){ + this.sock.close(); + } this.status = kDisconnected; } diff --git a/web-service/server/src/public/js/bundle.js b/web-service/server/src/public/js/bundle.js index 317a0f6f29e4d1da4e92e13ab3da27688da886e9..df925f24df11fa503677a67b9c21a5e85f5134c0 100644 --- a/web-service/server/src/public/js/bundle.js +++ b/web-service/server/src/public/js/bundle.js @@ -4306,7 +4306,6 @@ function Peer(ws) { } let close = () => { - console.log("connection closed") this.status = kDisconnected; this._notify("disconnect", this); } @@ -4319,10 +4318,14 @@ function Peer(ws) { //if undefined, client is using peer if(this.sock.on === undefined){ + console.log("THIS.SOCK", this.sock); this.sock.onopen = (event) => { + console.log("socket opened") this.sock.send(encode([0, '__handshake__'])); - console.log("socket was opened") + this.sock.send('get_stream'); } + this.sock.onerror = error; + console.log("Ready state", this.sock) //Server is using peer }else{ this.sock.on("message", message); @@ -4471,8 +4474,12 @@ Peer.prototype.send = function(name, ...args) { } } +//This was a problem and needed to change it so that +//this.sock.close() can only be called by server (!=undefined) Peer.prototype.close = function() { - this.sock.close = close; + if(this.sock.on !== undefined){ + this.sock.close(); + } this.status = kDisconnected; } @@ -4652,8 +4659,7 @@ createCard = (url, viewers) => { connectToStream = () => { const ws = new WebSocket('ws://localhost:8080/') current_data.peer = new Peer(ws); - - return console.log('successfully connected to stream') + console.log("currentData", current_data.peer) //setTimeout 1s, ask for the amount of frames user has selected } diff --git a/web-service/server/src/public/js/index.js b/web-service/server/src/public/js/index.js index 335d9b5d944a252ecb8c9d1030e7d8a4acebe73f..0ec435d953f4779666ca03ba635a7f231e2afdec 100644 --- a/web-service/server/src/public/js/index.js +++ b/web-service/server/src/public/js/index.js @@ -143,8 +143,7 @@ createCard = (url, viewers) => { connectToStream = () => { const ws = new WebSocket('ws://localhost:8080/') current_data.peer = new Peer(ws); - - return console.log('successfully connected to stream') + console.log("currentData", current_data.peer) //setTimeout 1s, ask for the amount of frames user has selected }