From c9872c77254231d599856fa9e446589f89ad0cd5 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 13 May 2020 16:24:33 -0600 Subject: [PATCH] multi rooms with some race for multi write to a ws --- public/index.html | 14 ++++++-------- public/webrtc.js | 15 ++++++++++----- server.go | 13 +++++++++---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/public/index.html b/public/index.html index 69ef55f..66417dc 100755 --- a/public/index.html +++ b/public/index.html @@ -10,18 +10,16 @@
Audio
-
-
- +

- +
+ + + diff --git a/public/webrtc.js b/public/webrtc.js index 29f8c6d..7ae7437 100755 --- a/public/webrtc.js +++ b/public/webrtc.js @@ -25,14 +25,18 @@ class Config { static getUUID() { var uuid = Config.getCookie('uuid'); if (!uuid) { - uuid = Config.createUUID(); - Config.setCookie('uuid', uuid); + Config.newUUID(); } + Log.info("uuid", uuid); return uuid; } + static newUUID() { + var uuid = Config.createUUID(); + Config.setCookie('uuid', uuid); + } + static createUUID() { - return "" + new Date(); function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); } @@ -88,6 +92,7 @@ class Preview { class WS { constructor(address, cb) { + Log.warn("address", address); WS.ws = new WebSocket(address); WS.ws.onmessage = cb; } @@ -253,12 +258,12 @@ for (var i in ["log", "info", "warn", "error"]) { window.console = console; function pageReady() { - Config.getUUID(); + Config.newUUID(); var host = window.location.hostname; if (window.location.port) { host += ":" + window.location.port; } - new WS('wss://' + host + '/abc', Entropy.gotMessageFromServer); + new WS('wss://' + host + '/ws/' + window.location.pathname.split("/").slice(-1).pop(), Entropy.gotMessageFromServer); Entropy.pageReady(); } diff --git a/server.go b/server.go index f77a252..eda559c 100644 --- a/server.go +++ b/server.go @@ -31,15 +31,20 @@ func New() *Server { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Println("base", path.Base(r.URL.Path)) + log.Println("dir", path.Dir(r.URL.Path)) if !s.Authorize(w, r) { return } - if path.Ext(r.URL.Path) != "" { - s.fs.ServeHTTP(w, r) - } else if _, err := os.Stat(path.Join(config().GetString("d"), r.URL.Path[1:])); os.IsNotExist(err) { + if path.Dir(r.URL.Path) == "/ws" { s.ws.ServeHTTP(w, r) } else { - s.fs.ServeHTTP(w, r) + r.URL.Path = "/" + path.Base(r.URL.Path) + if _, err := os.Stat(path.Join(config().GetString("d"), path.Base(r.URL.Path))); os.IsNotExist(err) { + r.URL.Path = "/" + s.fs.ServeHTTP(w, r) + } else { + s.fs.ServeHTTP(w, r) + } } }