multi rooms with some race for multi write to a ws
parent
4145bea3ba
commit
c9872c7725
|
|
@ -10,18 +10,16 @@
|
||||||
<div>Audio<label class="switch"><input onclick="toggle('audio', this)" type="checkbox"><span class="slider round"></span></label></div>
|
<div>Audio<label class="switch"><input onclick="toggle('audio', this)" type="checkbox"><span class="slider round"></span></label></div>
|
||||||
|
|
||||||
<video id="preview" autoplay muted ></video>
|
<video id="preview" autoplay muted ></video>
|
||||||
<div id="remote">
|
<div id="remote"></div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<input type="button" id="start" onclick="start(true)" value="Start Video"></input>
|
<input type="button" id="start" onclick="start(true)" value="Start Video"></input>
|
||||||
|
|
||||||
|
<div id="log"></div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<footer>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
pageReady();
|
pageReady();
|
||||||
</script>
|
</script>
|
||||||
|
</footer>
|
||||||
<div id="log">
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,18 @@ class Config {
|
||||||
static getUUID() {
|
static getUUID() {
|
||||||
var uuid = Config.getCookie('uuid');
|
var uuid = Config.getCookie('uuid');
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
uuid = Config.createUUID();
|
Config.newUUID();
|
||||||
Config.setCookie('uuid', uuid);
|
|
||||||
}
|
}
|
||||||
|
Log.info("uuid", uuid);
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static newUUID() {
|
||||||
|
var uuid = Config.createUUID();
|
||||||
|
Config.setCookie('uuid', uuid);
|
||||||
|
}
|
||||||
|
|
||||||
static createUUID() {
|
static createUUID() {
|
||||||
return "" + new Date();
|
|
||||||
function s4() {
|
function s4() {
|
||||||
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
||||||
}
|
}
|
||||||
|
|
@ -88,6 +92,7 @@ class Preview {
|
||||||
|
|
||||||
class WS {
|
class WS {
|
||||||
constructor(address, cb) {
|
constructor(address, cb) {
|
||||||
|
Log.warn("address", address);
|
||||||
WS.ws = new WebSocket(address);
|
WS.ws = new WebSocket(address);
|
||||||
WS.ws.onmessage = cb;
|
WS.ws.onmessage = cb;
|
||||||
}
|
}
|
||||||
|
|
@ -253,12 +258,12 @@ for (var i in ["log", "info", "warn", "error"]) {
|
||||||
window.console = console;
|
window.console = console;
|
||||||
|
|
||||||
function pageReady() {
|
function pageReady() {
|
||||||
Config.getUUID();
|
Config.newUUID();
|
||||||
var host = window.location.hostname;
|
var host = window.location.hostname;
|
||||||
if (window.location.port) {
|
if (window.location.port) {
|
||||||
host += ":" + 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();
|
Entropy.pageReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
13
server.go
13
server.go
|
|
@ -31,15 +31,20 @@ func New() *Server {
|
||||||
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println("base", path.Base(r.URL.Path))
|
log.Println("base", path.Base(r.URL.Path))
|
||||||
|
log.Println("dir", path.Dir(r.URL.Path))
|
||||||
if !s.Authorize(w, r) {
|
if !s.Authorize(w, r) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if path.Ext(r.URL.Path) != "" {
|
if path.Dir(r.URL.Path) == "/ws" {
|
||||||
s.fs.ServeHTTP(w, r)
|
|
||||||
} else if _, err := os.Stat(path.Join(config().GetString("d"), r.URL.Path[1:])); os.IsNotExist(err) {
|
|
||||||
s.ws.ServeHTTP(w, r)
|
s.ws.ServeHTTP(w, r)
|
||||||
} else {
|
} 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue