From fab2ab97d7d3b0281860230c4ee251c2429c8e0b Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 13 May 2020 16:42:12 -0600 Subject: [PATCH] Working on making server and client uuid in sync but a challenjour has appeared is good --- pool.go | 2 +- public/webrtc.js | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pool.go b/pool.go index a5ed2e9..d5dd098 100644 --- a/pool.go +++ b/pool.go @@ -30,7 +30,7 @@ func (p *Pool) Push(id string, conn *websocket.Conn) { p.lock.Lock() p.conns.Store(id, &Conn{ws: *conn}) p.lock.Unlock() - p.Broadcast(websocket.TextMessage, strings.NewReader(`{"joined":"`+id+`"}`)) + p.Broadcast(websocket.TextMessage, strings.NewReader(`{"joined":"`+id+`", "uuid":"`+id+`"}`)) } func (p *Pool) Broadcast(mt int, r io.Reader) error { diff --git a/public/webrtc.js b/public/webrtc.js index 7ae7437..5221f45 100755 --- a/public/webrtc.js +++ b/public/webrtc.js @@ -123,7 +123,7 @@ class RTC { constructor(stream) { this.conn = new RTCPeerConnection(Config.iceConfig); this.conn.onicecandidate = (event) => { - if(event.candidate != null) { + if (event.candidate != null) { WS.ws.send(JSON.stringify({'ice': event.candidate, 'uuid': Config.getUUID()})); } }; @@ -153,27 +153,30 @@ class Entropy { static start(isCaller) { Entropy.rtc = new RTC(Entropy.local.stream); - if(isCaller) { + if (isCaller) { Entropy.rtc.offer(Entropy.createdDescription); } } static gotMessageFromServer(message) { - if(!Entropy.rtc || !Entropy.rtc.conn) Entropy.start(false); + if (!Entropy.rtc || !Entropy.rtc.conn) Entropy.start(false); var signal = JSON.parse(message.data); // Ignore messages from ourself - if(signal.uuid == Config.getUUID()) return; + if (signal.uuid == Config.getUUID()) return; - if(signal.sdp) { + if (signal.joined) + Log.info("a challenjour has appeared", JSON.stringify(signal)); + + if (signal.sdp) { Entropy.rtc.conn.setRemoteDescription(new RTCSessionDescription(signal.sdp)).then(function() { // Only create answers in response to offers - if(signal.sdp.type == 'offer') { + if (signal.sdp.type == 'offer') { Entropy.rtc.conn.createAnswer().then(Entropy.createdDescription).catch(Log.error); } }).catch(Log.error); - } else if(signal.ice) { + } else if (signal.ice) { Entropy.rtc.conn.addIceCandidate(new RTCIceCandidate(signal.ice)).catch(Log.error); } } @@ -212,7 +215,7 @@ class Local { video: this.gettype() == "video", audio: this.gettype() == "audio", }; - if(!navigator.mediaDevices.getUserMedia) { + if (!navigator.mediaDevices.getUserMedia) { Log.error('Your browser does not support getUserMedia API'); } navigator.mediaDevices.getUserMedia(constraints) @@ -258,7 +261,7 @@ for (var i in ["log", "info", "warn", "error"]) { window.console = console; function pageReady() { - Config.newUUID(); + //Config.newUUID(); var host = window.location.hostname; if (window.location.port) { host += ":" + window.location.port;